diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 8a1234f49..16a6050ff 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1328,6 +1328,18 @@ describe "EditSession", -> expect(editSession.buffer.lineForRow(0)).toBe "var first = function () {" expect(buffer.lineForRow(1)).toBe " var first = function(items) {" + it "preserves the indent level when copying and pasting multiple lines", -> + editSession.setAutoIndent(true) + editSession.setSelectedBufferRange([[4, 4], [7, 5]]) + editSession.copySelectedText() + editSession.setCursorBufferPosition([10, 0]) + editSession.pasteText() + + expect(editSession.lineForBufferRow(10)).toBe " while(items.length > 0) {" + expect(editSession.lineForBufferRow(11)).toBe " current = items.shift();" + expect(editSession.lineForBufferRow(12)).toBe " current < pivot ? left.push(current) : right.push(current);" + expect(editSession.lineForBufferRow(13)).toBe " }" + describe ".indentSelectedRows()", -> beforeEach -> editSession.tabLength = 2 diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index b7f71dd69..2cca596df 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -202,7 +202,8 @@ class EditSession maintainPasteboard = true pasteText: -> - @insertText(pasteboard.read()[0], normalizeIndent: true) + [text, metadata] = pasteboard.read() + @insertText(text, _.extend(metadata ? {}, normalizeIndent: true)) undo: -> @buffer.undo(this) diff --git a/src/app/selection.coffee b/src/app/selection.coffee index d8d3cca43..ca93b4538 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -269,8 +269,13 @@ class Selection copy: (maintainPasteboard=false) -> return if @isEmpty() text = @editSession.buffer.getTextInRange(@getBufferRange()) - text = pasteboard.read()[0] + "\n" + text if maintainPasteboard - pasteboard.write(text) + if maintainPasteboard + [currentText, metadata] = pasteboard.read() + text = currentText + '\n' + text + else + metadata = { indentBasis: @editSession.indentationForBufferRow(@getBufferRange().start.row) } + + pasteboard.write(text, metadata) fold: -> range = @getBufferRange()