diff --git a/apm/package.json b/apm/package.json index d8f4f906e..90093b3d4 100644 --- a/apm/package.json +++ b/apm/package.json @@ -6,6 +6,6 @@ "url": "https://github.com/atom/atom.git" }, "dependencies": { - "atom-package-manager": "1.18.12" + "atom-package-manager": "1.19.0" } } diff --git a/package.json b/package.json index 799fa0a1d..a1e893184 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "service-hub": "^0.7.4", "sinon": "1.17.4", "temp": "^0.8.3", - "text-buffer": "13.9.2", + "text-buffer": "13.10.0", "tree-sitter": "^0.8.4", "typescript-simple": "1.0.0", "underscore-plus": "^1.6.6", @@ -95,7 +95,7 @@ "autocomplete-atom-api": "0.10.6", "autocomplete-css": "0.17.5", "autocomplete-html": "0.8.4", - "autocomplete-plus": "2.39.1", + "autocomplete-plus": "2.40.0", "autocomplete-snippets": "1.11.2", "autoflow": "0.29.3", "autosave": "0.24.6", diff --git a/spec/text-editor-spec.js b/spec/text-editor-spec.js index ab84d88c8..ef2ced5e6 100644 --- a/spec/text-editor-spec.js +++ b/spec/text-editor-spec.js @@ -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) {') }) }) }) diff --git a/src/text-editor.js b/src/text-editor.js index dcf8e201e..47fb9f485 100644 --- a/src/text-editor.js +++ b/src/text-editor.js @@ -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.