Skip to content

fix: Refactor undo/redo functionality and clean up related code#77

Merged
Koyandechirag merged 2 commits into
FOSSEE:masterfrom
KrishGaur1354:fix/undoredo
Jun 3, 2026
Merged

fix: Refactor undo/redo functionality and clean up related code#77
Koyandechirag merged 2 commits into
FOSSEE:masterfrom
KrishGaur1354:fix/undoredo

Conversation

@KrishGaur1354
Copy link
Copy Markdown
Contributor

This pull request significantly refactors and improves the undo/redo system in the application, making snapshot management more robust, modular, and consistent. The changes centralize snapshot logic, ensure undo/redo stacks are updated at the correct moments, and enhance the reliability of restoring and saving the application's state, including connections and compound selections.

Undo/Redo System Refactoring and Improvements:

  • Introduced a new push_snapshot method in Graphics.py that encapsulates the logic for saving the current scene state, clearing the redo stack, and updating the undo/redo action states, replacing scattered snapshot code throughout the application.
  • Updated the undo and redo methods in mainApp.py to use a more robust stack-based approach: undo now restores the previous snapshot and only pushes to redo if not at the initial state, while redo pushes the redone snapshot back to undo. Also, a new _update_undo_redo_actions method ensures UI buttons are enabled/disabled correctly.
  • All actions that modify the scene (adding, deleting, or connecting items) now call push_snapshot at the appropriate time, ensuring that undo/redo stacks are always in sync with user actions. [1] [2] [3] [4] [5]

Snapshot Data Structure and Restore Enhancements:

  • The snapshot structure in save_canvas now includes items, connections, and compound selections, and uses deep copies of objects to ensure accurate restoration. The load_canvas_from_snapshot method has been rewritten to fully rebuild the scene, connections, and restore class counters for unique naming.

Code Cleanup and Responsibility Clarification:

  • The responsibility for pushing undo snapshots after scene modifications (such as adding or deleting unit operations) has been moved out of Container.py and into the main application logic, clarifying the separation of concerns and reducing redundancy. [1] [2]

Other Notable Adjustments:

  • Removed redundant or now-unnecessary code for shortcut setup and initial undo/redo stack cleaning, as this is now handled by the new snapshot logic. [1] [2] [3]

These changes collectively make the undo/redo functionality more predictable, reliable, and easier to maintain.

Resolve the modify/delete conflict on undo_redo/Undo.pkl by removing the
tracked pickle. Undo.pkl is a generated runtime artifact, now excluded via
.gitignore (undo_redo/ and src/main/Simulator/undo_redo/). Brings the PR up
to date with upstream; undo/redo verified working after the merge.
@KrishGaur1354 KrishGaur1354 marked this pull request as ready for review June 3, 2026 05:57
@KrishGaur1354 KrishGaur1354 changed the title WIP: Refactor undo/redo functionality and clean up related code fix: Refactor undo/redo functionality and clean up related code Jun 3, 2026
@Koyandechirag Koyandechirag merged commit bcede97 into FOSSEE:master Jun 3, 2026
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