From 3ca11c2cef5f5d9d6fd51dc8ba9909af6237500d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 3 Sep 2015 08:25:24 -0600 Subject: [PATCH] :art: select-line adjustments; Only select single row if row is given --- spec/selection-spec.coffee | 13 +++++++++++++ spec/text-editor-spec.coffee | 6 +++--- src/selection.coffee | 13 ++++--------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/spec/selection-spec.coffee b/spec/selection-spec.coffee index bdccb799d..e81f7906f 100644 --- a/spec/selection-spec.coffee +++ b/spec/selection-spec.coffee @@ -56,6 +56,19 @@ describe "Selection", -> selection.selectToScreenPosition([0, 25]) expect(selection.isReversed()).toBeFalsy() + describe ".selectLine(row)", -> + describe "when passed a row", -> + it "selects the specified row", -> + selection.setBufferRange([[2, 4], [3, 4]]) + selection.selectLine(5) + expect(selection.getBufferRange()).toEqual [[5, 0], [6, 0]] + + describe "when not passed a row", -> + it "selects all rows spanned by the selection", -> + selection.setBufferRange([[2, 4], [3, 4]]) + selection.selectLine() + expect(selection.getBufferRange()).toEqual [[2, 0], [4, 0]] + describe "when only the selection's tail is moved (regression)", -> it "notifies ::onDidChangeRange observers", -> selection.setBufferRange([[2, 0], [2, 10]], reversed: true) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 829c71f80..89acd4fa9 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -1284,7 +1284,7 @@ describe "TextEditor", -> expect(selection2.isReversed()).toBeFalsy() describe ".selectLinesContainingCursors()", -> - it "selects the entire line (including newlines) at given row", -> + it "selects to the entire line (including newlines) at given row", -> editor.setCursorScreenPosition([1, 2]) editor.selectLinesContainingCursors() expect(editor.getSelectedBufferRange()).toEqual [[1, 0], [2, 0]] @@ -1299,8 +1299,8 @@ describe "TextEditor", -> editor.selectLinesContainingCursors() expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [2, 0]] - describe "when selection span multiple row", -> - it "complete selection to contain the entire first and last line", -> + describe "when the selection spans multiple row", -> + it "selects from the beginning of the first line to the last line", -> selection = editor.getLastSelection() selection.setBufferRange [[1, 10], [3, 20]] editor.selectLinesContainingCursors() diff --git a/src/selection.coffee b/src/selection.coffee index ee93842b8..ca87c5ac9 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -324,17 +324,12 @@ class Selection extends Model # # * `row` The line {Number} to select (default: the row of the cursor). selectLine: (row, options) -> - if row? - range = @editor.bufferRangeForBufferRow(row, includeNewline: true) - @setBufferRange(@getBufferRange().union(range), options) - + @setBufferRange(@editor.bufferRangeForBufferRow(row, includeNewline: true), options) else - rowStart = @marker.getStartBufferPosition().row - rangeStart = @editor.bufferRangeForBufferRow(rowStart, includeNewline: true) - rowEnd = @marker.getEndBufferPosition().row - rangeEnd = @editor.bufferRangeForBufferRow(rowEnd, includeNewline: true) - @setBufferRange(@getBufferRange().union(rangeStart).union(rangeEnd), options) + startRange = @editor.bufferRangeForBufferRow(@marker.getStartBufferPosition().row) + endRange = @editor.bufferRangeForBufferRow(@marker.getEndBufferPosition().row, includeNewline: true) + @setBufferRange(startRange.union(endRange), options) @linewise = true @wordwise = false