mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Merge pull request #2045 from atom/cj-tabs-be-weird
Make Atom smarter about guessing if a file uses soft or hard tabs
This commit is contained in:
@@ -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()
|
||||
|
||||
8
spec/fixtures/sample-with-tabs-and-initial-comment.js
vendored
Normal file
8
spec/fixtures/sample-with-tabs-and-initial-comment.js
vendored
Normal file
@@ -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.');
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user