Use softWrapAtNewLines in moveDown and moveUp

/cc: @nathansobo
This commit is contained in:
Antonio Scandurra 2015-02-19 20:01:37 +01:00
parent d3b7ea475f
commit 79c16a0d00
4 changed files with 34 additions and 14 deletions

View File

@ -622,10 +622,10 @@ describe "DisplayBuffer", ->
expect(displayBuffer.clipScreenPosition([3, 58])).toEqual [3, 50]
expect(displayBuffer.clipScreenPosition([3, 1000])).toEqual [3, 50]
it "clips positions inside a phantom token to the beginning of the line", ->
expect(displayBuffer.clipScreenPosition([4, 0])).toEqual [4, 4]
expect(displayBuffer.clipScreenPosition([4, 1])).toEqual [4, 4]
expect(displayBuffer.clipScreenPosition([4, 3])).toEqual [4, 4]
it "wraps positions at the end of previous soft-wrapped line", ->
expect(displayBuffer.clipScreenPosition([4, 0])).toEqual [3, 50]
expect(displayBuffer.clipScreenPosition([4, 1])).toEqual [3, 50]
expect(displayBuffer.clipScreenPosition([4, 3])).toEqual [3, 50]
describe "when wrapAtSoftNewlines is true", ->
it "wraps positions at the end of soft-wrapped lines to the next screen line", ->
@ -634,10 +634,10 @@ describe "DisplayBuffer", ->
expect(displayBuffer.clipScreenPosition([3, 58], wrapAtSoftNewlines: true)).toEqual [4, 4]
expect(displayBuffer.clipScreenPosition([3, 1000], wrapAtSoftNewlines: true)).toEqual [4, 4]
it "wraps positions inside a phantom token to the previous line", ->
expect(displayBuffer.clipScreenPosition([4, 0], wrapAtSoftNewlines: true)).toEqual [3, 50]
expect(displayBuffer.clipScreenPosition([4, 1], wrapAtSoftNewlines: true)).toEqual [3, 50]
expect(displayBuffer.clipScreenPosition([4, 3], wrapAtSoftNewlines: true)).toEqual [3, 50]
it "clips positions to the beginning of the line", ->
expect(displayBuffer.clipScreenPosition([4, 0], wrapAtSoftNewlines: true)).toEqual [4, 4]
expect(displayBuffer.clipScreenPosition([4, 1], wrapAtSoftNewlines: true)).toEqual [4, 4]
expect(displayBuffer.clipScreenPosition([4, 3], wrapAtSoftNewlines: true)).toEqual [4, 4]
describe "when skipAtomicTokens is false (the default)", ->
it "clips screen positions in the middle of atomic tab characters to the beginning of the character", ->

View File

@ -334,6 +334,17 @@ describe "TextEditor", ->
expect(editor.getCursors()).toEqual [cursor1]
expect(cursor1.getBufferPosition()).toEqual [0,0]
describe "when the cursor was moved down from the beginning of an indented soft-wrapped line", ->
it "moves to the beginning of the previous line", ->
editor.setSoftWrapped(true)
editor.setEditorWidthInChars(50)
editor.setCursorScreenPosition([3, 0])
editor.moveDown()
editor.moveDown()
editor.moveUp()
expect(editor.getCursorScreenPosition()).toEqual [4, 4]
describe ".moveDown()", ->
it "moves the cursor down", ->
editor.setCursorScreenPosition([2, 2])
@ -375,6 +386,16 @@ describe "TextEditor", ->
editor.moveUp()
expect(editor.getCursorScreenPosition().column).toBe 0
describe "when the cursor is at the beginning of an indented soft-wrapped line", ->
it "moves to the beginning of the line's continuation on the next screen row", ->
editor.setSoftWrapped(true)
editor.setEditorWidthInChars(50)
editor.setCursorScreenPosition([3, 0])
editor.moveDown()
expect(editor.getCursorScreenPosition()).toEqual [4, 4]
describe "when there is a selection", ->
beforeEach ->
editor.setSelectedBufferRange([[4, 9],[5, 10]])

View File

@ -271,7 +271,7 @@ class Cursor extends Model
{ row, column } = @getScreenPosition()
column = @goalColumn if @goalColumn?
@setScreenPosition({row: row - rowCount, column: column})
@setScreenPosition({row: row - rowCount, column: column}, wrapAtSoftNewlines: true)
@goalColumn = column
# Public: Moves the cursor down one screen row.
@ -288,7 +288,7 @@ class Cursor extends Model
{ row, column } = @getScreenPosition()
column = @goalColumn if @goalColumn?
@setScreenPosition({row: row + rowCount, column: column})
@setScreenPosition({row: row + rowCount, column: column}, wrapAtSoftNewlines: true)
@goalColumn = column
# Public: Moves the cursor left one screen column.
@ -304,14 +304,13 @@ class Cursor extends Model
else
{row, column} = @getScreenPosition()
originalRow = row
while columnCount > column and row > 0
columnCount -= column
column = @editor.lineTextForScreenRow(--row).length
columnCount-- # subtract 1 for the row move
column = column - columnCount
@setScreenPosition({row, column}, wrapAtSoftNewlines: originalRow == row)
@setScreenPosition({row, column})
# Public: Moves the cursor right one screen column.
#

View File

@ -846,10 +846,10 @@ class DisplayBuffer extends Model
column = screenLine.clipScreenColumn(maxScreenColumn - 1)
else if screenLine.isColumnInsidePhantomToken(column)
if wrapAtSoftNewlines
column = screenLine.clipScreenColumn(0)
else
row--
column = @screenLines[row].getMaxScreenColumn() - 1
else
column = screenLine.clipScreenColumn(0)
else if wrapBeyondNewlines and column > maxScreenColumn and row < @getLastRow()
row++
column = 0