Retain goal column when moving up on first line.

Also: Respect a goal column of 0 when moving down on last line and then
back up. (Unlike TextMate)
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-23 14:56:30 -08:00
parent 101d20692d
commit 81fc69120f
2 changed files with 84 additions and 72 deletions

View File

@@ -19,31 +19,32 @@ class Cursor extends Template
moveUp: ->
{ row, col } = @getPosition()
if row is 0
col = 0
col = @goalColumn if @goalColumn?
if row > 0
@setPosition({row: row - 1, col: col})
else
row--
col = @goalColumn if @goalColumn
@setPosition({row, col})
@goalColumn ?= col
moveDown: ->
{ row, col } = @getPosition()
col = @goalColumn if @goalColumn
if row < @parentView.buffer.numLines() - 1
row++
@setPosition({row, col})
else
@moveToEndOfLine()
@moveToLineStart()
@goalColumn = col
moveToEndOfLine: ->
moveDown: ->
{ row, col } = @getPosition()
col = @goalColumn if @goalColumn?
if row < @parentView.buffer.numLines() - 1
@setPosition({row: row + 1, col: col})
else
@moveToLineEnd()
@goalColumn = col
moveToLineEnd: ->
{ row } = @getPosition()
@setPosition({ row, col: @parentView.buffer.getLine(row).length })
moveToLineStart: ->
{ row } = @getPosition()
@setPosition({ row, col: 0 })
moveRight: ->
{ row, col } = @getPosition()
if col < @parentView.buffer.getLine(row).length