From dedde7b22239dc072ae4c3f05d067d9e1d3be525 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 19 Feb 2013 21:01:22 -0800 Subject: [PATCH] Only add newline when insert row exceeds last row Previously if the line before a trailing newline was duplicated an extra newline would inserted with the duplicated line. --- spec/app/editor-spec.coffee | 12 ++++++++++++ src/app/edit-session.coffee | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index fbe514f73..769b0306b 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2680,6 +2680,18 @@ describe "Editor", -> expect(buffer.lineForRow(15)).toBeUndefined() expect(editor.getCursorBufferPosition()).toEqual [14, 0] + describe "when the cursor is on the second to last line and the last line only a newline", -> + it "duplicates the current line below and moves the cursor down one row", -> + editor.moveCursorToBottom() + editor.insertNewline() + editor.setCursorBufferPosition([12]) + editor.trigger 'editor:duplicate-line' + expect(buffer.lineForRow(12)).toBe '};' + expect(buffer.lineForRow(13)).toBe '};' + expect(buffer.lineForRow(14)).toBe '' + expect(buffer.lineForRow(15)).toBeUndefined() + expect(editor.getCursorBufferPosition()).toEqual [13, 0] + describe ".moveEditSessionToIndex(fromIndex, toIndex)", -> describe "when the edit session moves to a later index", -> it "updates the edit session order", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 181415a02..c9b52d350 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -421,7 +421,7 @@ class EditSession bufferRange = new Range([cursorPosition.row], [cursorPosition.row + 1]) insertPosition = new Point(bufferRange.end.row) - if insertPosition.row >= @buffer.getLastRow() + if insertPosition.row > @buffer.getLastRow() @unfoldCurrentRow() if cursorRowFolded @buffer.append("\n#{@getTextInBufferRange(bufferRange)}") @foldCurrentRow() if cursorRowFolded