Map h to MoveRight

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-24 10:06:25 -08:00
parent a647fa4220
commit 59086a1131
4 changed files with 26 additions and 7 deletions

View File

@@ -119,6 +119,13 @@ describe "VimMode", ->
editor.trigger keydownEvent('h')
expect(editor.getPosition()).toEqual(column: 0, row: 1)
describe "the j keybinding", ->
it "moves the cursor down, but not to the end of the last line", ->
editor.trigger keydownEvent 'j'
expect(editor.getPosition()).toEqual(column: 1, row: 2)
editor.trigger keydownEvent 'j'
expect(editor.getPosition()).toEqual(column: 1, row: 2)
describe "the k keybinding", ->
it "moves the cursor up, but not to the beginning of the first line", ->
editor.trigger keydownEvent('k')
@@ -126,12 +133,13 @@ describe "VimMode", ->
editor.trigger keydownEvent('k')
expect(editor.getPosition()).toEqual(column: 1, row: 0)
describe "the j keybinding", ->
it "moves the cursor down, but not to the end of the last line", ->
editor.trigger keydownEvent 'j'
expect(editor.getPosition()).toEqual(column: 1, row: 2)
editor.trigger keydownEvent 'j'
expect(editor.getPosition()).toEqual(column: 1, row: 2)
fdescribe "the l keybinding", ->
it "moves the cursor right, but not to the next line", ->
editor.setPosition(column: 4, row: 1)
editor.trigger keydownEvent('l')
expect(editor.getPosition()).toEqual(column: 5, row: 1)
editor.trigger keydownEvent('l')
expect(editor.getPosition()).toEqual(column: 5, row: 1)
describe "the w keybinding", ->
it "moves the cursor to the beginning of the next word", ->

View File

@@ -89,6 +89,9 @@ class Editor extends Template
moveLeft: ->
@aceEditor.navigateLeft()
moveRight: ->
@aceEditor.navigateRight()
moveUp: ->
@aceEditor.navigateUp()

View File

@@ -32,6 +32,7 @@ class VimMode
'h': 'move-left'
'j': 'move-down'
'k': 'move-up'
'l': 'move-right'
'w': 'move-to-next-word'
@handleCommands
@@ -41,6 +42,7 @@ class VimMode
'move-left': => new motions.MoveLeft(@editor)
'move-up': => new motions.MoveUp(@editor)
'move-down': => new motions.MoveDown @editor
'move-right': => new motions.MoveRight @editor
'move-to-next-word': => new motions.MoveToNextWord(@editor)
'numeric-prefix': (e) => @numericPrefix(e)

View File

@@ -14,6 +14,12 @@ class MoveLeft extends Motion
position.column-- if position.column > 0
@editor.selectToPosition position
class MoveRight extends Motion
execute: ->
{column, row} = @editor.getPosition()
currentLineLength = @editor.getLineText(row).length
@editor.moveRight() if column < currentLineLength
class MoveUp extends Motion
execute: ->
{column, row} = @editor.getPosition()
@@ -59,5 +65,5 @@ class SelectLines extends Motion
@editor.setPosition(column: 0, row: @editor.getRow())
@editor.selectToPosition(column: 0, row: @editor.getRow() + @count)
module.exports = { MoveLeft, MoveUp, MoveDown, MoveToNextWord, SelectLines }
module.exports = { MoveLeft, MoveRight, MoveUp, MoveDown, MoveToNextWord, SelectLines }