Skip to content

fix: center search result line in read-only markdown view - #692

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/02b4d2cbd4d4
Oct 28, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/02b4d2cbd4d4

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

fix: center search result line in read-only markdown view

  1. Root cause (scroll): in read-only markdown view search next/prev called
    jumpToLine with keepLineAtCenter=false, so the hidden TextEdit only
    scrolled minimally and kept the match at the bottom edge of its own
    viewport, while render-page sync only aligns the top visible block;
    since the 800px rendered column is taller per source line, the match
    fell below the rendered fold (reliably reproducible when maximized)
  2. Fix (scroll): pass keepLineAtCenter=true in searchKeywordSeletion so
    keepCurrentLineAtCenter centers the anchor line; the explicit
    scrollbar setValue also drives valueChanged render-page scroll sync
  3. Root cause (highlight): clicking next/prev as the first find action of
    a session never registers the keyword (m_keywordForSearchAll stays
    empty), so handleFindKeyword took the clear branch and never pushed
    highlightSearch to the rendered page - the match scrolled into view
    but carried no highlight (Enter works because it registers)
  4. Fix (highlight): handleFindKeyword now registers the current keyword
    and always calls highlightKeywordInView, matching the Enter path
  5. Test: EditWrapper UT (maximized/normal, Enter/click paths) asserts
    scrollToLine lands within half a screen of the match; Window UT
    asserts click-first pushes highlightSearch to the renderer

Log: fix search result not visible in read-only markdown view

Influence:

  1. Test search next/prev in read-only markdown view, verify the match is
    highlighted and centered, clicking Next first without pressing Enter
  2. Test search next/prev in edit mode, verify no regression
  3. Verify render-page highlight follows find next/prev and page scroll

fix: 修复只读Markdown视图下查找结果不在当前屏显示

  1. 根因(滚动):只读Markdown视图下查找下一个/上一个调用jumpToLine时
    传入keepLineAtCenter=false,隐藏的TextEdit仅做最小滚动、匹配项停在
    其视口底边缘,而渲染页滚动同步仅按顶部可见行对齐;800px定宽渲染列
    每源码行渲染高度更大,匹配项落到渲染视口折叠线下(最大化时必现)
  2. 方案(滚动):searchKeywordSeletion中jumpToLine的keepLineAtCenter改为
    true,keepCurrentLineAtCenter将锚点行居中,显式scrollbar setValue
    同时驱动valueChanged渲染页滚动同步
  3. 根因(高亮):会话内首个查找动作若直接点击"下一个"(未经回车路径
    注册查找词),m_keywordForSearchAll为空使handleFindKeyword走清空
    分支,渲染页收不到highlightSearch推送——匹配滚入视口却无任何高亮
    (回车路径会注册查找词,故先回车后点击一切正常)
  4. 方案(高亮):handleFindKeyword注册当前查找词并无条件调用
    highlightKeywordInView,与回车路径行为对齐
  5. 测试:EditWrapper单测(最大化/普通窗口、回车/点击路径)断言
    scrollToLine落点距匹配行不超半屏;Window单测断言点击先行也会向
    渲染页推送highlightSearch

Log: 修复只读Markdown视图下查找结果不在当前屏显示的问题

Influence:

  1. 在只读Markdown视图下不按回车、直接点击"下一个"测试查找,验证匹配
    内容带高亮且居中显示,重点验证窗口最大化场景
  2. 在编辑模式下测试查找功能,验证无回归
  3. 验证渲染页高亮随查找下一个/上一个同步刷新

PMS: BUG-380705

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Search next/previous now centers the matched line by enabling jumpToLine’s keepLineAtCenter behavior, which updates the scrollbar and triggers read-only Markdown render-page synchronization without changing other jumpToLine callers.

Sequence diagram for centered search synchronization

sequenceDiagram
    participant User
    participant TextEdit
    participant ScrollBar
    participant MarkdownView

    User->>TextEdit: searchKeywordSeletion(keyword, cursor, findNext)
    TextEdit->>TextEdit: jumpToLine(line, true)
    TextEdit->>TextEdit: keepCurrentLineAtCenter()
    TextEdit->>ScrollBar: setValue(value)
    ScrollBar-->>MarkdownView: valueChanged(value)
    MarkdownView->>MarkdownView: synchronize rendered-page scroll
    TextEdit->>TextEdit: setTextCursor(match)
