mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
WIP: Use a goal column when moving down
Still needs to be cleared when moving horizontally.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user