From a283faf998cd32332ae3337ca07856c3881ab92e Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 3 Dec 2024 16:54:41 +0200 Subject: [PATCH] Adjust free text annotation size when text editing ends --- .../PDF/Views/FreeTextAnnotationView.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Zotero/Scenes/Detail/PDF/Views/FreeTextAnnotationView.swift b/Zotero/Scenes/Detail/PDF/Views/FreeTextAnnotationView.swift index 8b7e86d9f..0add9e4d7 100644 --- a/Zotero/Scenes/Detail/PDF/Views/FreeTextAnnotationView.swift +++ b/Zotero/Scenes/Detail/PDF/Views/FreeTextAnnotationView.swift @@ -37,6 +37,22 @@ final class FreeTextAnnotationView: PSPDFKitUI.FreeTextAnnotationView { } } +extension FreeTextAnnotationView { + override func textViewDidEndEditing(_ textView: UITextView) { + guard let annotation = annotation as? FreeTextAnnotation else { return } + let previousTextBoundingBox = annotation.textBoundingBox + super.textViewDidEndEditing(textView) + annotation.sizeToFit() + var newTextBoundingBox = annotation.textBoundingBox + let minX = min(previousTextBoundingBox.minX, newTextBoundingBox.minX) + let maxX = max(previousTextBoundingBox.maxX, newTextBoundingBox.maxX) + let minY = min(previousTextBoundingBox.minY, newTextBoundingBox.minY) + let maxY = max(previousTextBoundingBox.maxY, newTextBoundingBox.maxY) + annotation.textBoundingBox = CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY) + NotificationCenter.default.post(name: .PSPDFAnnotationChanged, object: annotation, userInfo: [PSPDFAnnotationChangedNotificationKeyPathKey: ["boundingBox", "fontSize"]]) + } +} + final class FreeTextInputAccessory: UIView { private weak var delegate: FreeTextInputDelegate? private weak var sizePicker: FontSizeView?