Solutions for Undo/Redo Buffer Loss on Format-on-Save #31307
joshuambg
started this conversation in
Feature Ideas / Enhancements
Replies: 1 comment
-
I've added a feature request for this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Reference Issue: #31021 - Redo buffer is cleared when saving a file
Problem Summary
Currently,
format_on_save
pushes a new undo state that clears the redo buffer, making it impossible to redo previously undone changes after saving. While @notpeter mentioned this would require "non-linear undo/redo history," I believe there are more targeted solutions that could preserve the current linear model while fixing this UX issue.Proposed Solutions
Solution 1: Transparent Formatting Operations
The core issue isn't the undo/redo system itself—it's that
format_on_save
is being treated as a user action when it should be transparent.Approach: Instead of pushing formatting changes as a new undo state, apply formatting while preserving the existing redo buffer by updating stored operations to account for formatting changes.
Implementation concept:
format_on_save
triggers, calculate the formatting diffThis is similar to operational transformation used in collaborative editors and is a well-solved problem for position-preserving changes like indentation and whitespace normalization.
Solution 2: Formatting Layers
Treat formatting as a separate layer that gets applied on save/display but isn't part of the core document state for undo/redo purposes.
Benefits:
Solution 3: Conditional Undo State Creation
Only push a new undo state for formatting if the formatting actually changed something substantial (beyond whitespace/indentation).
Implementation:
Expected User Experience
With any of these solutions:
The goal is maintaining the intuitive expectation that content changes remain redoable even after save operations, while keeping the elegance of the current linear undo/redo model.
Beta Was this translation helpful? Give feedback.
All reactions