Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Commit 4955d5f

Browse files
committed
cancel operator-pending on unrecognized key strokes
1 parent 062e41b commit 4955d5f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/vim-state.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class VimState
3636
@activateVisualMode('characterwise') if @mode is 'command'
3737
, 100)
3838

39+
@subscriptions.add atom.keymaps.onDidFailToMatchBinding (e) =>
40+
return unless e.keyboardEventTarget is @editorElement
41+
if @mode is 'operator-pending'
42+
atom.keymaps.cancelPendingState()
43+
@resetCommandMode()
44+
3945
@editorElement.classList.add("vim-mode")
4046
@setupCommandMode()
4147
if settings.startInInsertMode()

spec/vim-state-spec.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,25 @@ describe "VimState", ->
418418
keydown('`')
419419
commandModeInputKeydown('q')
420420
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
421+
422+
describe "unknown key bindings", ->
423+
beforeEach ->
424+
editor.setText "line one\n line two\n"
425+
editor.setCursorBufferPosition [0, 0]
426+
427+
it "cancels short pending operations on unrecognized keybinding", ->
428+
keydown 'c'
429+
keydown 'q' #cq doesn't work, should cancel
430+
keydown 'w'
431+
expect(editor.getCursorBufferPosition()).toEqual [0, 5]
432+
expect(editor.getText()).toBe "line one\n line two\n"
433+
expect(vimState.mode).toEqual 'command'
434+
435+
it "cancels long pending operations on unrecognized keybinding", ->
436+
keydown 'c'
437+
keydown 'i'
438+
keydown '3' #i3 is unrecognized, should cancel the whole `ci3` sequence
439+
keydown 'w'
440+
expect(editor.getCursorBufferPosition()).toEqual [0, 5]
441+
expect(editor.getText()).toBe "line one\n line two\n"
442+
expect(vimState.mode).toEqual 'command'

0 commit comments

Comments
 (0)