From 86c720af8139f48a74a0048857fb8d48297cf466 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 10 Mar 2014 17:54:34 -0700 Subject: [PATCH] Normalize all tabs, not just the first one Refs atom/language-javascript#10 --- spec/editor-spec.coffee | 16 ++++++++++++++++ src/editor.coffee | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index f628c3f57..6dac3be9e 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -2866,3 +2866,19 @@ describe "Editor", -> {tokens} = editor.lineForScreenRow(0) expect(tokens[2].value).toBe "SELECT" expect(tokens[2].scopes).toEqual ["source.js", "comment.line.double-slash.js", "keyword.other.DML.sql"] + + describe ".normalizeTabsInBufferRange()", -> + fit "normalizes tabs depending on the editor's soft tab/tab length settings", -> + editor.setTabLength(1) + editor.setSoftTabs(true) + editor.setText('\t\t\t') + editor.normalizeTabsInBufferRange([[0, 0], [0, 1]]) + expect(editor.getText()).toBe ' \t\t' + + editor.setTabLength(2) + editor.normalizeTabsInBufferRange([[0, 0], [Infinity, Infinity]]) + expect(editor.getText()).toBe ' ' + + editor.setSoftTabs(false) + editor.normalizeTabsInBufferRange([[0, 0], [Infinity, Infinity]]) + expect(editor.getText()).toBe ' ' diff --git a/src/editor.coffee b/src/editor.coffee index a4569bed4..5cd4f2676 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -679,7 +679,7 @@ class Editor extends Model # {Range}. normalizeTabsInBufferRange: (bufferRange) -> return unless @getSoftTabs() - @scanInBufferRange /\t/, bufferRange, ({replace}) => replace(@getTabText()) + @scanInBufferRange /\t/g, bufferRange, ({replace}) => replace(@getTabText()) # Public: For each selection, if the selection is empty, cut all characters # of the containing line following the cursor. Otherwise cut the selected