Add multi-level undo and redo - #8
Open
sigmanor wants to merge 3 commits into
Open
Conversation
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.
There is no undo in the editor. Ctrl+Z only reverted the last paste, so typing and deletions could not be taken back at all, and GTK 3 gives GtkTextBuffer nothing to fall back on.
An undo step keeps a snapshot of the note rather than a list of offsets, and restoring one replaces only the part that actually differs. Rewriting the whole buffer would reset the scroll position and strip every tag until the next idle render, so a long note would jump to the top and the raw markdown would flash for a moment. The re-render also runs in the same main loop iteration as the edit, so no frame is ever drawn with the syntax showing.
Edits are grouped into word-sized steps: a new one starts on a space, after a pause, when the edit kind changes, or when it lands somewhere else. Typing or pasting over a selection reaches the buffer as a delete plus an insert, and those are kept together so one Ctrl+Z brings the original text back.
Changes:
src/undo.c/src/undo.hholding the history, capped at 100 stepsinsert-text/delete-range; the markdown renderer and note loading are excluded, since they rewrite the buffer themselvesCyrillic_yamarkyd_editor_get_contentnow copies the runs between anchors instead of one character at a time, since the history reads it far more often than autosave did