From 53fc625534fcaed4093fc836e982bf203a01f2a5 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 5 Mar 2012 15:51:56 -0800 Subject: [PATCH] Inserting a newline indents the cursor (based on information from previous line) --- spec/atom/editor-spec.coffee | 10 ++++++++-- src/atom/editor.coffee | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index c374f848e..0f377433d 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -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] - - diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 6782037c7..8aaad5663 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -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()