From afab19938eafa3817bd3a25408378ccef7ea0b03 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 5 Jun 2012 10:32:45 -0700 Subject: [PATCH 1/2] Use wasReversed instead of isReversed to show the local variable stores some temporal state. --- src/app/selection.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/selection.coffee b/src/app/selection.coffee index d62c134af..ba9156e97 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -108,10 +108,10 @@ class Selection extends View { text, shouldOutdent } = @autoIndentText(text) oldBufferRange = @getBufferRange() @editor.destroyFoldsContainingBufferRow(oldBufferRange.end.row) - isReversed = @isReversed() + wasReversed = @isReversed() @clearSelection() newBufferRange = @editor.buffer.change(oldBufferRange, text) - @cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if isReversed + @cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed @autoOutdentText() if shouldOutdent indentSelectedRows: -> From 4f364e8cd8ace755799972e678825099d3a88beb Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 5 Jun 2012 11:29:40 -0700 Subject: [PATCH 2/2] Add newline-below event --- spec/app/editor-spec.coffee | 8 ++++++++ src/app/editor.coffee | 5 +++++ src/app/keymaps/editor.coffee | 7 ++++--- 3 files changed, 17 insertions(+), 3 deletions(-) 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'