diff --git a/spec/extensions/snippets-spec.coffee b/spec/extensions/snippets-spec.coffee index 7b8c3bfcc..f56cf7a2e 100644 --- a/spec/extensions/snippets-spec.coffee +++ b/spec/extensions/snippets-spec.coffee @@ -173,6 +173,20 @@ describe "Snippets extension", -> editor.trigger keydownEvent('tab', target: editor[0]) expect(editor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]] + it "restores tabs stops in active edit session even when the initial expansion was in a different edit session", -> + anotherEditor = editor.splitRight() + + editor.insertText ' t5\n' + editor.setCursorBufferPosition [0, 6] + editor.trigger keydownEvent('tab', target: editor[0]) + expect(buffer.lineForRow(0)).toBe " first line" + editor.undo() + + anotherEditor.redo() + expect(anotherEditor.getCursorBufferPosition()).toEqual [0, 14] + anotherEditor.trigger keydownEvent('tab', target: anotherEditor[0]) + expect(anotherEditor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]] + describe ".loadSnippetsFile(path)", -> it "loads the snippets in the given file", -> spyOn(fs, 'read').andReturn """ diff --git a/src/extensions/snippets/snippet-expansion.coffee b/src/extensions/snippets/snippet-expansion.coffee index 66800e1da..332e8e695 100644 --- a/src/extensions/snippets/snippet-expansion.coffee +++ b/src/extensions/snippets/snippet-expansion.coffee @@ -55,6 +55,7 @@ class SnippetExpansion anchorRange.destroy() for anchorRange in @tabStopAnchorRanges @editSession.snippetExpansion = null - restoreTabStops: -> + restore: (@editSession) -> + @editSession.snippetExpansion = this @tabStopAnchorRanges = @tabStopAnchorRanges.map (anchorRange) => @editSession.addAnchorRange(anchorRange.getBufferRange()) diff --git a/src/extensions/snippets/snippets.coffee b/src/extensions/snippets/snippets.coffee index d283157da..d1c51de9d 100644 --- a/src/extensions/snippets/snippets.coffee +++ b/src/extensions/snippets/snippets.coffee @@ -32,10 +32,8 @@ module.exports = snippetExpansion = new SnippetExpansion(snippet, editSession) editSession.snippetExpansion = snippetExpansion editSession.pushOperation - undo: -> editSession.snippetExpansion.destroy() - redo: -> - editSession.snippetExpansion = snippetExpansion - snippetExpansion.restoreTabStops() + undo: -> snippetExpansion.destroy() + redo: (editSession) -> snippetExpansion.restore(editSession) else e.abortKeyBinding()