mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
When a snippet expansion is redone, tab stops are restored
This commit is contained in:
@@ -160,6 +160,19 @@ describe "Snippets extension", ->
|
||||
editor.trigger keydownEvent('tab', target: editor[0])
|
||||
expect(buffer.lineForRow(0)).toBe "first line"
|
||||
|
||||
describe "when a snippet expansion is undone and redone", ->
|
||||
it "recreates the snippet's tab stops", ->
|
||||
editor.insertText ' t5\n'
|
||||
editor.setCursorBufferPosition [0, 6]
|
||||
editor.trigger keydownEvent('tab', target: editor[0])
|
||||
expect(buffer.lineForRow(0)).toBe " first line"
|
||||
editor.undo()
|
||||
editor.redo()
|
||||
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0, 14]
|
||||
editor.trigger keydownEvent('tab', target: editor[0])
|
||||
expect(editor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]]
|
||||
|
||||
describe ".loadSnippetsFile(path)", ->
|
||||
it "loads the snippets in the given file", ->
|
||||
spyOn(fs, 'read').andReturn """
|
||||
|
||||
@@ -54,3 +54,7 @@ class SnippetExpansion
|
||||
destroy: ->
|
||||
anchorRange.destroy() for anchorRange in @tabStopAnchorRanges
|
||||
@editSession.snippetExpansion = null
|
||||
|
||||
restoreTabStops: ->
|
||||
@tabStopAnchorRanges = @tabStopAnchorRanges.map (anchorRange) =>
|
||||
@editSession.addAnchorRange(anchorRange.getBufferRange())
|
||||
|
||||
@@ -29,9 +29,13 @@ module.exports =
|
||||
prefix = editSession.getLastCursor().getCurrentWordPrefix()
|
||||
if snippet = @snippetsByExtension[editSession.getFileExtension()][prefix]
|
||||
editSession.transact ->
|
||||
editSession.snippetExpansion = new SnippetExpansion(snippet, editSession)
|
||||
snippetExpansion = new SnippetExpansion(snippet, editSession)
|
||||
editSession.snippetExpansion = snippetExpansion
|
||||
editSession.pushOperation
|
||||
undo: -> editSession.snippetExpansion.destroy()
|
||||
redo: ->
|
||||
editSession.snippetExpansion = snippetExpansion
|
||||
snippetExpansion.restoreTabStops()
|
||||
else
|
||||
e.abortKeyBinding()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user