mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Merge pull request #1840 from atom/ks-newline-above-indent
Use current indent level for newline above
This commit is contained in:
@@ -1424,6 +1424,26 @@ 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", ->
|
||||
atom.config.set('editor.autoIndent', true)
|
||||
|
||||
editor.setText(' var test')
|
||||
editor.setCursorBufferPosition([0,2])
|
||||
editor.insertNewlineAbove()
|
||||
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0,2]
|
||||
expect(editor.lineForBufferRow(0)).toBe ' '
|
||||
expect(editor.lineForBufferRow(1)).toBe ' var test'
|
||||
|
||||
editor.setText('\n var test')
|
||||
editor.setCursorBufferPosition([1,2])
|
||||
editor.insertNewlineAbove()
|
||||
|
||||
expect(editor.getCursorBufferPosition()).toEqual [1,2]
|
||||
expect(editor.lineForBufferRow(0)).toBe ''
|
||||
expect(editor.lineForBufferRow(1)).toBe ' '
|
||||
expect(editor.lineForBufferRow(2)).toBe ' var test'
|
||||
|
||||
describe ".backspace()", ->
|
||||
describe "when there is a single cursor", ->
|
||||
changeScreenRangeHandler = null
|
||||
|
||||
@@ -622,11 +622,18 @@ class Editor extends Model
|
||||
# Public: For each cursor, insert a newline at the end of the preceding line.
|
||||
insertNewlineAbove: ->
|
||||
@transact =>
|
||||
onFirstLine = @getCursorBufferPosition().row is 0
|
||||
bufferRow = @getCursorBufferPosition().row
|
||||
indentLevel = @indentationForBufferRow(bufferRow)
|
||||
onFirstLine = bufferRow is 0
|
||||
|
||||
@moveCursorToBeginningOfLine()
|
||||
@moveCursorLeft()
|
||||
@insertNewline()
|
||||
@moveCursorUp() if onFirstLine
|
||||
@setIndentationForBufferRow(bufferRow, indentLevel) if @shouldAutoIndent()
|
||||
|
||||
if onFirstLine
|
||||
@moveCursorUp()
|
||||
@moveCursorToEndOfLine()
|
||||
|
||||
# Indent all lines intersecting selections. See {Selection::indent} for more
|
||||
# information.
|
||||
|
||||
Reference in New Issue
Block a user