feat(history): group table undo actions and keep silent loads out of history - #364
Open
ruike123xxx wants to merge 2 commits into
Open
ruike123xxx wants to merge 2 commits into
ruike123xxx wants to merge 2 commits into
Conversation
Keep CM6 typing joins, isolate table actions, and split pending cell commits so Ctrl+Z matches one complete table action. Co-authored-by: Cursor <cursoragent@cursor.com>
Silent setDocument was still recorded as an edit, so Ctrl+Z after opening a file reverted the previous buffer. Undo also skipped in-progress table cells that had not blurred yet. Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
This branch has not been deployed
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.
Summary / 摘要
Group live-preview table edits into one undo step per complete action, and keep silent document loads out of the undo stack.
表格 live-preview 按完整动作(格失焦 / 增删行列)各成一条撤销;silent 打开文件不再进入撤销栈。
Motivation / 背景与动机
Roadmap #8 asks for undo/redo grouping and explicitly says to coordinate with
tableEditingCount. Three real gaps, no new host API:Roadmap 第 8 项要求 undo/redo 分组,并点名要协同
tableEditingCount。三个真实缺口,不加新的宿主 API:Table widget edits joined typing or each other. Cell commits and add/remove row/column are adjacent document changes. Without
isolateHistory, CodeMirror'snewGroupDelaymerged a table action with nearby typing — one Ctrl+Z reverted both.表格操作会和打字并进同一组。 格提交、增删行列都是相邻的文档变更。不加
isolateHistory,CM6 的newGroupDelay会把一次表格动作和旁边的打字并掉,一次 Ctrl+Z 两边一起退。Cell-to-cell navigation cannot dispatch. Existing live-preview tests forbid a blurred cell from stealing focus. So a cell blur that is only moving to another cell must queue the commit (
pendingCellCommits) and flush isolated transactions only when leaving the table, while holding the editing lock so CM6 does not recreate the widget mid-flush.格子之间不能立刻写回。 已有 live-preview 测试禁止失焦格子抢焦点。格到格的 blur 只能先把提交排进
pendingCellCommits,离开表格后再按格做隔离 dispatch,并且要抓住 editing lock,避免 CM6 在 flush 中途拆掉 widget。Silent loads and dirty cells polluted history.
setDocument(md, { silent: true })is the file-open path, but it was still recorded as an edit — Ctrl+Z after open reverted the previous buffer. Programmaticundo()/redo()also skipped a cell that had not blurred yet.silent 加载和未失焦的格子会污染历史。
setDocument(..., { silent: true })是打开文件的路径,却仍被记成一次编辑——打开后立刻 Ctrl+Z 会退回上一份文档。程序化undo()/redo()也看不到还没 blur 的格子。docs/ROADMAP.md): Item feat(core): add getSelectedText() API #8 — Undo / redo grouping (P1, Needs OpenSpec = No)Changes / 变更内容
packages/core:src/live-preview-table.ts— tag cell / structure commits withinput.table.cell/input.table.structure+isolateHistory.of("full"). Queue per-cell commits on blur; flush them as isolated transactions when leaving the table. RouteaddRow()through the shareddispatch()so it gets the source-staleness guard.src/editor.ts— silentsetDocument/replaceRangeuseTransaction.addToHistory.of(false).undo()/redo()flush pending table edits before calling CodeMirror.src/types.ts— document thatsilentalso excludes the change from undo history.packages/plugin-history:transactionExtenderisolatesinput.table.*userEvents. NoHistoryPluginOptions, nogetUndoDepth, nogroupHistory. Typing still uses CM6 default joins.@codemirror/state(MIT) forTransaction.userEvent/transactionExtender.docs/ROADMAP.md/ROADMAP.zh.md: item feat(core): add getSelectedText() API #8 →in-progress.README.md/README.zh.md: plugin-history line mentions table grouping and silent-load exclusion.apps/electron-demo: —openspec/: —Testing / 测试
plugin-history10,editor48,live-preview84,live-preview-regressions9,plugin-toolbar44,transaction-pipeline7,dynamic-contributions10 (212 tests).packages/plugin-history/test/plugin-history.test.ts— CM6 typing still joins; table cell vs typing isolation; live GFM cell blur undo/redo; adjacent cells after blur are two undos; add-column is one undo; consecutive add-row clicks are two undos; dirty cell +undo()without blur reverts the in-progress edit.packages/core/test/editor.test.ts— silentsetDocument/replaceRangestay out of history; non-silentsetDocumentremains undoable.Compliance / 合规自检
userEvent, queue commits when cell-to-cell navigation cannot dispatch, exclude silent loads withaddToHistory: false.AI-assisted notes / AI 使用说明:AI 结对起草实现与测试;逐行对照表格 12 条规则和已有失焦测试。未新增宿主 API。
@codemirror/state@^6.6.0— MIT —Transaction.userEvent/transactionExtenderinplugin-history; already used by sibling packages..env/ personal vault data committed / 无敏感信息Checklist / 自检清单
silenthistory exclusion documented onsetDocument/replaceRange; no new methodslive-preview-table.ts→ walked through the 12 Table Widget rules in CLAUDE.md / 已核对 12 条表格规则 — cell-to-cell still skips dispatch;tableEditingCountheld across queued flush;addRowuses shared dispatch; no HTML5 drag; no inline border styles