From 4332d070033f903676b9bd3cb5651cc1cae1ddc0 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Mon, 16 Nov 2026 23:59:18 +0800 Subject: [PATCH] fix: correct table-block anchor Y in markdown scroll sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: buildAnchorMap() used docY(children[i]) for table blocks, which returns the .table-block div top including the 37px header wrapper, causing a systematic 37px offset in scroll sync 2. Fix: query the inner element via child.querySelector and use its top as previewY; fall back to docY(child) for non-table blocks 3. Impact: only table-block anchor Y values change; non-table blocks and function signature are unaffected Log: fix markdown dual-pane scroll sync offset for table-heavy docs Influence: 1. Test scroll sync with table-heavy markdown documents 2. Test scroll sync with non-table markdown documents (regression) 3. Test scroll sync with mixed content (tables + headings + images) fix: 修正Markdown滚动同步中表格块锚点Y坐标 1. 根因:buildAnchorMap() 对表格块使用 docY(children[i]),返回 .table-block div 的顶部(含37px表头容器),导致滚动同步存在 系统性37px偏移 2. 方案:通过 child.querySelector 查找内部
元素,使用其 顶部作为 previewY;非表格块回退到 docY(child) 3. 影响:仅表格块锚点Y值变化,非表格块和函数签名不受影响 Log: 修复表格密集文档双栏滚动同步偏移问题 Influence: 1. 测试表格密集Markdown文档的滚动同步 2. 测试非表格Markdown文档的滚动同步(回归) 3. 测试混合内容(表格+标题+图片)的滚动同步 PMS: BUG-378227 --- src/editor/markdown/web/main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/editor/markdown/web/main.js b/src/editor/markdown/web/main.js index bfe9dcfd..3ff47b6f 100644 --- a/src/editor/markdown/web/main.js +++ b/src/editor/markdown/web/main.js @@ -235,7 +235,10 @@ function buildAnchorMap() { if (blocks.length === children.length) { lastAnchorMode = "zip"; for (let i = 0; i < children.length; i++) { - anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(children[i]) }); + const child = children[i]; + const tableEl = child.querySelector('.table-wrapper table'); + const y = tableEl ? docY(tableEl) : docY(child); + anchors.push({ sourceLine: blocks[i].startLine, previewY: y }); } } else { const astHeadings = blocks.filter((b) => b.type === "heading");