Skip to content

Commit

Permalink
Merge pull request #141 from qwertyyb/fix/disable-toggle-mode
Browse files Browse the repository at this point in the history
fix: 修复禁止切换中英文后,无法在 Chrome 浏览器中使用快捷键的问题
  • Loading branch information
qwertyyb authored Dec 3, 2024
2 parents 0d5370e + 14c2c3b commit 1f00d65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Fire/FireInputController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class FireInputController: IMKInputController {
// ---- handlers begin -----

private func hotkeyHandler(event: NSEvent) -> Bool? {
NSLog("[FireInputController] hotkeyHandler")
if event.type == .flagsChanged {
return nil
}
Expand All @@ -125,11 +126,9 @@ class FireInputController: IMKInputController {
}

func flagChangedHandler(event: NSEvent) -> Bool? {
if Defaults[.disableEnMode] {
return nil
}
NSLog("[FireInputController] flagChangedHandler")
// 只有在shift keyup时,才切换中英文输入, 否则会导致shift+[a-z]大写的功能失效
if Utils.shared.toggleInputModeKeyUpChecker.check(event) {
if !Defaults[.disableEnMode] && Utils.shared.toggleInputModeKeyUpChecker.check(event) {
NSLog("[FireInputController]toggle mode: \(inputMode)")

// 把当前未上屏的原始code上屏处理
Expand All @@ -138,20 +137,21 @@ class FireInputController: IMKInputController {
Fire.shared.toggleInputMode()
return true
}
// 监听.flagsChanged事件只为切换中英文,其它情况不处理
// 当用户已经按下了非shift的修饰键时,不处理
if event.type == .flagsChanged ||
(event.modifierFlags != .init(rawValue: 0) &&
event.modifierFlags != .shift &&
// 方向键的modifierFlags
event.modifierFlags != .init(arrayLiteral: .numericPad, .function)
// 监听.flagsChanged事件只为切换中英文,其它情况不处理需要返回 false 以避免快捷键不生效
if event.type == .flagsChanged || (
event.modifierFlags != .init(rawValue: 0)
// 输入法需要处理方向键做翻页,所以需要排除方向键
&& event.modifierFlags != .init(arrayLiteral: .numericPad, .function)
) {

NSLog("[FireInputController] flagChangedHandler no need handle")
return false
}
return nil
}

private func enModeHandler(event: NSEvent) -> Bool? {
NSLog("[FireInputController] enModeHandler")
// 英文输入模式, 不做任何处理
if inputMode == .enUS {
return false
Expand Down
2 changes: 2 additions & 0 deletions Fire/FireMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ extension FireInputController {
}
@objc func checkForUpdates(_ sender: Any!) {
NSApp.setActivationPolicy(.accessory)
NSApp.activate(ignoringOtherApps: true)
SUUpdater.shared()?.checkForUpdates(sender)
}
override func showPreferences(_ sender: Any!) {
NSApp.setActivationPolicy(.accessory)
NSApp.activate(ignoringOtherApps: true)
FirePreferencesController.shared.show()
}
@objc func showUserDictPrefs(_ sender: Any!) {
Expand Down

0 comments on commit 1f00d65

Please sign in to comment.