Skip to content

Commit

Permalink
Fix text lookup action regression
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Jan 14, 2025
1 parent 757aa35 commit 79f7243
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Zotero/Scenes/Detail/PDF/PDFCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protocol PdfReaderCoordinatorDelegate: AnyObject {
func show(error: PDFDocumentExporter.Error)
func share(url: URL, barButton: UIBarButtonItem)
func share(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle)
func lookup(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle)
func showDeletedAlertForPdf(completion: @escaping (Bool) -> Void)
func showSettings(with settings: PDFSettings, sender: UIBarButtonItem) -> ViewModel<ReaderSettingsActionHandler>
func showReader(document: Document, userInterfaceStyle: UIUserInterfaceStyle)
Expand Down Expand Up @@ -303,6 +304,18 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate {
self.share(item: text, sourceView: .view(view, rect), userInterfaceStyle: userInterfaceStyle)
}

func lookup(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle) {
DDLogInfo("PDFCoordinator: show lookup")
// When presented as a popover, UIReferenceLibraryViewController ignores overrideUserInterfaceStyle, so we wrap it in a navigation controller to force it.
let controller = UINavigationController(rootViewController: UIReferenceLibraryViewController(term: text))
controller.setNavigationBarHidden(true, animated: false)
controller.overrideUserInterfaceStyle = userInterfaceStyle
controller.modalPresentationStyle = .popover
controller.popoverPresentationController?.sourceView = view
controller.popoverPresentationController?.sourceRect = rect
self.navigationController?.present(controller, animated: true, completion: nil)
}

func show(error: PDFReaderState.Error) {
let title: String
let message: String
Expand Down
14 changes: 14 additions & 0 deletions Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ extension PDFDocumentViewController: PDFViewControllerDelegate {
return action
}

case .PSPDFKit.accessibility:
return action

case .share:
guard action.identifier == .PSPDFKit.share else { return nil }
return action.replacing(handler: { [weak self] _ in
Expand All @@ -796,6 +799,17 @@ extension PDFDocumentViewController: PDFViewControllerDelegate {

case .pspdfkitActions:
switch action.identifier {
case .PSPDFKit.define:
return action.replacing(title: L10n.lookUp, handler: { [weak self] _ in
guard let self else { return }
coordinatorDelegate?.lookup(
text: glyphs.text,
rect: pageView.convert(glyphs.boundingBox, from: pageView.pdfCoordinateSpace),
view: pageView,
userInterfaceStyle: viewModel.state.settings.appearanceMode.userInterfaceStyle
)
})

case .PSPDFKit.searchDocument:
return action.replacing(handler: { [weak self] _ in
guard let self, let pdfController else { return }
Expand Down

0 comments on commit 79f7243

Please sign in to comment.