Skip to content

Commit

Permalink
Adjust free text annotation size when text editing ends
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Dec 3, 2024
1 parent e953532 commit a283faf
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Zotero/Scenes/Detail/PDF/Views/FreeTextAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit a283faf

Please sign in to comment.