8000 beep on unrecognized commands to warn the user by jacekkopecky · Pull Request #781 · atom/vim-mode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

beep on unrecognized commands to warn the user #781

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{Range} = require 'atom'

# copied from atom/atom-keymap src/helpers.coffee
AtomModifierRegex = /(ctrl|alt|shift|cmd)$/

module.exports =
# Public: Determines if a string should be considered linewise or character
#
Expand All @@ -25,3 +28,8 @@ module.exports =
newRange
else
oldRange.union(newRange)

# copied and simplified from atom/atom-keymap src/helpers.coffee
# see atom/atom-keymap#97
isAtomModifier: (keystroke) ->
AtomModifierRegex.test(keystroke)
6 changes: 6 additions & 0 deletions lib/vim-state.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class VimState
else
@activateNormalMode()

@subscriptions.add atom.keymaps.onDidFailToMatchBinding (e) =>
return unless e.keyboardEventTarget is @editorElement
return if Utils.isAtomModifier(e.keystrokes)
if e.keystrokes.indexOf(' ') < 0 and @mode isnt "insert"
atom.beep()

destroy: ->
unless @destroyed
@destroyed = true
Expand Down
41 changes: 41 additions & 0 deletions spec/vim-state-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,44 @@ describe "VimState", ->
keydown('`')
normalModeInputKeydown('q')
expect(editor.getCursorScreenPosition()).toEqual [1, 2]

describe "unknown key bindings", ->
beforeEach ->
editor.setText "line one\n line two\n"
editor.setCursorBufferPosition [0, 0]

describe "in operator-pending mode", ->
beforeEach ->
keydown 'c'

it "beeps on unrecognized keybinding, ignores them", ->
keydown 'q' #cq doesn't work, q not implemented so will beep
expect(atom.beep).toHaveBeenCalled()
keydown 'w'
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
expect(editor.getText()).toBe " one\n line two\n"
expect(vimState.mode).toEqual 'insert'

it "replays long pending operations and beeps on short unrecognized keybinding", ->
keydown 'i'
keydown '3' # i3 is unrecognized, replays 'i' and beeps, replays '3' which is recognized
# FIXME for some reason, the replay of 'i' in specs doesn't go to the editor so the beep doesn't happen
# expect(atom.beep).toHaveBeenCalled()
keydown 'w'
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
expect(editor.getText()).toBe "two\n"
expect(vimState.mode).toEqual 'insert'

describe "in visual mode", ->
beforeEach ->
keydown 'v'

it "cancels whole unrecognized keybinding", ->
keydown 'i'
keydown '3' # i3 is unrecognized, replays 'i' and beeps, replays '3' which is recognized
# FIXME for some reason, the replay of 'i' in specs doesn't go to the editor so the beep doesn't happen
# expect(atom.beep).toHaveBeenCalled()
keydown 'w'
expect(editor.getCursorBufferPosition()).toEqual [1, 7]
expect(editor.getSelectedText()).toBe "line one\n line t"
expect(vimState.mode).toEqual 'visual'
0