mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Shift-meta-z to redo.
This commit is contained in:
@@ -51,6 +51,7 @@ class Editor extends View
|
||||
'meta-c': 'copy'
|
||||
'meta-v': 'paste'
|
||||
'meta-z': 'undo'
|
||||
'meta-Z': 'redo'
|
||||
|
||||
@on 'move-right', => @moveCursorRight()
|
||||
@on 'move-left', => @moveCursorLeft()
|
||||
@@ -67,6 +68,7 @@ class Editor extends View
|
||||
@on 'copy', => @copySelection()
|
||||
@on 'paste', => @paste()
|
||||
@on 'undo', => @undo()
|
||||
@on 'redo', => @redo()
|
||||
|
||||
buildCursorAndSelection: ->
|
||||
@cursor = new Cursor(this)
|
||||
@@ -244,3 +246,6 @@ class Editor extends View
|
||||
|
||||
undo: ->
|
||||
@undoManager.undo()
|
||||
|
||||
redo: ->
|
||||
@undoManager.redo()
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
module.exports =
|
||||
class UndoManager
|
||||
undoHistory: null
|
||||
undoInProgress: null
|
||||
redoHistory: null
|
||||
preserveHistory: false
|
||||
|
||||
constructor: (@buffer) ->
|
||||
@undoHistory = []
|
||||
@redoHistory = []
|
||||
@buffer.on 'change', (op) =>
|
||||
@undoHistory.push(op) unless @undoInProgress
|
||||
unless @preserveHistory
|
||||
@undoHistory.push(op)
|
||||
@redoHistory = []
|
||||
|
||||
undo: ->
|
||||
return unless @undoHistory.length
|
||||
op = @undoHistory.pop()
|
||||
@undoInProgress = true
|
||||
@buffer.change op.newRange, op.oldText
|
||||
@undoInProgress = false
|
||||
if op = @undoHistory.pop()
|
||||
@preservingHistory =>
|
||||
@buffer.change op.newRange, op.oldText
|
||||
@redoHistory.push op
|
||||
|
||||
redo: ->
|
||||
if op = @redoHistory.pop()
|
||||
@preservingHistory =>
|
||||
@buffer.change op.oldRange, op.newText
|
||||
@undoHistory.push op
|
||||
|
||||
preservingHistory: (fn) ->
|
||||
@preserveHistory = true
|
||||
fn()
|
||||
@preserveHistory = false
|
||||
|
||||
Reference in New Issue
Block a user