diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index b6e741e66..292eb28d9 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1413,6 +1413,15 @@ describe "EditSession", -> expect(buffer.lineForRow(11)).toBe " return sort(Array.apply(this, arguments));" expect(editSession.getSelectedBufferRange()).toEqual [[9, 1 + editSession.tabLength], [11, 15 + editSession.tabLength]] + it "does not indent the last row if the selection ends at column 0", -> + editSession.tabLength = 2 + editSession.setSelectedBufferRange([[9,1], [11,0]]) + editSession.indentSelectedRows() + expect(buffer.lineForRow(9)).toBe " };" + expect(buffer.lineForRow(10)).toBe "" + expect(buffer.lineForRow(11)).toBe " return sort(Array.apply(this, arguments));" + expect(editSession.getSelectedBufferRange()).toEqual [[9, 1 + editSession.tabLength], [11, 0]] + describe "when softTabs is disabled", -> it "indents selected lines (that are not empty) and retains selection", -> convertToHardTabs(buffer) @@ -1470,8 +1479,19 @@ describe "EditSession", -> expect(buffer.lineForRow(0)).toBe "var quicksort = function () {" expect(buffer.lineForRow(1)).toBe "var sort = function(items) {" expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;" + expect(buffer.lineForRow(3)).toBe " var pivot = items.shift(), current, left = [], right = [];" expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [3, 15 - editSession.tabLength]] + it "does not outdent the last line of the selection if it ends at column 0", -> + editSession.setSelectedBufferRange([[0,1], [3,0]]) + editSession.outdentSelectedRows() + expect(buffer.lineForRow(0)).toBe "var quicksort = function () {" + expect(buffer.lineForRow(1)).toBe "var sort = function(items) {" + expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;" + expect(buffer.lineForRow(3)).toBe " var pivot = items.shift(), current, left = [], right = [];" + + expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [3, 0]] + describe ".toggleLineCommentsInSelection()", -> it "toggles comments on the selected lines", -> editSession.setSelectedBufferRange([[4, 5], [7, 5]]) diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 6a19e5aa7..4759d1206 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -173,8 +173,8 @@ class Selection @indentSelectedRows() indentSelectedRows: -> - range = @getBufferRange() - for row in [range.start.row..range.end.row] + [start, end] = @getBufferRowRange() + for row in [start..end] @editSession.buffer.insert([row, 0], @editSession.getTabText()) unless @editSession.buffer.lineLengthForRow(row) == 0 normalizeIndent: (text, options) -> @@ -270,10 +270,10 @@ class Selection @editSession.buffer.deleteRows(start, end) outdentSelectedRows: -> - range = @getBufferRange() + [start, end] = @getBufferRowRange() buffer = @editSession.buffer leadingTabRegex = new RegExp("^ {1,#{@editSession.getTabLength()}}|\t") - for row in [range.start.row..range.end.row] + for row in [start..end] if matchLength = buffer.lineForRow(row).match(leadingTabRegex)?[0].length buffer.delete [[row, 0], [row, matchLength]]