mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Fix handling of {undo: 'skip'} in TextEditor.insertText
Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
committed by
Nathan Sobo
parent
75f43b0b0e
commit
733d6381cc
@@ -3507,13 +3507,16 @@ describe('TextEditor', () => {
|
||||
})
|
||||
|
||||
describe("when the undo option is set to 'skip'", () => {
|
||||
beforeEach(() => editor.setSelectedBufferRange([[1, 2], [1, 2]]))
|
||||
|
||||
it('does not undo the skipped operation', () => {
|
||||
let range = editor.insertText('x')
|
||||
range = editor.insertText('y', {undo: 'skip'})
|
||||
it('groups the change with the previous change for purposes of undo and redo', () => {
|
||||
editor.setSelectedBufferRanges([
|
||||
[[0, 0], [0, 0]],
|
||||
[[1, 0], [1, 0]]
|
||||
])
|
||||
editor.insertText('x')
|
||||
editor.insertText('y', {undo: 'skip'})
|
||||
editor.undo()
|
||||
expect(buffer.lineForRow(1)).toBe(' yvar sort = function(items) {')
|
||||
expect(buffer.lineForRow(0)).toBe('var quicksort = function () {')
|
||||
expect(buffer.lineForRow(1)).toBe(' var sort = function(items) {')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1330,15 +1330,24 @@ class TextEditor {
|
||||
insertText (text, options = {}) {
|
||||
if (!this.emitWillInsertTextEvent(text)) return false
|
||||
|
||||
let groupLastChanges = false
|
||||
if (options.undo === 'skip') {
|
||||
options = Object.assign({}, options)
|
||||
delete options.undo
|
||||
groupLastChanges = true
|
||||
}
|
||||
|
||||
const groupingInterval = options.groupUndo ? this.undoGroupingInterval : 0
|
||||
if (options.autoIndentNewline == null) options.autoIndentNewline = this.shouldAutoIndent()
|
||||
if (options.autoDecreaseIndent == null) options.autoDecreaseIndent = this.shouldAutoIndent()
|
||||
return this.mutateSelectedText(selection => {
|
||||
const result = this.mutateSelectedText(selection => {
|
||||
const range = selection.insertText(text, options)
|
||||
const didInsertEvent = {text, range}
|
||||
this.emitter.emit('did-insert-text', didInsertEvent)
|
||||
return range
|
||||
}, groupingInterval)
|
||||
if (groupLastChanges) this.buffer.groupLastChanges()
|
||||
return result
|
||||
}
|
||||
|
||||
// Essential: For each selection, replace the selected text with a newline.
|
||||
|
||||
Reference in New Issue
Block a user