Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideImplementationUpdate zip-mode anchor construction to use the rendered table’s position instead of the containing block’s position, while preserving the block-position fallback.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/editor/markdown/web/main.js" line_range="238" />
<code_context>
lastAnchorMode = "zip";
for (let i = 0; i < children.length; i++) {
- anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(children[i]) });
+ if (blocks[i].type === "table") {
+ const trs = children[i].querySelectorAll("table tbody tr");
+ if (trs.length > 0) {
</code_context>
<issue_to_address>
**Packaged preview keeps table drift**
When the application runs its embedded preview with the checked-in bundle, `milkdown.html` loads `build/main.bundle.js`, and the Qt resource embeds that bundle rather than `main.js`. Since the bundle still uses block-level table anchors, the row-level mapping never reaches users and table scrolling remains misaligned.
Regenerate `build/main.bundle.js` and the Qt resource from the updated `main.js`.
Also at `src/editor/markdown/web/main.js:239`.
</issue_to_address>
### Comment 2
<location path="src/editor/markdown/web/main.js" line_range="242" />
<code_context>
+ const trs = children[i].querySelectorAll("table tbody tr");
+ if (trs.length > 0) {
+ anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(trs[0]) });
+ if (trs.length > 1) {
+ anchors.push({ sourceLine: blocks[i].startLine + 1,
+ previewY: trs[0].getBoundingClientRect().bottom + window.scrollY });
</code_context>
<issue_to_address>
**Header-only tables misalign scrolling**
When a valid GFM table has a header and separator but no data rows, `buildAnchorMap` skips the separator-line anchor because `trs.length` is 1, so `lineToPreviewY` and `previewYToLine` interpolate that line toward the next block or document sentinel instead of mapping it to the header row’s bottom. Scrolling around the table is misaligned.
Add the separator-line anchor for a table with a header even when it has no data rows.
Also at `src/editor/markdown/web/main.js:243`.
</issue_to_address>
### Comment 3
<location path="src/editor/markdown/web/main.js" line_range="241-246" />
<code_context>
+ if (blocks[i].type === "table") {
+ const trs = children[i].querySelectorAll("table tbody tr");
+ if (trs.length > 0) {
+ anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(trs[0]) });
+ if (trs.length > 1) {
+ anchors.push({ sourceLine: blocks[i].startLine + 1,
+ previewY: trs[0].getBoundingClientRect().bottom + window.scrollY });
+ for (let r = 1; r < trs.length; r++) {
+ anchors.push({ sourceLine: blocks[i].startLine + r + 1, previewY: docY(trs[r]) });
+ }
+ }
</code_context>
<issue_to_address>
**Anchor harness reports failure**
When the local Markdown harness is run against a document containing its existing table fixture, the new table-row anchors make `amap.slice(0, expectedLines.length)` include the table's delimiter and data-row anchors, so the existing `A1_anchor_exact_source_lines` check compares `20` with the expected paragraph line `23` and reports FAIL whenever the local harness runs.
Update the harness assertion to account for the table's row anchors while still checking the following block's source line.
</issue_to_address>
### Comment 4
<location path="src/editor/markdown/web/main.js" line_range="241" />
<code_context>
+ if (blocks[i].type === "table") {
+ const trs = children[i].querySelectorAll("table tbody tr");
+ if (trs.length > 0) {
+ anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(trs[0]) });
+ if (trs.length > 1) {
+ anchors.push({ sourceLine: blocks[i].startLine + 1,
</code_context>
<issue_to_address>
**Progressive rendering skips row anchors**
When the user scrolls while a multi-batch document is still rendering, `buildAnchorMap` reaches this table-row branch only when AST blocks and rendered children have equal counts; during a multi-batch render, its mismatch path builds heading-only anchors, so table scroll synchronization remains approximate until rendering completes.
Provide table-row anchors in the progressive-render mismatch path, or otherwise preserve accurate table mapping while batches are incomplete.
</issue_to_address>| lastAnchorMode = "zip"; | ||
| for (let i = 0; i < children.length; i++) { | ||
| anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(children[i]) }); | ||
| if (blocks[i].type === "table") { |
There was a problem hiding this comment.
🟠 High · Packaged preview keeps table drift
When the application runs its embedded preview with the checked-in bundle, milkdown.html loads build/main.bundle.js, and the Qt resource embeds that bundle rather than main.js. Since the bundle still uses block-level table anchors, the row-level mapping never reaches users and table scrolling remains misaligned.
Regenerate build/main.bundle.js and the Qt resource from the updated main.js.
Also at src/editor/markdown/web/main.js:239.
Prompt for AI agents
In `src/editor/markdown/web/main.js` at line 238:
**Packaged preview keeps table drift**
When the application runs its embedded preview with the checked-in bundle, `milkdown.html` loads `build/main.bundle.js`, and the Qt resource embeds that bundle rather than `main.js`. Since the bundle still uses block-level table anchors, the row-level mapping never reaches users and table scrolling remains misaligned.
Regenerate `build/main.bundle.js` and the Qt resource from the updated `main.js`.
Also at `src/editor/markdown/web/main.js:239`.| const trs = children[i].querySelectorAll("table tbody tr"); | ||
| if (trs.length > 0) { | ||
| anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(trs[0]) }); | ||
| if (trs.length > 1) { |
There was a problem hiding this comment.
🟡 Medium · Header-only tables misalign scrolling
When a valid GFM table has a header and separator but no data rows, buildAnchorMap skips the separator-line anchor because trs.length is 1, so lineToPreviewY and previewYToLine interpolate that line toward the next block or document sentinel instead of mapping it to the header row’s bottom. Scrolling around the table is misaligned.
Add the separator-line anchor for a table with a header even when it has no data rows.
Also at src/editor/markdown/web/main.js:243.
Prompt for AI agents
In `src/editor/markdown/web/main.js` at line 242:
**Header-only tables misalign scrolling**
When a valid GFM table has a header and separator but no data rows, `buildAnchorMap` skips the separator-line anchor because `trs.length` is 1, so `lineToPreviewY` and `previewYToLine` interpolate that line toward the next block or document sentinel instead of mapping it to the header row’s bottom. Scrolling around the table is misaligned.
Add the separator-line anchor for a table with a header even when it has no data rows.
Also at `src/editor/markdown/web/main.js:243`.| anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(trs[0]) }); | ||
| if (trs.length > 1) { | ||
| anchors.push({ sourceLine: blocks[i].startLine + 1, | ||
| previewY: trs[0].getBoundingClientRect().bottom + window.scrollY }); | ||
| for (let r = 1; r < trs.length; r++) { | ||
| anchors.push({ sourceLine: blocks[i].startLine + r + 1, previewY: docY(trs[r]) }); |
There was a problem hiding this comment.
🟡 Medium · Anchor harness reports failure
When the local Markdown harness is run against a document containing its existing table fixture, the new table-row anchors make amap.slice(0, expectedLines.length) include the table's delimiter and data-row anchors, so the existing A1_anchor_exact_source_lines check compares 20 with the expected paragraph line 23 and reports FAIL whenever the local harness runs.
Update the harness assertion to account for the table's row anchors while still checking the following block's source line.
Prompt for AI agents
In `src/editor/markdown/web/main.js` at lines 241-246:
**Anchor harness reports failure**
When the local Markdown harness is run against a document containing its existing table fixture, the new table-row anchors make `amap.slice(0, expectedLines.length)` include the table's delimiter and data-row anchors, so the existing `A1_anchor_exact_source_lines` check compares `20` with the expected paragraph line `23` and reports FAIL whenever the local harness runs.
Update the harness assertion to account for the table's row anchors while still checking the following block's source line.| if (blocks[i].type === "table") { | ||
| const trs = children[i].querySelectorAll("table tbody tr"); | ||
| if (trs.length > 0) { | ||
| anchors.push({ sourceLine: blocks[i].startLine, previewY: docY(trs[0]) }); |
There was a problem hiding this comment.
🟡 Medium · Progressive rendering skips row anchors
When the user scrolls while a multi-batch document is still rendering, buildAnchorMap reaches this table-row branch only when AST blocks and rendered children have equal counts; during a multi-batch render, its mismatch path builds heading-only anchors, so table scroll synchronization remains approximate until rendering completes.
Provide table-row anchors in the progressive-render mismatch path, or otherwise preserve accurate table mapping while batches are incomplete.
Prompt for AI agents
In `src/editor/markdown/web/main.js` at line 241:
**Progressive rendering skips row anchors**
When the user scrolls while a multi-batch document is still rendering, `buildAnchorMap` reaches this table-row branch only when AST blocks and rendered children have equal counts; during a multi-batch render, its mismatch path builds heading-only anchors, so table scroll synchronization remains approximate until rendering completes.
Provide table-row anchors in the progressive-render mismatch path, or otherwise preserve accurate table mapping while batches are incomplete.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 <table> 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 查找内部 <table> 元素,使用其 顶部作为 previewY;非表格块回退到 docY(child) 3. 影响:仅表格块锚点Y值变化,非表格块和函数签名不受影响 Log: 修复表格密集文档双栏滚动同步偏移问题 Influence: 1. 测试表格密集Markdown文档的滚动同步 2. 测试非表格Markdown文档的滚动同步(回归) 3. 测试混合内容(表格+标题+图片)的滚动同步 PMS: BUG-378227
761173f to
4332d07
Compare
Root Cause Analysis
The Markdown dual-pane scroll sync in deepin-editor uses
buildAnchorMap()to map source line numbers to preview Y coordinates. For table blocks, the function useddocY(children[i])which returns the top of the.table-blockdiv — this includes a 37px header wrapper (36px header + 1px border). The resulting systematic 37px offset caused visible misalignment between the editor and preview panes when scrolling table-heavy Markdown documents.Fix
Query the inner
<table>element viachild.querySelector('.table-wrapper table')and use its top aspreviewYfor table blocks. Non-table blocks fall back to the originaldocY(child)logic, preserving existing behavior.Change Safety Assessment
Code Safety
buildAnchorMap()was introduced in commit262648622(BUG-378227 initial fix). This change refines the anchor Y for table blocks; it does not revert the core anchor mapping mechanism.reapplyScroll,syncScroll, editor scroll handler) are unaffected — function signature unchanged, only internal anchor Y values change for table blocks.Business Impact Scope
Markdown dual-pane scroll sync for table-heavy documents. Non-table documents are unaffected (querySelector returns null, falls back to original logic).
Verification Suggestion
Test scroll sync with table-heavy Markdown documents (primary), non-table documents (regression), and mixed content (tables + headings + images).
根因分析
deepin-editor 的 Markdown 双栏滚动同步使用
buildAnchorMap()将源码行号映射到预览 Y 坐标。对于表格块,该函数使用docY(children[i])返回.table-blockdiv 的顶部——包含 37px 表头容器(36px 表头 + 1px 边框)。这导致系统性 37px 偏移,在滚动表格密集的 Markdown 文档时编辑栏与预览栏明显不同步。修复方案
通过
child.querySelector('.table-wrapper table')查找内部<table>元素,使用其顶部作为表格块的previewY。非表格块回退到原始docY(child)逻辑,保持现有行为不变。改动安全评估
代码安全评估
buildAnchorMap()由 commit262648622(BUG-378227 初始修复)引入。本次改动细化表格块的锚点 Y 值,不撤销核心锚点映射机制。reapplyScroll、syncScroll、编辑器滚动处理器)不受影响——函数签名不变,仅表格块的内部锚点 Y 值变化。业务影响范围
Markdown 双栏滚动同步(表格密集文档)。非表格文档不受影响(querySelector 返回 null,回退原逻辑)。
验证建议
测试表格密集 Markdown 文档的滚动同步(主要场景)、非表格文档(回归验证)、混合内容(表格+标题+图片)。
PMS: BUG-378227