diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 87c8727fc..c314fd271 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -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) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index b08d8ab61..b644ac4e7 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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