Skip to content

[diffs/edit] Fix edit stack coalescing#1000

Merged
ije merged 2 commits into
beta-1.3from
ije/fix-editStack-coalescing
Jul 16, 2026
Merged

[diffs/edit] Fix edit stack coalescing#1000
ije merged 2 commits into
beta-1.3from
ije/fix-editStack-coalescing

Conversation

@ije

@ije ije commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

EditStack coalescing (3) — coalescing decisions compare a new edit against
whatever sits on top of the undo stack purely by geometry, with no state reset
after undo/redo: an undo can expose a stale top entry that new typing then
fuses into; an undo-boundary marker stops blocking merges once it is undone;
and backspace followed by forward-delete at the same pivot coalesces into a
single undo step instead of getting an undo stop when the delete direction
flips.

  • Undo/redo now closes the active coalescing group, preventing stale or boundary-hidden entries from merging.
  • Delete entries retain backspace/forward-delete direction, so direction flips create undo stops.

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jul 16, 2026 5:55pm
pierre-docs-diffshub Ready Ready Preview Jul 16, 2026 5:55pm
pierre-docs-trees Ready Ready Preview Jul 16, 2026 5:55pm
pierrejs-diff-demo Ready Ready Preview Jul 16, 2026 5:55pm

Request Review

@ije

ije commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 0185a5ed3a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes EditStack undo/redo coalescing behavior in packages/diffs so new edits don’t incorrectly merge into stale history after undo/redo, and so backspace vs forward-delete direction changes introduce an undo stop (instead of being merged into one step).

Changes:

  • Close the active coalescing group on undo/redo via EditStack.peekUndoForCoalescing() + internal state, preventing merges into newly exposed (stale/boundary-hidden) undo entries.
  • Track and persist delete direction using coalescingMode so backspace/delete flips don’t coalesce when geometry is ambiguous.
  • Promote previously test.failing coalescing scenarios to passing tests; remove the corresponding “known bugs” note; fix the findNextMatch naming typo across code/tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/diffs/test/README.md Removes the “known bugs” entry now covered/fixed by the updated coalescing behavior.
packages/diffs/test/editorSelection.test.ts Renames test usage from findNexMatch to findNextMatch.
packages/diffs/test/editorEditStack.test.ts Converts previously failing undo/redo + delete-direction coalescing scenarios into normal passing tests; adds coverage for direction flips.
packages/diffs/src/editor/textDocument.ts Switches coalescing comparison to peekUndoForCoalescing() so undo/redo closes coalescing groups.
packages/diffs/src/editor/selection.ts Renames exported helper to findNextMatch.
packages/diffs/src/editor/editStack.ts Implements coalescing-group gating (#canCoalesce) and adds coalescingMode to preserve delete direction across coalesced runs.
packages/diffs/src/editor/editor.ts Updates import/call site to use findNextMatch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ije
ije marked this pull request as ready for review July 16, 2026 18:11
@ije
ije merged commit 53351da into beta-1.3 Jul 16, 2026
9 checks passed
@ije
ije deleted the ije/fix-editStack-coalescing branch July 16, 2026 18:11

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0185a5ed3a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +170 to +174
if (
selection.start.line !== selection.end.line ||
selection.start.character !== selection.end.character
) {
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve delete direction for editor delete commands

When Backspace/Delete is invoked through the editor path, applyDeleteCharacterToSelections passes the expanded delete ranges as selectionsBefore, not the original collapsed carets. This branch therefore breaks on the non-collapsed selection and leaves coalescingMode unset, so a Backspace followed by forward Delete at the same pivot still coalesces in production UI; on abc, Backspace after b then Delete causes one undo to restore both b and c instead of just c.

Useful? React with 👍 / 👎.

amadeus pushed a commit that referenced this pull request Jul 21, 2026
* fix typo

* fix editStack coalescing bugs.
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.

2 participants