Skip to content

fix: sync find highlight to render page on first next click - #699

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/v6705-click-first-highlight
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/v6705-click-first-highlight

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

fix: sync find highlight to render page on first next click

  1. Root cause: clicking next/prev as the first find action of a session
    never registers the keyword (m_keywordForSearchAll stays empty), so
    Window::handleFindKeyword took the clear branch and never pushed
    highlightSearch to the rendered MarkdownView - the match scrolled
    into view but carried no highlight; pressing Enter first registers
    the keyword, which is why "Enter then click" works but "click first"
    loses the highlight (verified on the Qt 6.8.0 build of BUG-380705)
  2. Fix: handleFindKeyword now registers the current keyword and always
    calls highlightKeywordInView, matching the Enter path
    (handleUpdateSearchKeyword)
  3. Test: Window UT asserts click-first pushes highlightSearch to the
    injected renderer with the right keyword and advancing match index;
    EditWrapper UT adds Enter/click path-parity and LivePreview-then-
    ReadView flow scenarios for the scroll sync regression

Log: fix find highlight missing when clicking next before enter

Influence:

  1. In read-only markdown view, press Ctrl+F and click Next directly
    without pressing Enter, verify the match is highlighted and centered
  2. Test the same flow in edit mode and live preview, verify no regression
  3. Verify render-page highlight follows subsequent next/prev clicks

fix: 修复直接点击"下一个"时渲染页无查找高亮

  1. 根因:会话内首个查找动作若直接点击"下一个/上一个"(未经回车路径
    注册查找词),m_keywordForSearchAll为空使handleFindKeyword走清空
    分支,渲染页收不到highlightSearch推送——匹配滚入视口却无任何高亮;
    回车路径会注册查找词,故"先回车再点击"正常、"直接点击"丢高亮
    (在BUG-380705修复版 Qt 6.8.0 构建上实测确认)
  2. 方案:handleFindKeyword注册当前查找词并无条件调用
    highlightKeywordInView,与回车路径行为对齐
  3. 测试:Window单测断言点击先行也会向注入渲染器推送highlightSearch
    且命中序号随点击推进;EditWrapper单测补充回车/点击路径一致性与
    LivePreview进只读视图流程的滚动同步回归场景

Log: 修复只读Markdown视图下直接点击"下一个"渲染页无高亮的问题

Influence:

  1. 在只读Markdown视图下Ctrl+F后不按回车、直接点击"下一个",验证匹配
    内容带高亮且居中显示
  2. 在编辑模式与实时预览下验证相同流程无回归
  3. 验证渲染页高亮随后续点击"下一个/上一个"同步刷新

PMS: BUG-380705

Summary by Sourcery

Synchronize rendered-page find highlights when navigating search results directly with Next or Previous.

Bug Fixes:

  • Ensure clicking Next or Previous as the first find action registers the search term and synchronizes highlights to the rendered Markdown view.
  • Preserve correct match highlighting and index advancement across read-only, editing, and live-preview workflows.

Tests:

  • Add regression coverage for renderer highlight updates on click-first searches and subsequent match navigation.
  • Expand editor-wrapper scenarios to cover Enter-versus-click parity and Live Preview/read-only view transitions, including stale layout geometry.

1. Root cause: clicking next/prev as the first find action of a session
   never registers the keyword (m_keywordForSearchAll stays empty), so
   Window::handleFindKeyword took the clear branch and never pushed
   highlightSearch to the rendered MarkdownView - the match scrolled
   into view but carried no highlight; pressing Enter first registers
   the keyword, which is why "Enter then click" works but "click first"
   loses the highlight (verified on the Qt 6.8.0 build of BUG-380705)
2. Fix: handleFindKeyword now registers the current keyword and always
   calls highlightKeywordInView, matching the Enter path
   (handleUpdateSearchKeyword)
3. Test: Window UT asserts click-first pushes highlightSearch to the
   injected renderer with the right keyword and advancing match index;
   EditWrapper UT adds Enter/click path-parity and LivePreview-then-
   ReadView flow scenarios for the scroll sync regression

Log: fix find highlight missing when clicking next before enter

Influence:
1. In read-only markdown view, press Ctrl+F and click Next directly
   without pressing Enter, verify the match is highlighted and centered
2. Test the same flow in edit mode and live preview, verify no regression
3. Verify render-page highlight follows subsequent next/prev clicks

