Skip to content

Conversation

@eloisebrosseau
Copy link
Contributor

SG-41210: Add a per user undo-redo stack to Annotate Mode

Summarize your change.

The undo, redo and clear actions in the Annotate Mode were refactored. A new undo property was added so that bringing back cleared annotations would be done through an undo action instead of redo. Both the undo and redo properties were made per user via the username and process id values. An undoClearAllFrames and a redoClearAllFrames properties were also created to managed clearing annotations on the timeline. This action is special because in a context of multiple annotators, clearing can be done by anyone on any frames and specifically undone by the user who made the action. Basic undo and redo actions are per frame. However, undoing and redoing a clear of all the annotations on the timeline can be done on any frame.

The undo, redo and clear button states were also updated to match this new implementation of the Annotate Mode. If the draw mode is _Select (i.e. the cursor), all three buttons are disabled since the Annotate mode is not actually active anymore and the states were not updated in that case. Undoing, redoing and clearing annotations can only be done if a real drawing mode (e.g. pen or text) is selected to avoid issues with the buttons not being updated.

This implementation is following this design:

Draw a paint stroke

  • Add a "create" action for the stroke onto that user's undo stack for that frame
  • Empty the redo stack for that frame

Clear all on a frame

  • Empty the undo and redo stacks for that frame
  • Add a "ClearAll" action for all the strokes for that frame

- Clear all frames on the timeline

  • Empty the undo and redo stacks for all frames
  • Add a "ClearAllFrames" action for the strokes for all frames

Undo

  • If the undoClearAllFrames property has an action
    • Restore the strokes stored in the action
    • Assign the action to the redoClearAllFrames property
    • Reset the undoClearAllFrames property
  • Else if the undo stack for that frame is not empty
    • Pop the action object
    • If the action was "create"
      • Remove the annotation from the order property
    • Else if the action was "clearAll"
      • Restore all the annotations for that action
    • Push the action onto the redo stack

Redo

  • If the redoClearAllFrames property has an action
    • Remove the strokes stored in the action
    • Assign the action to the undoClearAllFrames property
    • Reset the redoClearAllFrames property
  • Else if the redo stack for that frame is not empty
    • Pop the action object
    • If the action was "create"
      • Restore the annotation from the order property
    • Else if the action was "clearAll"
      • Remove all the annotations for that action
    • Push the action onto the undo stack

Describe the reason for the change.

Some changes were needed to match the new product requirements around undo, redo and clear actions. This changes were mainly needed to handle multiple annotators simultaneously in a Live Review session.

Describe what you have tested and on which operating system.

Basic operations of drawing, undoing, redoing, clearing a frame, and clearing the timeline were tested on macOS 15.6.1

Copy link
Contributor

@bernie-laberge bernie-laberge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful !
Well done @eloisebrosseau !
Not essential but perhaps we should bump the version of the Annotate package to 1.21 ?

Signed-off-by: Éloïse Brosseau <[email protected]>
Signed-off-by: Éloïse Brosseau <[email protected]>
Signed-off-by: Éloïse Brosseau <[email protected]>
Signed-off-by: Éloïse Brosseau <[email protected]>
Signed-off-by: Éloïse Brosseau <[email protected]>
Signed-off-by: Éloïse Brosseau <[email protected]>
Signed-off-by: Éloïse Brosseau <[email protected]>
@eloisebrosseau eloisebrosseau force-pushed the refactor-annotate-stack branch from 4c889ae to d684062 Compare December 4, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants