project_panel: Initial redo support#51970
Conversation
* Introduce `project_panel::Redo` action
* Add the necessary handler for the `project_panel::Redo` action
* For the time being, the redo implementation doesn't actually redo
anything at all as that will be added in a future commit, this one
was more focused on actually shipping the cursor-based tracking of
undo history in order to support redoing operations
* Introduce `UndoManager::cursor` in order to allow tracking where the
current position is in the undo history, which also makes it easier to
re-use the undo history for redoing operations, without the need to
introduce another data structure to hold the redo history
* Update default platform keymaps to include a binding for
`project_panel::Redo`
* Update `project_panel::undo::UndoManager::redo` to support redoing rename operations. Support for other opeations will come in future commits * Extract rename logic into `project_panel::undo::UndoManager::rename` as it can be used both when undoing and redoing rename operations * Refactor `project_panel::undo::UndoManager::show_errors` to expect the title as an argument, so that it can be used for both undo and redo errors * Update `project_panel::project_panel_tests::test_undo_rename` to `project_panel::project_panel_tests::test_undo_redo_rename` as it now also tests redoing rename operations
📏 PR Size: 1768 lines changed (size/XL)Please note: this PR exceeds the 400 LOC soft limit.
✅ "How to Review" section appears to include guidance — thank you! |
* Update `project_panel::undo::UndoManager::redo_operation` in order to suport redoing `ProjectPanelOperation::Batch` operations. * Introduce `project_panel::undo::test::build_rename_operation` helper function * Add tests for ensuring that redoing a batch of operations works as expected
c022997 to
e97db03
Compare
|
Moving this back to Draft as I've noticed, while working on adding redo support to file creation operations, that it makes more sense to have separate stacks for the undo and redo operations. For example, when a new file is created through the Project Panel, we record that as a If we were to keep all of this tracking logic in a single As such, I'm now working on updating this approach such that, undoing a |
Update fields for both `project_panel::undo::Rename` and `project_panel::PasteTask` from `old_path` and `new_path` to `from` and `to` to make it a little bit easier to reason about when undoing and redoing.
Refactor how `project_panel::undo::UndoManager` supports redo operations. The initial plan before this commit was to have a single `VecDeque` complemented by a cursor, where undoing an operation meant decreasing the cursor, and redoing meant increasing the cursor. That works fine for almost all cases but, in the particular case of a `Create` or `Trash` operation, we'll eventually need to keep track of the trashed entry when we wish to redo a `Create` operation, or undo a `Trash` operation. As such, this commit re-introduces the idea of using two different stacks, one for the list of operations to undo and one for the list of operations to redo, namely `project_panel::undo::UndoManager::undo_stack` and `project_panel::undo::UndoManager::redo_stack`. It also updates the overall approach such that: 1. When recording an operation, we invert it and push that to the undo stack 2. When undoing, we execute the most recent operation in the undo stack and push its inverse to the redo stack 3. When redoing, we execute the most recent operation in the redo stack and push its inverse to the undo stack This makes it so that `UndoManager` more or less only needs to know which operation to execute and where to push the resulting operation, allowing us to get rid of `UndoManager::undo_operation` and `UndoManager::redo_operation` specific methods. Unfortunately, one thing that was lost in this refactor is that, right now, we early-return in the `Batch` operation, as soon as a single operation fails, so we'll always only show one message, we might want to revisit this later.
|
I’m going to close this in favor of #53311 for a couple of reasons:
So even though that pull request is larger and takes a different approach, it’s in a much better place, especially since it was shaped through pairing 🙂 |
Context
These changes continue the work started on #47091 by introducing support for redoing actions in the Project Panel, namely through the
Redoaction.How to Review
Although the order of the commits should help in reviewing these changes, here's a quick breakdown with the order I recommend reviewing these changes:
project_panel::undo::UndoManager::cursorwhich allows tracking the position in thehistoryof operations where the user currently iscursorwe can now move the cursor either backwards on undo, or forwards onredoproject_panel::Redoaction, as well as a listener for this actionproject_panel::RedoProjectPanelOperation::RenameandProjectPanelOperation::Batch. Support for redoingProjectPanelOperation::Createwill come in a future Pull Request, once we add the ability to track the trashed file's locationSelf-Review Checklist
Release Notes: