Emit did-insert-text on pasteText()

This commit is contained in:
Antonio Scandurra
2015-07-28 10:38:11 +02:00
parent b00c148de8
commit d46fea9d10
2 changed files with 17 additions and 2 deletions

View File

@@ -3015,6 +3015,16 @@ describe "TextEditor", ->
expect(insertedStrings).toEqual ["hello"]
it "notifies ::onDidInsertText observers", ->
insertedStrings = []
editor.onDidInsertText ({text, range}) ->
insertedStrings.push(text)
atom.clipboard.write("hello")
editor.pasteText()
expect(insertedStrings).toEqual ["hello"]
describe "when `autoIndentOnPaste` is true", ->
beforeEach ->
atom.config.set("editor.autoIndentOnPaste", true)

View File

@@ -2627,14 +2627,19 @@ class TextEditor extends Model
if containsNewlines or not cursor.hasPrecedingCharactersOnLine()
options.indentBasis ?= indentBasis
range = null
if fullLine and selection.isEmpty()
oldPosition = selection.getBufferRange().start
selection.setBufferRange([[oldPosition.row, 0], [oldPosition.row, 0]])
selection.insertText(text, options)
range = selection.insertText(text, options)
newPosition = oldPosition.translate([1, 0])
selection.setBufferRange([newPosition, newPosition])
else
selection.insertText(text, options)
range = selection.insertText(text, options)
didInsertEvent = {text, range}
@emit('did-insert-text', didInsertEvent) if includeDeprecatedAPIs
@emitter.emit 'did-insert-text', didInsertEvent
# Public: For each selection, if the selection is empty, cut all characters
# of the containing line following the cursor. Otherwise cut the selected