feat: made undo work when importing pattern. #2160
Open
+13
−10
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.
A user complained that they imported a file by accident when they meant to export it and as a result had trouble recovering the changes they were trying to save. Auto-save saved the day but there is no reason for not being able to undo changes after importing a pattern.
In fact, the previous implementation treated importing a pattern as a reset on the editor instance which actually erased all previous undo entries. Importing now is treated as a normal editing operation where the entire file is replaced with the imported pattern.
Since all imports use AddText it was easy to add an undo entry to that function while removing the part where the previous undo records were being deleted.
Care is taken to add the preprocessed version of the imported file to the undo buffer so that unwanted chars don't sneak in. A bug was found in the handling of a tab char as well but hopefully it wont need to be used anymore.