From 3a4ec903fa0b1c98e56978c1b11e31a5c504ad17 Mon Sep 17 00:00:00 2001 From: Michal Rentka Date: Fri, 9 Aug 2024 12:01:30 +0200 Subject: [PATCH] Enabled text, underline annotations, fixed content editing for underline annotation --- Zotero.xcodeproj/project.pbxproj | 18 +++++++------- Zotero/Models/AnnotationsConfig.swift | 3 +-- .../Views/AnnotationEditViewController.swift | 24 +++++++++---------- ...itCell.swift => TextContentEditCell.swift} | 6 ++--- ...htEditCell.xib => TextContentEditCell.xib} | 8 +++---- .../PDF/Views/PDFReaderViewController.swift | 3 +-- 6 files changed, 30 insertions(+), 32 deletions(-) rename Zotero/Scenes/Detail/Annotation Popover/Views/{HighlightEditCell.swift => TextContentEditCell.swift} (93%) rename Zotero/Scenes/Detail/Annotation Popover/Views/{HighlightEditCell.xib => TextContentEditCell.xib} (91%) diff --git a/Zotero.xcodeproj/project.pbxproj b/Zotero.xcodeproj/project.pbxproj index 9dde2695b..b334486d6 100644 --- a/Zotero.xcodeproj/project.pbxproj +++ b/Zotero.xcodeproj/project.pbxproj @@ -848,8 +848,8 @@ B39649182869B0D0000BCB6C /* ISBNParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B39649172869B0D0000BCB6C /* ISBNParser.swift */; }; B3972689247D403200A8B469 /* UrlDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3972688247D403200A8B469 /* UrlDetector.swift */; }; B3981427257A5A16002C755C /* AnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3981426257A5A16002C755C /* AnnotationView.swift */; }; - B398142E257A649D002C755C /* HighlightEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398142C257A649D002C755C /* HighlightEditCell.swift */; }; - B398143F257A8EB2002C755C /* HighlightEditCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B398143E257A8EB2002C755C /* HighlightEditCell.xib */; }; + B398142E257A649D002C755C /* TextContentEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398142C257A649D002C755C /* TextContentEditCell.swift */; }; + B398143F257A8EB2002C755C /* TextContentEditCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B398143E257A8EB2002C755C /* TextContentEditCell.xib */; }; B3981B76258399AA00F8D15A /* NoteAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3981B75258399AA00F8D15A /* NoteAnnotation.swift */; }; B398A915270C6A4300968EE8 /* WebDavController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398A914270C6A4300968EE8 /* WebDavController.swift */; }; B398A917270C6A5B00968EE8 /* WebDavSessionStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398A916270C6A5B00968EE8 /* WebDavSessionStorage.swift */; }; @@ -1853,8 +1853,8 @@ B39649172869B0D0000BCB6C /* ISBNParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ISBNParser.swift; sourceTree = ""; }; B3972688247D403200A8B469 /* UrlDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlDetector.swift; sourceTree = ""; }; B3981426257A5A16002C755C /* AnnotationView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnnotationView.swift; sourceTree = ""; }; - B398142C257A649D002C755C /* HighlightEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightEditCell.swift; sourceTree = ""; }; - B398143E257A8EB2002C755C /* HighlightEditCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HighlightEditCell.xib; sourceTree = ""; }; + B398142C257A649D002C755C /* TextContentEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextContentEditCell.swift; sourceTree = ""; }; + B398143E257A8EB2002C755C /* TextContentEditCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextContentEditCell.xib; sourceTree = ""; }; B3981B75258399AA00F8D15A /* NoteAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteAnnotation.swift; sourceTree = ""; }; B398A914270C6A4300968EE8 /* WebDavController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebDavController.swift; sourceTree = ""; }; B398A916270C6A5B00968EE8 /* WebDavSessionStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebDavSessionStorage.swift; sourceTree = ""; }; @@ -3078,18 +3078,18 @@ B32CDD3C2AEA9BB100EF5054 /* AnnotationPopoverViewController.xib */, B34C40FD25711C990057D5F5 /* ColorPickerCell.swift */, B3764D9C2574F2DE0024274F /* ColorPickerCircleView.swift */, + 61FA14CF2B08E24A00E7D423 /* ColorPickerStackView.swift */, B36FD9B22A7929C8002D77E8 /* FontSizeCell.swift */, B36FD9B02A7924CB002D77E8 /* FontSizePickerViewController.swift */, B398D6BF2A77F9C60049A296 /* FontSizeView.swift */, - B398142C257A649D002C755C /* HighlightEditCell.swift */, - B398143E257A8EB2002C755C /* HighlightEditCell.xib */, B34A4B7126E65FC200B3E993 /* LineWidthCell.swift */, B34A4B6F26E63C9900B3E993 /* LineWidthView.swift */, B34DF1BB2576956F0019CCD1 /* SwitchCell.swift */, B34DF1BC2576956F0019CCD1 /* SwitchCell.xib */, + B398142C257A649D002C755C /* TextContentEditCell.swift */, + B398143E257A8EB2002C755C /* TextContentEditCell.xib */, B34DF1B325768BB70019CCD1 /* TextFieldCell.swift */, B34DF1B425768BB70019CCD1 /* TextFieldCell.xib */, - 61FA14CF2B08E24A00E7D423 /* ColorPickerStackView.swift */, ); path = Views; sourceTree = ""; @@ -4419,7 +4419,7 @@ buildActionMask = 2147483647; files = ( B3593F33241A61C700760E20 /* ItemDetailNoteContentView.xib in Resources */, - B398143F257A8EB2002C755C /* HighlightEditCell.xib in Resources */, + B398143F257A8EB2002C755C /* TextContentEditCell.xib in Resources */, 618D83E72BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */, B32A273D254841B80081E061 /* CreatorEditViewController.xib in Resources */, B3830CE9255451DC00910FE0 /* TagPickerViewController.xib in Resources */, @@ -5316,7 +5316,7 @@ B3F3D62C255EBE3500F310C2 /* AnnotationViewHeader.swift in Sources */, B3E8FE34271429C300F51458 /* ExportLocalePickerView.swift in Sources */, B39D42D929C0B82F0035CDA9 /* TagFilterCell.swift in Sources */, - B398142E257A649D002C755C /* HighlightEditCell.swift in Sources */, + B398142E257A649D002C755C /* TextContentEditCell.swift in Sources */, B32F0BDA298BFCEE00C04557 /* LogsViewController.swift in Sources */, B3BC1F60254322D200BA3388 /* ItemDetailAbstractEditCell.swift in Sources */, B3422F44289A9F2400C53DD2 /* ItemDetailAttachmentContentView.swift in Sources */, diff --git a/Zotero/Models/AnnotationsConfig.swift b/Zotero/Models/AnnotationsConfig.swift index b4080edd7..d9fdbd528 100644 --- a/Zotero/Models/AnnotationsConfig.swift +++ b/Zotero/Models/AnnotationsConfig.swift @@ -32,8 +32,7 @@ struct AnnotationsConfig { // Size of note annotation in PDF document. static let noteAnnotationSize: CGSize = CGSize(width: 22, height: 22) static let positionSizeLimit = 65000 - // TODO: Enable when text/underline annotations are fully available - static let supported: PSPDFKit.Annotation.Kind = [.note, .highlight, .square, .ink]//, .underline, .freeText] + static let supported: PSPDFKit.Annotation.Kind = [.note, .highlight, .square, .ink, .underline, .freeText] static func colors(for type: AnnotationType) -> [String] { switch type { diff --git a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift index a8ae7975e..32e59dffd 100644 --- a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift +++ b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift @@ -16,14 +16,14 @@ typealias AnnotationEditDeleteAction = () -> Void final class AnnotationEditViewController: UIViewController { private enum Section { - case properties, pageLabel, actions, highlight, fontSize + case properties, pageLabel, actions, textContent, fontSize func cellId(index: Int) -> String { switch self { case .properties: return index == 0 ? "ColorPickerCell" : "LineWidthCell" case .actions: return "ActionCell" case .pageLabel: return "PageLabelCell" - case .highlight: return "HighlightCell" + case .textContent: return "TextContentCell" case .fontSize: return "FontSizeCell" } } @@ -48,8 +48,8 @@ final class AnnotationEditViewController: UIViewController { if includeFontPicker { sections.insert(.fontSize, at: 0) } - if viewModel.state.type == .highlight { - sections.insert(.highlight, at: 0) + if viewModel.state.type == .highlight || viewModel.state.type == .underline { + sections.insert(.textContent, at: 0) } } @@ -90,7 +90,7 @@ final class AnnotationEditViewController: UIViewController { private func update(to state: AnnotationEditState) { if state.changes.contains(.color) { - self.reload(sections: [.properties, .highlight]) + self.reload(sections: [.properties, .textContent]) } if state.changes.contains(.pageLabel) { self.reload(sections: [.pageLabel]) @@ -112,7 +112,7 @@ final class AnnotationEditViewController: UIViewController { private func scrollToHighlightCursor() { let indexPath = IndexPath(row: 0, section: 0) - guard let cell = self.tableView.cellForRow(at: indexPath) as? HighlightEditCell, let cellCaretRect = cell.caretRect else { return } + guard let cell = self.tableView.cellForRow(at: indexPath) as? TextContentEditCell, let cellCaretRect = cell.caretRect else { return } let rowRect = self.tableView.rectForRow(at: indexPath) let caretRect = CGRect(x: (rowRect.minX + cellCaretRect.minX), y: (rowRect.minY + cellCaretRect.minY) + 10, width: cellCaretRect.width, height: cellCaretRect.height) @@ -123,10 +123,10 @@ final class AnnotationEditViewController: UIViewController { } private func updatePreferredContentSize() { - let sectionCount = self.sections.count - (self.sections.contains(.highlight) ? 1 : 0) + let sectionCount = self.sections.count - (self.sections.contains(.textContent) ? 1 : 0) var height: CGFloat = (CGFloat(sectionCount) * 80) + 36 // 80 for 36 spacer and 44 cell height - if self.viewModel.state.type == .highlight { + if sections.contains(.textContent) { let width = AnnotationPopoverLayout.width - ((AnnotationPopoverLayout.annotationLayout.horizontalInset * 2) + AnnotationPopoverLayout.annotationLayout.highlightContentLeadingOffset + AnnotationPopoverLayout.annotationLayout.highlightLineWidth) @@ -188,7 +188,7 @@ final class AnnotationEditViewController: UIViewController { self.tableView.dataSource = self self.tableView.register(ColorPickerCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0)) self.tableView.register(LineWidthCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 1)) - self.tableView.register(UINib(nibName: "HighlightEditCell", bundle: nil), forCellReuseIdentifier: Section.highlight.cellId(index: 0)) + self.tableView.register(UINib(nibName: "TextContentEditCell", bundle: nil), forCellReuseIdentifier: Section.textContent.cellId(index: 0)) self.tableView.register(FontSizeCell.self, forCellReuseIdentifier: Section.fontSize.cellId(index: 0)) self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.actions.cellId(index: 0)) self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.pageLabel.cellId(index: 0)) @@ -225,8 +225,8 @@ extension AnnotationEditViewController: UITableViewDataSource { cell.valueObservable.subscribe(onNext: { value in self.viewModel.process(action: .setLineWidth(CGFloat(value))) }).disposed(by: cell.disposeBag) } - case .highlight: - if let cell = cell as? HighlightEditCell { + case .textContent: + if let cell = cell as? TextContentEditCell { cell.setup(with: self.viewModel.state.highlightText, color: self.viewModel.state.color) cell.textObservable .subscribe(onNext: { [weak self] text, needsHeightReload in @@ -270,7 +270,7 @@ extension AnnotationEditViewController: UITableViewDelegate { tableView.deselectRow(at: indexPath, animated: true) switch self.sections[indexPath.section] { - case .properties, .highlight: break + case .properties, .textContent: break case .actions: self.deleteAction() diff --git a/Zotero/Scenes/Detail/Annotation Popover/Views/HighlightEditCell.swift b/Zotero/Scenes/Detail/Annotation Popover/Views/TextContentEditCell.swift similarity index 93% rename from Zotero/Scenes/Detail/Annotation Popover/Views/HighlightEditCell.swift rename to Zotero/Scenes/Detail/Annotation Popover/Views/TextContentEditCell.swift index f0bc408a1..ccdaeffb5 100644 --- a/Zotero/Scenes/Detail/Annotation Popover/Views/HighlightEditCell.swift +++ b/Zotero/Scenes/Detail/Annotation Popover/Views/TextContentEditCell.swift @@ -1,5 +1,5 @@ // -// HighlightEditCell.swift +// TextContentEditCell.swift // Zotero // // Created by Michal Rentka on 04.12.2020. @@ -10,7 +10,7 @@ import UIKit import RxSwift -final class HighlightEditCell: UITableViewCell { +final class TextContentEditCell: UITableViewCell { @IBOutlet private weak var lineView: UIView! @IBOutlet private weak var textView: UITextView! @@ -49,7 +49,7 @@ final class HighlightEditCell: UITableViewCell { } } -extension HighlightEditCell: UITextViewDelegate { +extension TextContentEditCell: UITextViewDelegate { func textViewDidChange(_ textView: UITextView) { let height = textView.contentSize.height textView.sizeToFit() diff --git a/Zotero/Scenes/Detail/Annotation Popover/Views/HighlightEditCell.xib b/Zotero/Scenes/Detail/Annotation Popover/Views/TextContentEditCell.xib similarity index 91% rename from Zotero/Scenes/Detail/Annotation Popover/Views/HighlightEditCell.xib rename to Zotero/Scenes/Detail/Annotation Popover/Views/TextContentEditCell.xib index e2afda47e..49f529510 100644 --- a/Zotero/Scenes/Detail/Annotation Popover/Views/HighlightEditCell.xib +++ b/Zotero/Scenes/Detail/Annotation Popover/Views/TextContentEditCell.xib @@ -1,9 +1,9 @@ - + - + @@ -11,7 +11,7 @@ - + @@ -53,7 +53,7 @@ - + diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift index 4f5f3b44f..7defdbf7d 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift @@ -250,8 +250,7 @@ class PDFReaderViewController: UIViewController { separator.translatesAutoresizingMaskIntoConstraints = false separator.backgroundColor = Asset.Colors.annotationSidebarBorderColor.color - // TODO: Add .underline and .freeText tools when those annotations are fully available - let annotationToolbar = AnnotationToolbarViewController(tools: [.highlight, .note, .image, .ink, .eraser], undoRedoEnabled: true, size: navigationBarHeight) + let annotationToolbar = AnnotationToolbarViewController(tools: [.highlight, .underline, .note, .freeText, .image, .ink, .eraser], undoRedoEnabled: true, size: navigationBarHeight) annotationToolbar.delegate = self add(controller: documentController)