Repository navigation
Add workspaceEditUndoStops proposal and group typing undo in Markdown editor - #350198
Henning Dieterichs (hediet) wants to merge 7 commits into
Conversation
…tops Fixes #328933 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Undo grouping still merges edits across navigation, deletion-direction changes, paste operations, and batched word boundaries, causing Undo to remove more text than intended.
4 open issues
What changed in this PR
This PR addresses character-by-character undo in the Markdown custom editor by adding proposed workspace-edit undo controls and using them to group typing and deletions.
Changes:
- Adds and gates
workspaceEditUndoStops, threading its metadata through the bulk-edit pipeline. - Introduces Markdown undo grouping and resets it at supported interaction boundaries.
- Adds proposal-gating, undo/redo, grouping, and bridge tests.
| File | Description |
|---|---|
src/vscode-dts/vscode.proposed.workspaceEditUndoStops.d.ts |
Declares proposed undo-stop metadata. |
src/vs/workbench/contrib/bulkEdit/browser/bulkTextEdits.ts |
Supports appending single-document edits to open undo elements. |
src/vs/workbench/contrib/bulkEdit/browser/bulkEditService.ts |
Passes undo controls while isolating mixed edit groups. |
src/vs/workbench/api/test/browser/mainThreadEditors.test.ts |
Tests coalescing, explicit boundaries, and undo/redo. |
src/vs/workbench/api/test/browser/extHostBulkEdits.test.ts |
Tests proposal gating and metadata forwarding. |
src/vs/workbench/api/common/extHostBulkEdits.ts |
Gates and forwards proposed metadata. |
src/vs/workbench/api/common/extHost.protocol.ts |
Extends the bulk-edit remote-call contract. |
src/vs/workbench/api/browser/mainThreadBulkEdits.ts |
Forwards undo controls to the bulk-edit service. |
src/vs/platform/extensions/common/extensionsApiProposals.ts |
Registers the new proposal. |
src/vs/editor/browser/services/bulkEditService.ts |
Adds internal undo-stop options. |
extensions/markdown-language-features/tsconfig.json |
Includes the proposal declarations. |
extensions/markdown-language-features/src/test/markdownEditorUndoGrouping.test.ts |
Tests typing, deletion, and reset grouping rules. |
extensions/markdown-language-features/src/test/markdownEditorBridge.test.ts |
Tests word-level undo/redo through the bridge. |
extensions/markdown-language-features/src/preview/markdownEditorUndoGrouping.ts |
Implements Markdown undo-grouping decisions. |
extensions/markdown-language-features/src/preview/markdownEditorProvider.ts |
Applies grouping metadata and resets grouping state. |
extensions/markdown-language-features/package.json |
Enables the proposal for the Markdown extension. |
Review effort: Balanced
…it/navigation/paste hints - Split batched typing insertions at word/space undo-stop boundaries so undo granularity does not depend on IPC batching - Forward explicit undoEditHint notifications (break, isolated, deleteBackward, deleteForward) from the Markdown editor webview for pointer/navigation moves, plain-text pastes of any length, and deletion direction switches - Add unit tests and burst-typing integration regression test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Connor Peet (connor4312)
left a comment
There was a problem hiding this comment.
Two blocking sync regressions in split writes: a concurrent document change can stall the Markdown editor, and a partially applied batch can silently drop typed text. I also found one non-blocking undo-boundary issue under batching.
Written by Connor's agent running GPT-6.1 Sol
Addresses @connor4312 review feedback on #350198: - Add workspace.applyEditSequence (under workspaceEditUndoStops) backed by BulkTextEditSequence so multi-segment single-document edits validate document version once and apply atomically with per-step undo stops (eliminating partial writes). - Buffer document change events during applyEdit/applyEditSequence and replay all buffered external changes on rejection (or after our atomic segments), preventing stalls when a competing edit wins the race. - Track paste (isolated) and navigation (break) hint offsets through TextDocumentSync so composed pending edits preserve paste/break boundaries without isolating adjacent typing. - Add unit and bridge regression tests for all three scenarios. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Base:
|
When vscode.workspace.applyEdit(external) and applyEditSequence(editor) race on the same initial document version, applyEditSequence can win first (fewer microtask hops than BulkTextEdits) and cause externalApplied to return false. Handle either race outcome in the test so both edits still land and convergence is verified deterministically across Electron, Browser, and Remote test runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pull request was closed
In remote integration CI runs, background panel initialization (e.g. Chat) can
steal focus after showTextDocument, causing executeCommand('undo') to target the
focused panel input instead of the test document. Re-focus the document right
before each undo/redo command and revert/close the untitled editor in finally.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1f20996
…-granularity Resolved conflict in src/vs/platform/extensions/common/extensionsApiProposals.ts by keeping both workbenchMode and workspaceEditUndoStops in alphabetical order. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-granularity Resolved conflicts with textDocumentReadonly in package.json, tsconfig.json, and markdownEditorProvider.ts (preserving both document.isReadonly checks and undo grouping / atomic applyEditSequence). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Summary
Fixes #328933
In the Markdown custom text editor, every keystroke is applied to the backing
TextDocumentvia a separatevscode.workspace.applyEditcall. BecauseBulkTextEditsunconditionally creates and closes a newSingleModelEditStackElementfor each call, pressing Undo (Ctrl+Z/Cmd+Z) reverted one character at a time instead of word/phrase chunks.This PR adds a minimal proposed API (
workspaceEditUndoStops) to control undo-stop boundaries on single-documentWorkspaceEdits and adopts it inMarkdownEditorProviderso contiguous typing and deletions coalesce into word-level undo steps matching VS Code's regular text editor.Demo
Typing
"The quick brown fox jumps over the lazy dog."character-by-character in the Markdown Editor, then pressingCtrl+Zthree times andCtrl+Ytwice (Code OSS from this branch):undo-granularity-demo.webm
Ctrl+Z(removes" dog."as one step)What Changed
1. Workbench & Proposed API (
workspaceEditUndoStops)src/vscode-dts/vscode.proposed.workspaceEditUndoStops.d.tsextendingWorkspaceEditMetadatawith optionalundoStopBefore?: booleanandundoStopAfter?: boolean(both default totrue, preserving existing behavior for all callers).workspaceEditUndoStopsinsrc/vs/platform/extensions/common/extensionsApiProposals.tsand gated usage inExtHostBulkEdits.applyWorkspaceEditviacheckProposedApiEnabled.undoStopBefore/undoStopAfterthroughMainThreadBulkEdits->IBulkEditOptions->BulkEditService->BulkTextEdits.BulkTextEdits.apply(single-document text edits only):undoStopBeforeistrue(default), closes any previously open stack element viatask.model.pushStackElement()before pushing a newSingleModelEditStackElement.undoStopBeforeisfalse, reuses the topSingleModelEditStackElementon the document's undo stack if it is still open (canAppend(task.model)).undoStopAfterisfalse, leaves theSingleModelEditStackElementopen so the nextundoStopBefore: falseedit can coalesce into it; whentrue(default), closes it as before.2. Markdown Editor Adapter
extensions/markdown-language-features/src/preview/markdownEditorUndoGrouping.ts(MarkdownEditorUndoGrouper), mirroring VS Code'sshouldPushStackElementBetweenword/space/edit-kind grouping:"hello"|" world"), and consecutive spaces coalesce then break before the next word.MarkdownEditorProviderto pass the computed{ undoStopBefore, undoStopAfter }metadata tovscode.workspace.applyEditand enabled theworkspaceEditUndoStopsproposal inextensions/markdown-language-features/package.jsonandtsconfig.json.API Design Note (for review)
undoStopBefore/undoStopAfteronWorkspaceEditMetadata?TextEditor.edit(cb, { undoStopBefore, undoStopAfter })API verbatim, so custom text editors get the exact same primitive thatTextEditorextensions already use without introducing a new undo-group token lifecycle or custom-editor-only edit method.true/true, so existing callers and multi-file edits are unaffected.@vscode/web-editors,MarkdownEditorUndoGrouperhas zero VS Code runtime dependencies (onlyDocumentTextEdit) and can move there cleanly.Validation
coreTypecheck(dw run .tmp\dev-workspace.ts coreTypecheck): passedtypecheck(dw run .tmp\dev-workspace.ts typecheck): passedbuild/hygiene.tson all 14 touched source/test files): passed (0 errors)scripts/test.bat --run src/vs/workbench/api/test/browser/extHostBulkEdits.test.ts --run src/vs/workbench/api/test/browser/mainThreadEditors.test.ts): 13 passing (including proposal gating, coalescing consecutive edits, undo/redo, andundoStopBefore: trueboundary breaking)dw run .tmp\dev-workspace.ts markdownExtensionTests): 226 passing (includingMarkdownEditorUndoGrouperunit tests and end-to-endMarkdown editor bridgetyping + undo/redo test)slot-15, recorded above)