Skip fold placeholders when moving right

This relies on a new `eagerWrap` option to clipScreenPosition which
will wrap positions inside of atomic line fragments (which is what fold
placeholders are) to the end of the fragment rather than the beginning.
It also wraps positions beyond the end of a hard line to the next line,
which means Cursor.moveRight just has to increment the column, then
call clipPosition with eager wrap set to true to get all the correct
behavior.
This commit is contained in:
Nathan Sobo
2012-02-27 12:45:26 -07:00
parent c2cba8bdcd
commit 22305f350f
7 changed files with 74 additions and 35 deletions

View File

@@ -77,12 +77,7 @@ class Cursor extends View
moveRight: ->
{ row, column } = @getScreenPosition()
if column < @editor.buffer.getLine(row).length
column++
else if row < @editor.buffer.numLines() - 1
row++
column = 0
@setScreenPosition({row, column})
@setScreenPosition(@editor.clipScreenPosition([row, column + 1], true))
moveLeft: ->
{ row, column } = @getScreenPosition()

View File

@@ -211,8 +211,8 @@ class Editor extends View
else
$(window).off 'resize', @_setMaxLineLength
clipScreenPosition: (screenPosition) ->
@lineWrapper.clipScreenPosition(screenPosition)
clipScreenPosition: (screenPosition, eagerWrap=false) ->
@lineWrapper.clipScreenPosition(screenPosition, eagerWrap)
pixelPositionForScreenPosition: ({row, column}) ->
{ top: row * @lineHeight, left: column * @charWidth }

View File

@@ -134,8 +134,8 @@ class LineFolder
bufferPositionForScreenPosition: (screenPosition) ->
@lineMap.bufferPositionForScreenPosition(screenPosition)
clipScreenPosition: (screenPosition) ->
@lineMap.clipScreenPosition(screenPosition)
clipScreenPosition: (screenPosition, eagerWrap=false) ->
@lineMap.clipScreenPosition(screenPosition, eagerWrap)
screenRangeForBufferRange: (bufferRange) ->
@lineMap.screenRangeForBufferRange(bufferRange)

View File

@@ -141,10 +141,9 @@ class LineMap
end = @bufferPositionForScreenPosition(screenRange.end)
new Range(start, end)
clipScreenPosition: (screenPosition) ->
clipScreenPosition: (screenPosition, eagerWrap) ->
screenPosition = Point.fromObject(screenPosition)
debugger if screenPosition.isEqual [7,4]
screenPosition = new Point(Math.max(0, screenPosition.row), Math.max(0, screenPosition.column))
maxRow = @lastScreenRow()
if screenPosition.row > maxRow
@@ -157,8 +156,17 @@ class LineMap
break if nextDelta.isGreaterThan(screenPosition)
screenDelta = nextDelta
maxColumn = screenDelta.column + screenLine.lengthForClipping()
screenDelta.column = Math.min(maxColumn, screenPosition.column)
if screenLine.isAtomic
if eagerWrap and screenPosition.column > screenDelta.column
screenDelta.column = screenDelta.column + screenLine.text.length
else
maxColumn = screenDelta.column + screenLine.text.length
if eagerWrap and screenPosition.column > maxColumn
screenDelta.row++
screenDelta.column = 0
else
screenDelta.column = Math.min(maxColumn, screenPosition.column)
screenDelta
logLines: (start=0, end=@screenLineCount() - 1)->

View File

@@ -93,11 +93,15 @@ class LineWrapper
@lineFolder.bufferRangeForScreenRange(
@lineMap.bufferRangeForScreenRange(screenRange))
clipScreenPosition: (screenPosition) ->
clipScreenPosition: (screenPosition, eagerWrap=false) ->
@lineMap.screenPositionForBufferPosition(
@lineFolder.clipScreenPosition(
@lineMap.bufferPositionForScreenPosition(
@lineMap.clipScreenPosition(screenPosition))))
@lineMap.clipScreenPosition(screenPosition, eagerWrap)
),
eagerWrap
)
)
lineForScreenRow: (screenRow) ->
@linesForScreenRows(screenRow, screenRow)[0]