-
Notifications
You must be signed in to change notification settings - Fork 152
SD-3358 - tracked deletion is captured char by char in suggesting mode #3610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harbournick
merged 9 commits into
main
from
gabriel/sd-3358-tracked-deletion-is-captured-char-by-char-in-suggesting-mode
Jun 3, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
22b8a2d
fix: implement deletion coalescing for adjacent tracked deletions
chittolina 7467ac5
test: add spec for contiguous Backspace deletion in suggesting mode
chittolina aaeb6df
fix: refine deletion coalescing logic to exclude structured changes
chittolina 2387eb3
fix: comments
chittolina 414fe53
fix: update ZERO_WIDTH_ANCHOR_NODE_NAMES to include permission marker…
chittolina 497aed3
fix: added comment to clarify edge case
chittolina 8336b39
fix: added clarifying comment
chittolina e8f84fb
Merge branch 'main' into gabriel/sd-3358-tracked-deletion-is-captured…
chittolinag d9a342e
Merge branch 'main' into gabriel/sd-3358-tracked-deletion-is-captured…
harbournick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
97 changes: 97 additions & 0 deletions
97
tests/behavior/tests/comments/sd-3358-keystroke-delete-coalesce.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { test, expect, type SuperDocFixture } from '../../fixtures/superdoc.js'; | ||
|
|
||
| // SD-3358 / TC-EDIT-018: a contiguous same-author deletion authored | ||
| // keystroke-by-keystroke in suggesting mode must surface as ONE logical tracked | ||
| // deletion, not one per character — and that must hold across run seams, | ||
| // including Google-Docs comment-anchor markers that sit between runs. | ||
|
|
||
| test.use({ config: { toolbar: 'full', comments: 'off', trackChanges: true } }); | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const GD_DOC_PATH = path.resolve(__dirname, '../../test-data/comments-tcs/gd-open-comment.docx'); | ||
|
|
||
| const REVIEWER = { name: 'Guest Reviewer', email: 'track@example.com' }; | ||
|
|
||
| /** Group tracked-deletion text by logical change id. One id == one logical deletion. */ | ||
| const snapshotTrackDeletesById = (superdoc: SuperDocFixture): Promise<Record<string, string>> => | ||
| superdoc.page.evaluate(() => { | ||
| const editor = (window as any).editor; | ||
| const deleteById: Record<string, string> = {}; | ||
| editor.state.doc.descendants((node: any) => { | ||
| if (!node.isText || !node.text) return; | ||
| for (const mark of node.marks ?? []) { | ||
| if (mark.type?.name !== 'trackDelete') continue; | ||
| const id = String(mark.attrs?.id ?? ''); | ||
| if (!id) continue; | ||
| deleteById[id] = (deleteById[id] ?? '') + node.text; | ||
| } | ||
| }); | ||
| return deleteById; | ||
| }); | ||
|
|
||
| const setReviewer = (superdoc: SuperDocFixture): Promise<void> => | ||
| superdoc.page.evaluate((user) => { | ||
| (window as any).editor.setOptions({ user }); | ||
| }, REVIEWER); | ||
|
|
||
| test('contiguous Backspace deletion in suggesting mode is ONE tracked deletion (single run)', async ({ superdoc }) => { | ||
| await setReviewer(superdoc); | ||
| // Author normal content in editing mode, then switch to suggesting so the | ||
| // deletion is tracked (deleting an own insertion would collapse instead). | ||
| await superdoc.type('Alpha Beta'); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.setDocumentMode('suggesting'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| const pos = await superdoc.findTextPos('Beta'); | ||
| await superdoc.setTextSelection(pos + 'Beta'.length); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| for (let i = 0; i < 'Beta'.length; i += 1) { | ||
| await superdoc.press('Backspace'); | ||
| await superdoc.waitForStable(); | ||
| } | ||
|
|
||
| const deleteById = await snapshotTrackDeletesById(superdoc); | ||
| const ids = Object.keys(deleteById); | ||
| expect(ids).toHaveLength(1); | ||
| expect(deleteById[ids[0]]).toBe('Beta'); | ||
| }); | ||
|
|
||
| test('Backspace deletion across a run seam (Google-Docs comment anchors) is ONE tracked deletion', async ({ | ||
| superdoc, | ||
| }) => { | ||
| test.skip(!fs.existsSync(GD_DOC_PATH), 'Corpus document not available — run pnpm corpus:pull'); | ||
|
|
||
| // Imported Google-Docs paragraph "Open comment from Google Docs." is stored | ||
| // as two runs ("Open comment " + "from Google Docs.") with a comment anchored | ||
| // across the seam. Deleting back across that seam used to mint a second | ||
| // tracked deletion (SD-3358); it must stay one. | ||
| await superdoc.loadDocument(GD_DOC_PATH); | ||
| await superdoc.waitForStable(); | ||
| await setReviewer(superdoc); | ||
| await superdoc.setDocumentMode('suggesting'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| const before = await snapshotTrackDeletesById(superdoc); | ||
| expect(Object.keys(before)).toHaveLength(0); | ||
|
|
||
| // Caret at the end of the paragraph, then Backspace back across the seam: | ||
| // 25 chars deletes "comment from Google Docs." and leaves "Open " live. | ||
| const docsPos = await superdoc.findTextPos('Docs.'); | ||
| await superdoc.setTextSelection(docsPos + 'Docs.'.length); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| for (let i = 0; i < 'comment from Google Docs.'.length; i += 1) { | ||
| await superdoc.press('Backspace'); | ||
| await superdoc.waitForStable(); | ||
| } | ||
|
|
||
| const deleteById = await snapshotTrackDeletesById(superdoc); | ||
| const ids = Object.keys(deleteById); | ||
| expect(ids).toHaveLength(1); | ||
| expect(deleteById[ids[0]]).toBe('comment from Google Docs.'); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.