Skip to content

Commit 5c20f4c

Browse files
committed
fix shift+click wrong detection making shift+% buggy on pinyin
1 parent 475c7a4 commit 5c20f4c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/controller.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class FcitxInputController: IMKInputController {
2121
let client: Any!
2222
var accentColor = ""
2323
var selection: NSRange? = nil
24+
var lastEventIsShiftPress = false
2425
var obeySecureInput = true
2526

2627
// A registry of live FcitxInputController objects.
@@ -105,11 +106,17 @@ class FcitxInputController: IMKInputController {
105106
let newSelection = client.selectedRange()
106107
let selectionChanged: Bool = selection != newSelection
107108
selection = newSelection
108-
// Shift release when text selection is changed.
109-
if modsVal == 0 && (code == 56 || code == 60) && selectionChanged {
110-
// Send a no-op key event to fcitx so that Shift+Click doesn't trigger im toggle.
111-
process_key(uuid, 0, 0, 0, false, false)
109+
var isShiftPress = false
110+
if code == 56 || code == 60 {
111+
if modsVal == 131072 {
112+
isShiftPress = true
113+
} else if modsVal == 0 && lastEventIsShiftPress && selectionChanged {
114+
// Shift release following press when text selection is changed.
115+
// Send a no-op key event to fcitx so that Shift+Click doesn't trigger im toggle.
116+
process_key(uuid, 0, 0, 0, false, false)
117+
}
112118
}
119+
lastEventIsShiftPress = isShiftPress
113120
// It can change within an IMKInputController (e.g. sudo in Terminal), so must reevaluate before each key sent to IM.
114121
let isPassword = getSecureInputInfo(isOnFocus: false)
115122
let res = String(process_key(uuid, unicode, modsVal, code, isRelease, isPassword))

0 commit comments

Comments
 (0)