Merge pull request #8048 from svanharmelen/b-fix-indentation

Fix indentation for languages without indent pattern
This commit is contained in:
Max Brunsfeld
2015-07-23 12:00:28 -07:00
2 changed files with 14 additions and 5 deletions

View File

@@ -2272,6 +2272,17 @@ describe "TextEditor", ->
expect(editor.indentationForBufferRow(1)).toBe 1
expect(editor.indentationForBufferRow(2)).toBe 0
it "indents the new line to the current level when editor.autoIndent is true and no increaseIndentPattern is specified", ->
runs ->
atom.config.set("editor.autoIndent", true)
editor.setGrammar(atom.grammars.selectGrammar("file"))
editor.setText(' if true')
editor.setCursorBufferPosition([0, 8])
editor.insertNewline()
expect(editor.getGrammar()).toBe atom.grammars.nullGrammar
expect(editor.indentationForBufferRow(0)).toBe 1
expect(editor.indentationForBufferRow(1)).toBe 1
it "indents the new line to the correct level when editor.autoIndent is true and using a off-side rule language", ->
waitsForPromise ->
atom.packages.activatePackage('language-coffee-script')

View File

@@ -251,17 +251,15 @@ class LanguageMode
decreaseIndentRegex = @decreaseIndentRegexForScopeDescriptor(scopeDescriptor)
decreaseNextIndentRegex = @decreaseNextIndentRegexForScopeDescriptor(scopeDescriptor)
currentIndentLevel = @editor.indentationForBufferRow(bufferRow)
return currentIndentLevel unless increaseIndentRegex
if options?.skipBlankLines ? true
precedingRow = @buffer.previousNonBlankRow(bufferRow)
return 0 unless precedingRow?
else
precedingRow = bufferRow - 1
return currentIndentLevel if precedingRow < 0
return 0 if precedingRow < 0
desiredIndentLevel = @editor.indentationForBufferRow(precedingRow)
return desiredIndentLevel unless increaseIndentRegex
unless @editor.isBufferRowCommented(precedingRow)
precedingLine = @buffer.lineForRow(precedingRow)
@@ -270,7 +268,7 @@ class LanguageMode
unless @buffer.isRowBlank(precedingRow)
desiredIndentLevel -= 1 if decreaseIndentRegex?.testSync(line)
Math.max(desiredIndentLevel, 0)
# Calculate a minimum indent level for a range of lines excluding empty lines.