Use cursor:position-changed to make sure cursor never gets to end of line in command mode.

The exception being an empty line.
This commit is contained in:
Corey Johnson
2012-02-06 14:56:05 -08:00
parent f3eb6fc66c
commit bac59b7abf
4 changed files with 26 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ class VimMode
requireStylesheet 'vim-mode.css'
@opStack = []
@editor.addClass('command-mode')
@activateCommandMode()
atom.bindKeys '.editor', '<esc>': 'activate-command-mode'
@editor.on 'activate-command-mode', => @activateCommandMode()
@@ -70,6 +70,11 @@ class VimMode
@editor.removeClass('insert-mode')
@editor.addClass('command-mode')
@editor.on 'cursor:position-changed', =>
moveCursorBeforeNewline = not @editor.selection.modifyingSelection and @editor.cursor.isOnEOL() and @editor.getCurrentLine().length > 0
if moveCursorBeforeNewline
@editor.setCursorColumn(@editor.getCurrentLine().length - 1)
numericPrefix: (e) ->
num = parseInt(e.keyEvent.keystroke)
if @topOperator() instanceof operators.NumericPrefix

View File

@@ -4,10 +4,7 @@ class Command
class DeleteRight extends Command
execute: ->
@editor.delete()
isOnEOL = @editor.getCursorColumn() == @editor.getCurrentLine().length
if isOnEOL
@editor.setCursorColumn(@editor.getCursorColumn() - 1)
@editor.delete() unless @editor.getCurrentLine().length == 0
module.exports = { DeleteRight }

View File

@@ -17,8 +17,7 @@ class MoveLeft extends Motion
class MoveRight extends Motion
execute: ->
{column, row} = @editor.getCursorPosition()
isOnLastCharachter = @editor.getCursorColumn() == @editor.getCurrentLine().length - 1
@editor.moveCursorRight() unless isOnLastCharachter
@editor.moveCursorRight()
class MoveUp extends Motion
execute: ->