diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index fbc9c4498..ea9e203b4 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2127,6 +2127,14 @@ describe "Editor", -> expect(editor.renderedLines.find('.line:eq(2)')).toHaveHtml ' ' expect(editor.getCursorScreenPosition()).toEqual(row: 2, column: 0) + describe "insert-newline-below", -> + it "inserts a newline below the cursor, autoindents it, and moves the cursor to the end of the line", -> + editor.autoIndent = true + editor.trigger "newline-below" + expect(editor.buffer.lineForRow(0)).toBe "var quicksort = function () {" + expect(editor.buffer.lineForRow(1)).toBe " " + expect(editor.getCursorBufferPosition()).toEqual [1,2] + describe "backspace", -> describe "when the cursor is on the middle of the line", -> it "removes the character before the cursor", -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 486d035de..39f30410b 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -105,6 +105,7 @@ class Editor extends View 'select-up': @selectUp 'select-down': @selectDown 'newline': @insertNewline + 'newline-below': @insertNewlineBelow 'tab': @insertTab 'indent-selected-rows': @indentSelectedRows 'outdent-selected-rows': @outdentSelectedRows @@ -702,6 +703,10 @@ class Editor extends View insertNewline: -> @insertText('\n') + insertNewlineBelow: -> + @moveCursorToEndOfLine() + @insertNewline() + insertTab: -> if @getSelection().isEmpty() if @softTabs diff --git a/src/app/keymaps/editor.coffee b/src/app/keymaps/editor.coffee index 783de3ec8..48ca46067 100644 --- a/src/app/keymaps/editor.coffee +++ b/src/app/keymaps/editor.coffee @@ -5,9 +5,10 @@ window.keymap.bindKeys '.editor', 'shift-up': 'select-up' 'shift-down': 'select-down' 'meta-a': 'select-all' - enter: 'newline' - tab: 'tab' - backspace: 'backspace' + 'enter': 'newline' + 'meta-enter': 'newline-below' + 'tab': 'tab' + 'backspace': 'backspace' 'delete': 'delete' 'meta-x': 'cut' 'meta-c': 'copy'