feat: add undo and redo to rich text fields - #141
Merged
Conversation
Signed-off-by: Rizki Citra <rimzzlabs@proton.me>
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.
Part of #137.
The rich-text fields had no history at all.
buildRichTextExtensionsregistered Document, Paragraph, Text and the opt-in marks, and never a history plugin, so ProseMirror had nothing to undo against and Cmd+Z was a dead key in every description field. This registers TipTap'sUndoRedoextension and adds undo and redo buttons at the head of the field toolbar, disabled when there is nothing to undo or redo.UndoRedois a plugin over the transaction stream rather than a node or mark, so it adds nothing to the restricted schema and leaves export structure untouched. It ships in@tiptap/extensions, pinned to 3.27.1 to match the rest of the TipTap packages. History is per field and per mount: each editor instance keeps its own stack, and closing a section unmounts its editors and drops theirs.This does not give the document a global undo. Reordering sections, toggling visibility, and edits made in the plain inputs are outside a rich-text field's history, so #137 stays open.
Testing
Typed into a summary field and pressed Cmd+Z: the text returned to exactly its previous content, and Cmd+Shift+Z put it back. The toolbar buttons do the same thing, start out disabled on a freshly opened field, and the undo button enables as soon as there is an edit to take back. An undo also flows through to the live preview, so the reverted text disappears from the rendered page and from what would be exported.