fix: 修复直接点击"下一个"时渲染页无查找高亮

1. 根因:会话内首个查找动作若直接点击"下一个/上一个"(未经回车路径
   注册查找词),m_keywordForSearchAll为空使handleFindKeyword走清空
   分支,渲染页收不到highlightSearch推送——匹配滚入视口却无任何高亮;
   回车路径会注册查找词,故"先回车再点击"正常、"直接点击"丢高亮
   (在BUG-380705修复版 Qt 6.8.0 构建上实测确认)
2. 方案:handleFindKeyword注册当前查找词并无条件调用
   highlightKeywordInView,与回车路径行为对齐
3. 测试:Window单测断言点击先行也会向注入渲染器推送highlightSearch
   且命中序号随点击推进;EditWrapper单测补充回车/点击路径一致性与
   LivePreview进只读视图流程的滚动同步回归场景

Log: 修复只读Markdown视图下直接点击"下一个"渲染页无高亮的问题

Influence:
1. 在只读Markdown视图下Ctrl+F后不按回车、直接点击"下一个",验证匹配
   内容带高亮且居中显示
2. 在编辑模式与实时预览下验证相同流程无回归
3. 验证渲染页高亮随后续点击"下一个/上一个"同步刷新

PMS: BUG-380705
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 hours and 24 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[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.

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

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes first-click find navigation so the active keyword is registered and rendered Markdown highlighting is pushed immediately, then adds unit and integration coverage for click-first behavior, match advancement, search-path parity, and ReadView transition scenarios.

Sequence diagram for click-first find highlighting

sequenceDiagram
    actor User
    participant Window
    participant TextEditor
    participant MarkdownView

    User->>Window: handleFindKeyword(keyword, state)
    Window->>TextEditor: updateCursorKeywordSelection(keyword, state)
    Window->>Window: register m_keywordForSearchAll
    Window->>TextEditor: highlightKeywordInView(keyword)
    TextEditor->>MarkdownView: highlightSearch(keyword)
    Window->>TextEditor: markAllKeywordInView()
    MarkdownView-->>User: Render match highlighted and centered
Loading

File-Level Changes

Change Details Files
Registers the active search keyword on the first Next/Previous action and always synchronizes renderer-side search highlighting.
  • Replaces the previous clear-on-keyword-mismatch branch with keyword registration.
  • Always invokes highlightKeywordInView so rendered Markdown receives the current keyword and match highlight.
  • Preserves subsequent match navigation and existing mark-all/render update flow.
src/widgets/window.cpp
Adds renderer-observable regression coverage for click-first highlighting and match progression.
  • Adds a recording Markdown renderer stub to capture highlightSearch calls.
  • Verifies a first direct Next action registers the keyword, sends the correct keyword and first match index, and advances on the next click.
  • Updates the prior state expectation to reflect keyword registration rather than clearing.
tests/widgets_ut/test_window.cpp
Expands EditWrapper integration coverage across search entry paths and view-transition layouts.
  • Records renderer scroll history and refactors scenario setup to model direct, Enter, and click paths.
  • Adds parity coverage for Enter and click flows, including LivePreview-to-ReadView and maximize-after-ReadView transitions.
  • Processes queued UI events before asserting renderer synchronization and near-match scrolling.
tests/editor_wrapper/test_editwrapper.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复 BUG-380705,解决在会话内首次点击"下一个/上一个"查找按钮时(未经回车路径注册查找词), 渲染页(MarkdownView)收不到 highlightSearch 推送导致只读视图下命中处无高亮的问题。修复方案将点击路径 的行为与回车路径对齐:查找词变更时注册当前词而非清空,并始终调用 highlightKeywordInView 推送高亮。 四维度分析均无问题,OCR 审查与启发式扫描均无发现,测试覆盖充分。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前修复已正确,无需额外修改。核心修复片段如下(window.cpp handleFindKeyword): // // if (QString::compare(m_keywordForSearch, m_keywordForSearchAll, //                      Qt::CaseInsensitive) != 0) { //     qCDebug(appLog) << "m_keywordForSearchAll is not equal to m_keywordForSearch, register current keyword"; //     m_keywordForSearchAll = m_keywordForSearch; // } // wrapper->textEditor()->highlightKeywordInView(m_keywordForSearchAll);

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

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.

2 participants