mirror of
https://github.com/atom/atom.git
synced 2026-02-08 21:55:05 -05:00
When trying to compose operators that don't compose, the op stack is cleared
This commit is contained in:
@@ -21,24 +21,26 @@ class VimMode
|
||||
@setupCommandMode()
|
||||
|
||||
setupCommandMode: ->
|
||||
atom.bindKeys '.command-mode', (e) ->
|
||||
atom.bindKeys '.command-mode', (e) =>
|
||||
if e.keystroke.match /^\d$/
|
||||
return 'command-mode:numeric-prefix'
|
||||
if e.keystroke.match /^.$/
|
||||
@resetCommandMode()
|
||||
return false
|
||||
|
||||
@bindCommandModeKeys
|
||||
'i': 'insert'
|
||||
'd': 'delete'
|
||||
'x': 'delete-right'
|
||||
'h': 'move-left'
|
||||
'j': 'move-down'
|
||||
'k': 'move-up'
|
||||
'l': 'move-right'
|
||||
'w': 'move-to-next-word'
|
||||
'b': 'move-to-previous-word'
|
||||
'left': 'move-left'
|
||||
'right': 'move-right'
|
||||
i: 'insert'
|
||||
d: 'delete'
|
||||
x: 'delete-right'
|
||||
h: 'move-left'
|
||||
j: 'move-down'
|
||||
k: 'move-up'
|
||||
l: 'move-right'
|
||||
w: 'move-to-next-word'
|
||||
b: 'move-to-previous-word'
|
||||
esc: 'reset-command-mode'
|
||||
left: 'move-left'
|
||||
right: 'move-right'
|
||||
|
||||
@handleCommands
|
||||
'insert': => @activateInsertMode()
|
||||
@@ -51,6 +53,7 @@ class VimMode
|
||||
'move-to-next-word': => new motions.MoveToNextWord(@editor)
|
||||
'move-to-previous-word': => new motions.MoveToPreviousWord(@editor)
|
||||
'numeric-prefix': (e) => @numericPrefix(e)
|
||||
'reset-command-mode': => @resetCommandMode()
|
||||
|
||||
bindCommandModeKeys: (bindings) ->
|
||||
prefixedBindings = {}
|
||||
@@ -78,6 +81,9 @@ class VimMode
|
||||
|
||||
@editor.on 'cursor:position-changed', @moveCursorBeforeNewline
|
||||
|
||||
resetCommandMode: ->
|
||||
@opStack = []
|
||||
|
||||
moveCursorBeforeNewline: =>
|
||||
if not @editor.selection.modifyingSelection and @editor.cursor.isOnEOL() and @editor.getCurrentLine().length > 0
|
||||
@editor.setCursorColumn(@editor.getCurrentLine().length - 1)
|
||||
@@ -107,10 +113,14 @@ class VimMode
|
||||
|
||||
processOpStack: ->
|
||||
return unless @topOperator().isComplete()
|
||||
|
||||
poppedOperator = @opStack.pop()
|
||||
if @opStack.length
|
||||
@topOperator().compose(poppedOperator)
|
||||
@processOpStack()
|
||||
try
|
||||
@topOperator().compose(poppedOperator)
|
||||
@processOpStack()
|
||||
catch e
|
||||
(e instanceof operators.OperatorError) and @resetCommandMode() or throw e
|
||||
else
|
||||
poppedOperator.execute()
|
||||
|
||||
|
||||
@@ -61,4 +61,4 @@ class MoveToNextWord extends Motion
|
||||
column = nextLineMatch?.index or 0
|
||||
{ row, column }
|
||||
|
||||
module.exports = { MoveLeft, MoveRight, MoveUp, MoveDown, MoveToNextWord, MoveToPreviousWord }
|
||||
module.exports = { Motion, MoveLeft, MoveRight, MoveUp, MoveDown, MoveToNextWord, MoveToPreviousWord }
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
_ = require 'underscore'
|
||||
|
||||
class OperatorError
|
||||
constructor: (@message) ->
|
||||
@name = "Operator Error"
|
||||
|
||||
class NumericPrefix
|
||||
count: null
|
||||
complete: null
|
||||
@@ -43,8 +47,11 @@ class Delete
|
||||
@editor.setCursorPosition([@editor.getCursorRow(), 0])
|
||||
|
||||
compose: (motion) ->
|
||||
if not motion.select
|
||||
throw new OperatorError("Delete must compose with a motion")
|
||||
|
||||
@motion = motion
|
||||
@complete = true
|
||||
|
||||
module.exports = { NumericPrefix, Delete }
|
||||
module.exports = { NumericPrefix, Delete, OperatorError }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user