Merge pull request #1859 from atom/ks-newline-above-indent-level

Only alter indentation when it is too low
This commit is contained in:
Kevin Sawicki
2014-04-11 10:39:50 -07:00
2 changed files with 13 additions and 2 deletions

View File

@@ -1424,7 +1424,7 @@ describe "Editor", ->
editor.undo()
expect(editor.getCursorBufferPosition()).toEqual [3,4]
it "indents the new line to the same indent level as the current line when editor.autoIndent is true", ->
it "indents the new line to the correct level when editor.autoIndent is true", ->
atom.config.set('editor.autoIndent', true)
editor.setText(' var test')
@@ -1444,6 +1444,15 @@ describe "Editor", ->
expect(editor.lineForBufferRow(1)).toBe ' '
expect(editor.lineForBufferRow(2)).toBe ' var test'
editor.setText('function() {\n}')
editor.setCursorBufferPosition([1,1])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [1,2]
expect(editor.lineForBufferRow(0)).toBe 'function() {'
expect(editor.lineForBufferRow(1)).toBe ' '
expect(editor.lineForBufferRow(2)).toBe '}'
describe ".backspace()", ->
describe "when there is a single cursor", ->
changeScreenRangeHandler = null

View File

@@ -630,7 +630,9 @@ class Editor extends Model
@moveCursorToBeginningOfLine()
@moveCursorLeft()
@insertNewline()
@setIndentationForBufferRow(bufferRow, indentLevel) if @shouldAutoIndent()
if @shouldAutoIndent() and @indentationForBufferRow(bufferRow) < indentLevel
@setIndentationForBufferRow(bufferRow, indentLevel)
if onFirstLine
@moveCursorUp()