From 588d9b97eb4255d4f0febb0c3ba5d5d03aa073e1 Mon Sep 17 00:00:00 2001 From: Ivan Zuzak Date: Wed, 11 Jun 2014 18:31:37 +0200 Subject: [PATCH 1/2] Unindent only if the tab is at the start of the line --- src/selection.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/selection.coffee b/src/selection.coffee index c04fc7231..3092617b4 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -495,7 +495,7 @@ class Selection extends Model outdentSelectedRows: -> [start, end] = @getBufferRowRange() buffer = @editor.buffer - leadingTabRegex = new RegExp("^ {1,#{@editor.getTabLength()}}|\t") + leadingTabRegex = new RegExp("^( {1,#{@editor.getTabLength()}}|\t)") for row in [start..end] if matchLength = buffer.lineForRow(row).match(leadingTabRegex)?[0].length buffer.delete [[row, 0], [row, matchLength]] From 07308a4e04a69566560fb75f2f2d422b9c59acfa Mon Sep 17 00:00:00 2001 From: Ivan Zuzak Date: Wed, 11 Jun 2014 19:02:14 +0200 Subject: [PATCH 2/2] :white_check_mark: Add test for outdenting with tabs after normal characters --- spec/editor-spec.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 485ebe0ef..225709f0e 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -2258,6 +2258,15 @@ describe "Editor", -> editor.outdentSelectedRows() expect(buffer.lineForRow(0)).toBe "var quicksort = function () {" + it "outdents only up to the first non-space non-tab character", -> + editor.insertText(' \tfoo\t ') + editor.outdentSelectedRows() + expect(buffer.lineForRow(0)).toBe "\tfoo\t var quicksort = function () {" + editor.outdentSelectedRows() + expect(buffer.lineForRow(0)).toBe "foo\t var quicksort = function () {" + editor.outdentSelectedRows() + expect(buffer.lineForRow(0)).toBe "foo\t var quicksort = function () {" + describe "when one line is selected", -> it "outdents line and retains editor", -> editor.setSelectedBufferRange([[1,4], [1,14]])