Skip to content

Commit

Permalink
Process modifier release before new modifier
Browse files Browse the repository at this point in the history
Resolve rime#901
  • Loading branch information
LEOYoon-Tsaw committed May 23, 2024
1 parent a074cbb commit 4b6874d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sources/SquirrelInputController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,24 @@ final class SquirrelInputController: IMKInputController {
rimeModifiers ^= kLockMask.rawValue
_ = processKey(rimeKeycode, modifiers: rimeModifiers)
}

// Need to process release before modifier down. Because
// sometimes release event is delayed to next modifier keydown.
var buffer = [(keycode: UInt32, modifier: UInt32)]()
for flag in [NSEvent.ModifierFlags.shift, .control, .option, .command] {
if changes.contains(flag) {
let releaseMask = modifiers.contains(flag) ? 0 : kReleaseMask.rawValue
_ = processKey(rimeKeycode, modifiers: rimeModifiers | releaseMask)
if modifiers.contains(flag) { // New modifier
buffer.append((keycode: rimeKeycode, modifier: rimeModifiers))
} else { // Release
buffer.insert((keycode: rimeKeycode, modifier: rimeModifiers | kReleaseMask.rawValue), at: 0)
}
}
}
lastModifiers = modifiers
for (keycode, modifier) in buffer {
_ = processKey(keycode, modifiers: modifier)
}

lastModifiers = modifiers
rimeUpdate()

case .keyDown:
Expand Down

0 comments on commit 4b6874d

Please sign in to comment.