Merge pull request #8105 from atom/as-emit-did-insert-on-paste

Emit `did-insert-text` on `pasteText()`
This commit is contained in:
Nathan Sobo
2015-07-28 07:45:23 -06:00
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