WIP: Use a goal column when moving down

Still needs to be cleared when moving horizontally.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-23 13:40:37 -08:00
parent 7d4c236418
commit 1dcebbae45
3 changed files with 38 additions and 11 deletions

View File

@@ -6,7 +6,8 @@ class Cursor extends Template
@pre class: 'cursor', style: 'position: absolute;', => @raw ' '
viewProperties:
setPosition: (@point) ->
setPosition: (point) ->
@point = @parentView.clipPosition(point)
@updateAbsolutePosition()
getPosition: -> @point
@@ -21,11 +22,14 @@ class Cursor extends Template
moveDown: ->
{ row, col } = @getPosition()
if row < @parentView.buffer.numLines() - 1
row++
else
col = @parentView.buffer.getLine(row).length
@setPosition({row, col})
@goalColumn ?= col
@setPosition({row, col: @goalColumn || col})
moveRight: ->
{ row, col } = @getPosition()
@@ -46,7 +50,6 @@ class Cursor extends Template
@setPosition({row, col})
updateAbsolutePosition: ->
position = @parentView.pixelPositionFromPoint(@point)
@css(position)

View File

@@ -42,6 +42,10 @@ class Editor extends Template
@lines.append $$.pre(line)
@setPosition(row: 0, col: 0)
clipPosition: ({row, col}) ->
line = @buffer.getLine(row)
{ row: row, col: Math.min(line.length, col) }
pixelPositionFromPoint: ({row, col}) ->
{ top: row * @lineHeight, left: col * @charWidth }