mirror of
https://github.com/atom/atom.git
synced 2026-02-11 07:05:11 -05:00
When snippet expansion is undone, the snippet is destroyed
This is still in progress. You can't *redo* snippet expansion and restore tab stops. Also, this commit performs all changes associated with snippet expansion in a transaction.
This commit is contained in:
@@ -142,9 +142,9 @@ class Buffer
|
||||
@lines[startRow..endRow] = newLines
|
||||
@modified = true
|
||||
|
||||
pushOperation: (operation) ->
|
||||
pushOperation: (operation, editSession) ->
|
||||
if @undoManager
|
||||
@undoManager.pushOperation(operation)
|
||||
@undoManager.pushOperation(operation, editSession)
|
||||
else
|
||||
operation.do()
|
||||
|
||||
|
||||
@@ -238,16 +238,19 @@ class EditSession
|
||||
transact: (fn) ->
|
||||
@buffer.transact =>
|
||||
oldSelectedRanges = @getSelectedBufferRanges()
|
||||
@buffer.pushOperation
|
||||
@pushOperation
|
||||
undo: (editSession) ->
|
||||
editSession?.setSelectedBufferRanges(oldSelectedRanges)
|
||||
|
||||
fn()
|
||||
newSelectedRanges = @getSelectedBufferRanges()
|
||||
@buffer.pushOperation
|
||||
@pushOperation
|
||||
redo: (editSession) ->
|
||||
editSession?.setSelectedBufferRanges(newSelectedRanges)
|
||||
|
||||
pushOperation: (operation) ->
|
||||
@buffer.pushOperation(operation, this)
|
||||
|
||||
getAnchors: ->
|
||||
new Array(@anchors...)
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ class UndoManager
|
||||
@undoHistory = []
|
||||
@redoHistory = []
|
||||
|
||||
pushOperation: (operation) ->
|
||||
pushOperation: (operation, editSession) ->
|
||||
if @currentTransaction
|
||||
@currentTransaction.push(operation)
|
||||
else
|
||||
@undoHistory.push([operation])
|
||||
@redoHistory = []
|
||||
operation.do?()
|
||||
operation.do?(editSession)
|
||||
|
||||
transact: (fn) ->
|
||||
if @currentTransaction
|
||||
|
||||
@@ -5,11 +5,12 @@ class SnippetExpansion
|
||||
constructor: (snippet, @editSession) ->
|
||||
@editSession.selectToBeginningOfWord()
|
||||
startPosition = @editSession.getCursorBufferPosition()
|
||||
@editSession.insertText(snippet.body)
|
||||
if snippet.tabStops.length
|
||||
@placeTabStopAnchorRanges(startPosition, snippet.tabStops)
|
||||
if snippet.lineCount > 1
|
||||
@indentSubsequentLines(startPosition.row, snippet)
|
||||
@editSession.transact =>
|
||||
@editSession.insertText(snippet.body)
|
||||
if snippet.tabStops.length
|
||||
@placeTabStopAnchorRanges(startPosition, snippet.tabStops)
|
||||
if snippet.lineCount > 1
|
||||
@indentSubsequentLines(startPosition.row, snippet)
|
||||
|
||||
placeTabStopAnchorRanges: (startPosition, tabStopRanges) ->
|
||||
@tabStopAnchorRanges = tabStopRanges.map ({start, end}) =>
|
||||
|
||||
@@ -28,7 +28,10 @@ module.exports =
|
||||
editSession = editor.activeEditSession
|
||||
prefix = editSession.getLastCursor().getCurrentWordPrefix()
|
||||
if snippet = @snippetsByExtension[editSession.getFileExtension()][prefix]
|
||||
editSession.snippetExpansion = new SnippetExpansion(snippet, editSession)
|
||||
editSession.transact ->
|
||||
editSession.snippetExpansion = new SnippetExpansion(snippet, editSession)
|
||||
editSession.pushOperation
|
||||
undo: -> editSession.snippetExpansion.destroy()
|
||||
else
|
||||
e.abortKeyBinding()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user