Loading

File-Level Changes

Change Details Files
Center the editor on search matches so read-only Markdown rendering receives the scrollbar synchronization event.
  • Pass true for keepLineAtCenter in both next and previous search navigation paths.
  • Preserve existing cursor and match-highlight updates while invoking centered scrolling.
src/editor/dtextedit.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@pengfeixx
pengfeixx force-pushed the agent/agent/02b4d2cbd4d4 branch from 744f7ff to 076d9fd Compare October 28, 2026 02:49
1. Root cause: in read-only markdown view search next/prev called
   jumpToLine with keepLineAtCenter=false, so the hidden TextEdit only
   scrolled minimally and kept the match at the bottom edge of its own
   viewport, while render-page sync only aligns the top visible block;
   since the 800px rendered column is taller per source line, the match
   fell below the rendered fold (reliably reproducible when maximized)
2. Fix: pass keepLineAtCenter=true in searchKeywordSeletion so
   keepCurrentLineAtCenter centers the anchor line; the explicit
   scrollbar setValue also drives valueChanged render-page scroll sync
3. Test: add EditWrapper UT cases (maximized/normal window) asserting
   the renderer receives scrollToLine near the matched line; all 107
   editor_wrapper UT cases pass

Log: fix search result not visible in read-only markdown view

Influence:
1. Test search next/prev in read-only markdown view, verify match is
   centered on screen, especially with a maximized window
2. Test search next/prev in edit mode, verify no regression
3. Verify render-page scroll sync follows editor scrollbar

fix: 修复只读Markdown视图下查找结果不在当前屏显示

1. 根因:只读Markdown视图下查找下一个/上一个调用jumpToLine时传入
   keepLineAtCenter=false,隐藏的TextEdit仅做最小滚动、匹配项停在
   其视口底边缘,而渲染页滚动同步仅按顶部可见行对齐;800px定宽
   渲染列每源码行渲染高度更大,匹配项落到渲染视口折叠线下
   (窗口最大化时必现)
2. 方案:searchKeywordSeletion中jumpToLine的keepLineAtCenter改为
   true,keepCurrentLineAtCenter将锚点行居中,显式scrollbar
   setValue同时驱动valueChanged渲染页滚动同步
3. 测试:新增EditWrapper单测(最大化/普通窗口两场景),断言渲染器
   收到的scrollToLine行号贴近匹配行;editor_wrapper 107例全部通过

Log: 修复只读Markdown视图下查找结果不在当前屏显示的问题

Influence:
1. 在只读Markdown视图下测试查找下一个/上一个,验证匹配内容居中
   显示,重点验证窗口最大化场景
2. 在编辑模式下测试查找功能,验证无回归
3. 验证渲染页滚动与编辑器滚动条同步

PMS: BUG-380705
@pengfeixx
pengfeixx force-pushed the agent/agent/02b4d2cbd4d4 branch from 076d9fd to 2440706 Compare October 28, 2026 03:52
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了只读 Markdown 视图下搜索结果行未居中的问题,将 jumpToLine 的居中参数从 false 改为 true,变更范围小且目标明确。同时新增了 V6705 验证用例覆盖最大化窗口和普通窗口两种场景。四维度均无问题,无安全漏洞。OCR 建议补充下界断言以增强测试鲁棒性,属改进建议而非缺陷。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议在观测点 2 后补充下界断言 EXPECT_GE(dist, -3),确保渲染页不会过度滚动超过匹配行,使测试同时覆盖欠滚动和过滚动两种回归场景']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 建议在测试中补充下界断言,增强测试鲁棒性: // 观测点 1:渲染页确实收到滚动指令 EXPECT_GE(renderer->scrollCalls, 1); // 观测点 2(修复语义):同步行号与匹配行相距不超过半屏 + 少量余量 EXPECT_LE(dist, visibleLines / 2 + 3); // 观测点 3:渲染页未滚动超过匹配行(防止过度滚动) EXPECT_GE(dist, -3);

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 024d720 into linuxdeepin:master Oct 28, 2026
17 checks passed
@pengfeixx
pengfeixx deleted the agent/agent/02b4d2cbd4d4 branch October 28, 2026 07:30
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