This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Don’t handle or replay keystrokes during IME composition #178
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ class KeymapManager | |
@[key] = value for key, value of options | ||
@watchSubscriptions = {} | ||
@customKeystrokeResolvers = [] | ||
@compositionInProgress = false | ||
@clear() | ||
|
||
# Public: Clear all registered key bindings and enqueued keystrokes. For use | ||
|
@@ -491,6 +492,12 @@ class KeymapManager | |
# keystroke is the atom keybind syntax, e.g. 'ctrl-a' | ||
keystroke = @keystrokeForKeyboardEvent(event) | ||
|
||
# If an input method editor (IME) is visible, allow the operating system to | ||
# fully handle all keyboard events to prevent interference with menu | ||
# interactions. | ||
if @compositionInProgress | ||
return | ||
|
||
# We dont care about bare modifier keys in the bindings. e.g. `ctrl y` isnt going to work. | ||
if event.type is 'keydown' and @queuedKeystrokes.length > 0 and isBareModifier(keystroke) | ||
event.preventDefault() | ||
|
@@ -622,10 +629,16 @@ class KeymapManager | |
# event. This means the current event has removed any hope that the queued | ||
# key events will ever match any binding. So we will clear the state and | ||
# start over after replaying the events in `terminatePendingState`. | ||
@terminatePendingState() | ||
@terminatePendingState() if event.type is 'keyup' | ||
else | ||
@clearQueuedKeystrokes() | ||
|
||
handleCompositionStart: -> | ||
@compositionInProgress = true | ||
|
||
handleCompositionEnd: -> | ||
@compositionInProgress = false | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do these actually get called? The only call sites I see are in specs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They'll have to get called in Atom with some new event handlers. |
||
# Public: Translate a keydown event to a keystroke string. | ||
# | ||
# * `event` A `KeyboardEvent` of type 'keydown' | ||
|
@@ -762,16 +775,17 @@ class KeymapManager | |
@cancelPendingState() | ||
@clearQueuedKeystrokes() | ||
|
||
keyEventOptions = | ||
replay: true | ||
disabledBindings: bindingsToDisable | ||
unless @compositionInProgress | ||
keyEventOptions = | ||
replay: true | ||
disabledBindings: bindingsToDisable | ||
|
||
for event in eventsToReplay | ||
keyEventOptions.disabledBindings = bindingsToDisable | ||
@handleKeyboardEvent(event, keyEventOptions) | ||
for event in eventsToReplay | ||
keyEventOptions.disabledBindings = bindingsToDisable | ||
@handleKeyboardEvent(event, keyEventOptions) | ||
|
||
# We can safely re-enable the bindings when we no longer have any partial matches | ||
bindingsToDisable = null if bindingsToDisable? and not @pendingPartialMatches? | ||
# We can safely re-enable the bindings when we no longer have any partial matches | ||
bindingsToDisable = null if bindingsToDisable? and not @pendingPartialMatches? | ||
|
||
if fromTimeout and @pendingPartialMatches? | ||
@terminatePendingState(true) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning behind this change? I did some testing with my recent changes and it seems to work fine but I couldn't figure out why you added this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
compositionstart
happens afterkeydown
, we need to wait until keyup to know whether or not replay should be suppressed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, duh. Connecting that now with what you said in the PR description. Cool.