Inserting a newline indents the cursor (based on information from previous line)

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-03-05 15:51:56 -08:00
parent 3ff8a1e92c
commit 53fc625534
2 changed files with 16 additions and 3 deletions

View File

@ -440,6 +440,14 @@ describe "Editor", ->
editor.lines.trigger 'mouseup'
expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;"
describe "auto indent/outdent", ->
describe "when newline is inserted", ->
it "indents cursor based on the indentation of previous line", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\n")
expect(editor.buffer.getLine(5)).toEqual(" ")
describe "selection", ->
selection = null
@ -829,5 +837,3 @@ describe "Editor", ->
expect(editor.lines.find('.line:eq(5)').text()).toBe ' current = items.shift();'
expect(editor.getCursorBufferPosition()).toEqual [4, 29]

View File

@ -300,7 +300,14 @@ class Editor extends View
selectToBufferPosition: (position) ->
@selection.selectToBufferPosition(position)
insertText: (text) -> @selection.insertText(text)
insertText: (text) ->
if text[0] == "\n"
tab = " "
state = @lineWrapper.lineForScreenRow(@getRow).state
indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), tab)
text = text[0] + indent + text[1..]
@selection.insertText(text)
cutSelection: -> @selection.cut()
copySelection: -> @selection.copy()