Skip to content

fix: group contiguous note edits into a single undo step#4524

Open
patbyte wants to merge 1 commit into
cybersemics:mainfrom
patbyte:fix/note-undo-grouping
Open

fix: group contiguous note edits into a single undo step#4524
patbyte wants to merge 1 commit into
cybersemics:mainfrom
patbyte:fix/note-undo-grouping

Conversation

@patbyte

@patbyte patbyte commented Jul 6, 2026

Copy link
Copy Markdown

Route note edits through editThought instead of setDescendant so consecutive note changes merge in the undo stack, and mark toggleNote as non-undoable.

This PR fixes #4479.

Changes:

  • Note edits now dispatch editThought when the note value thought already exists, so they use the existing directional undo chunking logic
  • Empty note creation is no longer undoable
  • Added undo/redo coverage for note additions, deletes, replacements, and empty-note creation

Route note edits through editThought instead of setDescendant so
consecutive note changes merge in the undo stack, and mark toggleNote
as non-undoable.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Vercel preview: https://em-2gkypmahz-cybersemics.vercel.app

@raineorshine raineorshine requested a review from BayuAri July 6, 2026 15:24
@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue A: Undo is splitted into 2 stacks for replacing a word on Notes

- One
- Two

Step to Reproduce

  1. Create a new Note under One
  2. Type The world of beautiful birds
  3. Change the birds word into people
  4. Click Undo

Current behavior

The first Undo the replaced word becomes p
The second Undo the word is reverted to birds

Fast.type.mov
Slow.Type.mov

Expected behavior

The first Undo should revert to the original birds

@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue B: Backspace / Delete is not working and caret is moved to the end of the thought text after Undo on the first thought

Step to Reproduce

  1. Create a new Note under One
  2. Type The world of birds
  3. Select the word world
  4. Change the word into cage
  5. Click Undo to revert back to world
  6. Hit Delete button on the keyboard several time

Current behavior

Nothing happens.
The caret is moved to the end of the thought text.
Workaround: move the caret next to the desired word to make it works again to delete/backspace.

Issue.B.Backspace.Delete.is.not.working.after.Undo.MP4

Expected behavior

Backspace/delete should work after Undo action.
The caret should be placed where it left off

@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue C: Undo a new Notes creation is Undoing the last action prior the creating the new Notes but leaving the empty Notes

Step to Reproduce

  1. Create a new thought
  2. Add a text One
  3. Click Add Notes button
  4. Click Undo

Current behavior

One text is undone.
Newly created empty Note remains.
Undo again deletes the thought.

Issue.C.Undo.a.new.Notes.creation.is.Undoing.the.last.action.prior.the.creating.the.new.Notes.but.leaving.the.empty.Notes.MP4

Expected behavior

Newly created empty note should be deleted

@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue D: Backspace/Delete button on the keyboard deletes the thought space.

- One
- Two

Step to Reproduce

  1. Create a new Notes on Thought Two
  2. Type Hello World
  3. Change Hello to Great
  4. Tap Undo
  5. Tap Backspace/Delete button on the keyboard

Current behavior

Thought space is deleted.
Two text is merged onto the above One along with the Notes
This is related to Issue B

Issue.D.Backspace.Delete.button.on.the.keyboard.deletes.the.thought.space.MP4

Expected behavior

Backspace/Delete button on the keyboard should serve to delete the character before the caret.

@BayuAri BayuAri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raineorshine

Copy link
Copy Markdown
Contributor

@raineorshine
Question about Issue A, is this intended as the implementation of Replacements → separate undo steps

This raises a good question, though for the purpose of this issue we are just aiming to reproduce the undo/redo behavior that currently exists for normal thoughts. So for any edit to a note, check how many undo/redo steps are created if the same edit is applied to a normal thought.

That should be enough to figure out the intended functionality, but to answer your specific question about Issue A, you have come up with a case that I don't think I had considered yet, and I'm not sure how this is handled in the code currently. I think the code currently categorizes edits based on the string length delta:

ADD: a (1) → ab (2)
DELETE: ab (2) → a (1)
REPLACE: a (1) → b (1)

Issue A is unique in that it is a replacement, but the number of characters are not the same. I think birds (5) → people (6) would currently be categorized by an addition, which is probably wrong (i.e. a bug in normal thought undo/redo). Categorizing it as a replacement so that it gets its own undo step and is not merged with other contiguous additions makes more sense.

However, that's all out of scope for this issue, whose main purpose is to implement baseline undo/redo chunking to notes. This was understandably not so clear from my hasty bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undo/redo directional chunking for notes

3 participants