Skip to content

fix(live-preview): use live doc content for table column/row operations#156

Open
zhenyu666-debug wants to merge 1 commit into
floatboatai:mainfrom
zhenyu666-debug:fix/live-preview-table-ops-v2
Open

fix(live-preview): use live doc content for table column/row operations#156
zhenyu666-debug wants to merge 1 commit into
floatboatai:mainfrom
zhenyu666-debug:fix/live-preview-table-ops-v2

Conversation

@zhenyu666-debug

@zhenyu666-debug zhenyu666-debug commented Jul 14, 2026

Copy link
Copy Markdown

fix(live-preview): use live doc content for table column/row operations

Summary / 摘要

When adding or deleting columns/rows in a table, the operation now reads
cell content from the live editor document instead of the stale widget
snapshot. This fixes the 'click-twice' bug where the first add/delete
would fail because it used outdated content.

对表格进行添加或删除行列操作时,现在从实时编辑器文档读取单元格内容,
而不是过时的 widget 快照。这修复了"点击两次"的 bug——第一次操作会失败,
因为使用的是过期内容。

Motivation / 背景与动机

When a user clicks to add a column or delete a row in a table cell that
has pending uncommitted edits (IME input, selection, etc.), the widget
snapshot used for computing new cell content was stale. Two scenarios:

  1. Add column: snapshot shows old column count → new column gets wrong content
  2. Delete row: snapshot shows old row count → operation fails or deletes wrong row

用户点击添加列或删除行时,如果单元格有未提交的编辑(输入法输入、选区等),
widget 快照用于计算新单元格内容时已经过期。两种场景:

  1. 添加列:快照显示旧的列数 → 新列内容错误
  2. 删除行:快照显示旧的行数 → 操作失败或删错行
  • Issue: 点击两次才能成功添加/删除行列
  • Roadmap (docs/ROADMAP.md): live-preview stability / cell interaction
  • OpenSpec change: n/a (bug fix, no new capability)

Changes / 变更内容

Rebased to single commit — previous 8 commits reverted and rebuilt as one clean commit.

  • packages/core:
    • live-preview-table.ts: range detection rewritten to walk doc.lineAt() boundaries
      instead of guessing via this.source.length + 512. Prevents eating trailing
      paragraphs and missing rows on long tables.
    • live-preview-table.ts: stale guard restored in dispatch() and addRow() — checks
      that the live slice still looks like a table start before writing back.
    • live-preview-table.ts: all structural ops (addColumn, deleteColumn, addRow,
      deleteRow, moveColumn, moveRow) now read from liveSource() so cell edits
      made between re-renders are reflected in the next operation.
    • packages/core/test/live-preview-table-ops.test.ts: new regression suite covering
      trailing body preservation, live cell content after focus lock, IME composition,
      and undo/redo round-trip.
  • packages/plugin-*: no changes
  • apps/electron-demo: no changes

Testing / 测试

  • pnpm test passes / 全绿
  • Affected packages build (pnpm build) / 受影响包构建通过
  • New / updated vitest cases / 新增或更新的 vitest 用例:
    packages/core/test/live-preview-table-ops.test.ts — 5 regression scenarios:
    1. Trailing paragraphs preserved after addColumn
    2. Trailing paragraphs preserved after addRow
    3. First-click after cell edit reads live content (not stale snapshot)
    4. IME composition text survives the next addColumn
    5. Undo/redo round-trip for addColumn
  • Manual UI check in electron-demo / electron-demo 手动验证:
    • Add column after IME input → new column gets correct content ✓
    • Delete row after text selection → correct row deleted ✓
    • Click-twice scenario → first click works now ✓

Compliance / 合规自检

  • CLA signed
  • New dependencies (if any) listed with license & rationale: none
  • No build artifacts committed (dist/, dist-electron/, compiled .js from .ts) / 未提交构建产物
  • No secrets / .env / personal vault data committed / 无敏感信息

Checklist / 自检清单

  • Title follows Conventional Commits / 标题遵循 Conventional Commits
  • Public API changes update package README / types — no public API changed
  • Touched live-preview-table.ts → walked through the 12 Table Widget rules in CLAUDE.md /
    • 已核对 12 条表格规则 (add/delete column/row 不涉及 cell focus/editing/IME/selection)
  • New capability / breaking change → OpenSpec proposal linked / n/a (bug fix, no new capability)
  • Change aligns with project scope (GOVERNANCE.md §4) / 改动符合 GOVERNANCE.md §4 的项目范围

@CLAassistant

CLAassistant commented Jul 14, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@zhenyu666-debug zhenyu666-debug force-pushed the fix/live-preview-table-ops-v2 branch 2 times, most recently from 01ad993 to 53bc801 Compare July 15, 2026 07:55
@zhenyu666-debug

Copy link
Copy Markdown
Author

/cla check

1 similar comment
@zhenyu666-debug

Copy link
Copy Markdown
Author

/cla check

@zhenyu666-debug zhenyu666-debug force-pushed the fix/live-preview-table-ops-v2 branch from 7581ba4 to 68063f8 Compare July 15, 2026 09:36
@zhenyu666-debug

Copy link
Copy Markdown
Author

/cla check

1 similar comment
@zhenyu666-debug

Copy link
Copy Markdown
Author

/cla check

@zhenyu666-debug zhenyu666-debug force-pushed the fix/live-preview-table-ops-v2 branch from 68063f8 to 8548da6 Compare July 15, 2026 09:44
@zhenyu666-debug

Copy link
Copy Markdown
Author

/cla check

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.

3 participants