mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Merge pull request #8105 from atom/as-emit-did-insert-on-paste
Emit `did-insert-text` on `pasteText()`
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user