mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Add indentBasis metadata to pasteboard when copying text
This allows indent to be normalized properly even if the leading whitespace isn't copied from the first line.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user