Repository navigation
Keep the undo state in step with a run of typing - #7
Merged
Merged
Conversation
store_action_state stores a new state when the action changes, and is meant to fold continued editing of the same action into the state that run already created. The guard on that second branch tested current_state < len(history)-1, which is never true while editing forwards: store_state leaves current_state at the end of the history. So only the first keystroke of a run was ever recorded. Typing KEEP, pressing enter and undoing once gave back K rather than KEEP, and the same held for every action that followed a typing run. Fold into the current state whenever the action is unchanged, guarding only against writing over the initial state at index 0.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Undo stepped back further than the last edit. Typing
KEEP, pressing enter, then undoing once gave backK.Cause
store_action_statestores a new state when the action changes, and otherwise folds continued editing into the state that run already created. The second branch was guarded by:That is never true while editing forwards —
store_statesetscurrent_state = len(self.history)-1every time it appends. So a typing run was recorded as its first keystroke only, and the undo point left behind held one character of what the user had actually typed.The original carried two
FIXMEcomments on that branch ("this if is here just for safety", "current_state might be wrong"), so it was known to be doubtful.Fix
Fold into the current state whenever the action is unchanged, guarding only against overwriting the initial state at index 0.
Verification
KEEP, enter, undoKKEEPKEEP, duplicate line, undoKKEEPHELLO, tab, undoHHELLOWORD, backspace, undoWWORDKEEP, paste, undoKKEEPUnchanged where it was already right, which is the risk in touching history:
KEEP, undoKEEPmax_historytrimming is untouched,test.shpasses, flake8 clean.Found while fixing #6: the paste there inherited this, which is why its undo looked wrong.