Skip to content

Commit

Permalink
Add shift-z for redo, and make sure cursor is always correct
Browse files Browse the repository at this point in the history
  • Loading branch information
dabbler0 committed Jun 30, 2015
1 parent 343cfaf commit b7f0267
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ hook 'populate', 0, ->

# Now we hook to ctrl-z to undo.
hook 'keydown', 0, (event, state) ->
if event.which is Z_KEY and command_pressed(event)
if event.which is Z_KEY and event.shiftKey and command_pressed(event)
@redo()
else if event.which is Z_KEY and command_pressed(event)
@undo()
else if event.which is Y_KEY and command_pressed(event)
@redo()
Expand Down Expand Up @@ -698,6 +700,7 @@ Editor::undo = ->
@tree.perform(operation, 'backward', [@cursor]) unless operation is 'CAPTURE'

@popUndo()
@correctCursor()
@redrawMain()
return

Expand Down Expand Up @@ -750,6 +753,7 @@ Editor::spliceOut = (node) ->
@pushUndo operation

@prepareNode node, null
@correctCursor()
return operation

Editor::spliceIn = (node, location) ->
Expand All @@ -766,13 +770,20 @@ Editor::spliceIn = (node, location) ->
operation = null
operation = @tree.insert location, node, [@cursor]
@pushUndo operation
@correctCursor()
return operation

Editor::replace = (before, after, updates) ->
operation = @tree.replace before, after, updates
@pushUndo operation
@correctCursor()
return operation

Editor::correctCursor = ->
cursor = @tree.getFromLocation(@cursor)
unless @validCursorPosition cursor
@setCursor cursor

Editor::prepareNode = (node, context) ->
if node instanceof model.Container
leading = node.getLeadingText()
Expand Down Expand Up @@ -2429,6 +2440,7 @@ Editor::deleteAtCursor = ->
return

@setCursor block.start, null, 'before'
@undoCapture()
@spliceOut block
@redrawMain()

Expand Down

0 comments on commit b7f0267

Please sign in to comment.