Skip to content

Commit

Permalink
Implemented cmd+f command to pdf reader and items list (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrentka authored Jul 13, 2023
1 parent d2b87bd commit d4e7fc2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ final class ItemsViewController: UIViewController {
}
}

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
guard let key = presses.first?.key, key.characters == "f", key.modifierFlags.contains(.command) else {
super.pressesBegan(presses, with: event)
return
}
self.searchBarContainer?.searchBar.becomeFirstResponder()
}

deinit {
DDLogInfo("ItemsViewController deinitialized")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ final class PDFDocumentViewController: UIViewController {
self.updatePencilSettingsIfNeeded()
}

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
guard let controller = self.pdfController, let key = presses.first?.key, key.characters == "f", key.modifierFlags.contains(.command) else {
super.pressesBegan(presses, with: event)
return
}
self.parentDelegate?.showSearch(pdfController: controller, text: nil)
}

// MARK: - Actions

func focus(page: UInt) {
Expand Down
13 changes: 13 additions & 0 deletions Zotero/Scenes/Detail/PDF/Views/PDFSearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ final class PDFSearchViewController: UIViewController {
super.viewDidLoad()

self.setupViews()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

self.searchBar.becomeFirstResponder()

if let text = self.text {
Expand All @@ -68,6 +73,14 @@ final class PDFSearchViewController: UIViewController {
DDLogInfo("PDFSearchViewController deinitialized")
}

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
guard let key = presses.first?.key, key.keyCode == .keyboardEscape else {
super.pressesBegan(presses, with: event)
return
}
self.dismiss(animated: true, completion: nil)
}

// MARK: - Actions

private func search(for string: String) {
Expand Down

0 comments on commit d4e7fc2

Please sign in to comment.