Skip soft-wrap indentation tokens while selecting

* 🎨 Restructure specs a bit
*  Write specs for this new behavior
This commit is contained in:
Antonio Scandurra
2015-03-13 12:05:18 +01:00
parent c319b80464
commit 8ac4848805
2 changed files with 48 additions and 24 deletions

View File

@@ -1649,17 +1649,29 @@ describe "TextEditor", ->
]
describe "when the selection is empty", ->
it "does not skip soft-wrapped lines shorter than the current column", ->
editor.setSoftWrapped(true)
editor.setDefaultCharWidth(10)
editor.setEditorWidthInChars(40)
describe "when lines are soft-wrapped", ->
beforeEach ->
editor.setSoftWrapped(true)
editor.setDefaultCharWidth(10)
editor.setEditorWidthInChars(40)
editor.setCursorScreenPosition([6, 44])
editor.addSelectionBelow()
expect(editor.getSelectedScreenRanges()).toEqual [
[[6, 44], [6, 44]]
[[7, 26], [7, 26]]
]
it "skips soft-wrap indentation tokens", ->
editor.setCursorScreenPosition([6, 2])
editor.addSelectionBelow()
expect(editor.getSelectedScreenRanges()).toEqual [
[[6, 2], [6, 2]]
[[7, 6], [7, 6]]
]
it "does not skip them if they're shorter than the current column", ->
editor.setCursorScreenPosition([6, 44])
editor.addSelectionBelow()
expect(editor.getSelectedScreenRanges()).toEqual [
[[6, 44], [6, 44]]
[[7, 26], [7, 26]]
]
it "does not skip lines that are shorter than the current column", ->
editor.setCursorBufferPosition([3, 36])
@@ -1750,17 +1762,29 @@ describe "TextEditor", ->
]
describe "when the selection is empty", ->
it "does not skip soft-wrapped lines shorter than the current column", ->
editor.setSoftWrapped(true)
editor.setDefaultCharWidth(10)
editor.setEditorWidthInChars(40)
describe "when lines are soft-wrapped", ->
beforeEach ->
editor.setSoftWrapped(true)
editor.setDefaultCharWidth(10)
editor.setEditorWidthInChars(40)
editor.setCursorScreenPosition([6, 44])
editor.addSelectionAbove()
expect(editor.getSelectedScreenRanges()).toEqual [
[[6, 44], [6, 44]]
[[5, 30], [5, 30]]
]
it "skips soft-wrap indentation tokens", ->
editor.setCursorScreenPosition([8, 0])
editor.addSelectionAbove()
expect(editor.getSelectedScreenRanges()).toEqual [
[[8, 0], [8, 0]]
[[7, 6], [7, 6]]
]
it "does not skip them if they're shorter than the current column", ->
editor.setCursorScreenPosition([6, 44])
editor.addSelectionAbove()
expect(editor.getSelectedScreenRanges()).toEqual [
[[6, 44], [6, 44]]
[[5, 30], [5, 30]]
]
it "does not skip lines that are shorter than the current column", ->
editor.setCursorBufferPosition([6, 36])

View File

@@ -663,14 +663,14 @@ class Selection extends Model
for row in [nextRow..@editor.getLastScreenRow()]
range.start.row = row
range.end.row = row
clippedRange = @editor.clipScreenRange(range)
clippedRange = @editor.clipScreenRange(range, skipSoftWrapIndentation: true)
if range.isEmpty()
continue if range.end.column > 0 and clippedRange.end.column is 0
else
continue if clippedRange.isEmpty()
@editor.addSelectionForScreenRange(range, goalScreenRange: range)
@editor.addSelectionForScreenRange(clippedRange, goalScreenRange: range)
break
# Public: Moves the selection up one row.
@@ -681,14 +681,14 @@ class Selection extends Model
for row in [previousRow..0]
range.start.row = row
range.end.row = row
clippedRange = @editor.clipScreenRange(range)
clippedRange = @editor.clipScreenRange(range, skipSoftWrapIndentation: true)
if range.isEmpty()
continue if range.end.column > 0 and clippedRange.end.column is 0
else
continue if clippedRange.isEmpty()
@editor.addSelectionForScreenRange(range, goalScreenRange: range)
@editor.addSelectionForScreenRange(clippedRange, goalScreenRange: range)
break
# Public: Combines the given selection into this selection and then destroys