mirror of
https://github.com/atom/atom.git
synced 2026-02-09 06:05:11 -05:00
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:
@@ -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()
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)->
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user