From d6ea701d266d59c868de2b0563183754b5086b2e Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 6 Sep 2019 07:58:36 -0500 Subject: [PATCH] Prevent global keyboard shortcuts from being executed in modal dialogs --- iOS/KeyboardManager.swift | 20 ++++++++++---------- iOS/RootSplitViewController.swift | 5 ----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/iOS/KeyboardManager.swift b/iOS/KeyboardManager.swift index b5d6742b9..0af53e80e 100644 --- a/iOS/KeyboardManager.swift +++ b/iOS/KeyboardManager.swift @@ -20,17 +20,17 @@ class KeyboardManager { private(set) var keyCommands: [UIKeyCommand]? init(type: KeyboardType) { - let file = Bundle.main.path(forResource: type.rawValue, ofType: "plist")! - let entries = NSArray(contentsOfFile: file)! as! [[String: Any]] - keyCommands = entries.compactMap { createKeyCommand(keyEntry: $0) } + let globalFile = Bundle.main.path(forResource: KeyboardType.global.rawValue, ofType: "plist")! + let globalEntries = NSArray(contentsOfFile: globalFile)! as! [[String: Any]] + keyCommands = globalEntries.compactMap { createKeyCommand(keyEntry: $0) } + keyCommands!.append(contentsOf: globalAuxilaryKeyCommands()) + + let specificFile = Bundle.main.path(forResource: type.rawValue, ofType: "plist")! + let specificEntries = NSArray(contentsOfFile: specificFile)! as! [[String: Any]] + keyCommands!.append(contentsOf: specificEntries.compactMap { createKeyCommand(keyEntry: $0) } ) - switch type { - case .global: - keyCommands?.append(contentsOf: globalAuxilaryKeyCommands()) - case .sidebar: - keyCommands?.append(contentsOf: sidebarAuxilaryKeyCommands()) - default: - break + if type == .sidebar { + keyCommands!.append(contentsOf: sidebarAuxilaryKeyCommands()) } } diff --git a/iOS/RootSplitViewController.swift b/iOS/RootSplitViewController.swift index 3ea657a2a..c02d23594 100644 --- a/iOS/RootSplitViewController.swift +++ b/iOS/RootSplitViewController.swift @@ -13,11 +13,6 @@ class RootSplitViewController: UISplitViewController { var coordinator: SceneCoordinator! - private let keyboardManager = KeyboardManager(type: .global) - override var keyCommands: [UIKeyCommand]? { - return keyboardManager.keyCommands - } - // MARK: Keyboard Shortcuts @objc func scrollOrGoToNextUnread(_ sender: Any?) {