From 6bb260140b1f08ce771380c06f1dc4234ba09ffd Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 7 May 2014 12:18:05 -0700 Subject: [PATCH 1/2] Don't use comment lines to determine soft/hard tabs. Closes atom/language-php#24 Closes #1733 --- spec/editor-spec.coffee | 4 ++++ .../sample-with-tabs-and-initial-comment.js | 8 ++++++++ src/editor.coffee | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/sample-with-tabs-and-initial-comment.js diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index ac2d24ddf..91a282f55 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -2594,6 +2594,10 @@ describe "Editor", -> atom.workspace.open('sample-with-tabs.coffee', softTabs: true).then (editor) -> expect(editor.getSoftTabs()).toBeFalsy() + waitsForPromise -> + atom.workspace.open('sample-with-tabs-and-initial-comment.js', softTabs: true).then (editor) -> + expect(editor.getSoftTabs()).toBeFalsy() + waitsForPromise -> atom.workspace.open(null, softTabs: false).then (editor) -> expect(editor.getSoftTabs()).toBeFalsy() diff --git a/spec/fixtures/sample-with-tabs-and-initial-comment.js b/spec/fixtures/sample-with-tabs-and-initial-comment.js new file mode 100644 index 000000000..996d4dff0 --- /dev/null +++ b/spec/fixtures/sample-with-tabs-and-initial-comment.js @@ -0,0 +1,8 @@ +/** + * Look, this is a comment. Don't go making assumtions that I want soft tabs + * because this block comment has leading spaces, Geez. + */ + +if (beNice) { + console.log('Thank you for being nice.'); +} diff --git a/src/editor.coffee b/src/editor.coffee index 38dfb40f1..c790ea352 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -160,7 +160,7 @@ class Editor extends Model @displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrap}) @buffer = @displayBuffer.buffer - @softTabs = @buffer.usesSoftTabs() ? @softTabs ? atom.config.get('editor.softTabs') ? true + @softTabs = @usesSoftTabs() ? @softTabs ? atom.config.get('editor.softTabs') ? true for marker in @findMarkers(@getSelectionMarkerAttributes()) marker.setAttributes(preserveFolds: true) @@ -317,6 +317,19 @@ class Editor extends Model # Public: Set the on-screen length of tab characters. setTabLength: (tabLength) -> @displayBuffer.setTabLength(tabLength) + # Public: Determine if the buffer uses hard or soft tabs. + # + # Returns `true` if the first non-comment line with leading whitespace starts + # with a space character. Returns `false` if it starts with a hard tab (`\t`). + # + # Returns a {Boolean}, + usesSoftTabs: -> + for bufferRow in [0..@buffer.getLastRow()] + continue if @displayBuffer.tokenizedBuffer.lineForScreenRow(bufferRow).isComment() + if match = @buffer.lineForRow(bufferRow).match(/^\s/) + return match[0][0] != '\t' + undefined + # Public: Clip the given {Point} to a valid position in the buffer. # # If the given {Point} describes a position that is actually reachable by the From 8c6cdf7358d86eef6b11be1cf534a349aedb493f Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 7 May 2014 12:34:34 -0700 Subject: [PATCH 2/2] Upgrade to text-buffer@2.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3028f4dbf..fbe536603 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "serializable": "^1", "space-pen": "3.1.1", "temp": "0.5.0", - "text-buffer": "^2.2.0", + "text-buffer": "^2.2.1", "theorist": "^1", "underscore-plus": "^1.2.1", "vm-compatibility-layer": "0.1.0"