Skip to content

fix(reader): align search result content with count text - #431

Open
GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:fix/193245-align-search-result
Open

GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:fix/193245-align-search-result

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

In reader/sidebar/SearchResDelegate.cpp, the paint() method draws search count text with a right boundary at option.rect.right() - 20 (line 81), but the search content text (drawPageContenttext) uses option.rect.right() as its right boundary (line 97), and the bottom separator line also extends to option.rect.right() (line 106). This 20px discrepancy causes the search result count text and content text to appear misaligned — the count text has a 20px right margin while the content text extends to the edge.

Fix Approach

Adjust the content text width calculation and bottom line endpoint to use option.rect.right() - 20, matching the search count text's right boundary. Two lines changed in SearchResDelegate.cpp:

  1. contentSize width: option.rect.right() - textStartX → option.rect.right() - textStartX - 20
  2. drawBottomLine endpoint: option.rect.right() → option.rect.right() - 20

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target code is original UI layout implementation (commit 3412dad, 2020-11-18), not a previous bug fix product — this change does not revert any historical fix
  • No external callers depend on the modified drawing coordinates (reference_count = 0); changes are internal to paint() method

Business Impact Scope

Affects the search results sidebar in the document reader. The search result list items' content text and bottom separator line will now align with the search count text's right boundary. Users will see properly right-aligned search result content.

Verification Suggestion

Verify search result count text, content text, and bottom separator line are all right-aligned in the sidebar search results list. Test with various window widths.


根因分析

在 reader/sidebar/SearchResDelegate.cpp 的 paint() 方法中,搜索数量文字的右边界为 option.rect.right() - 20(第 81 行),而搜索内容文字(drawPageContenttext)的右边界为 option.rect.right()(第 97 行),底部分割线终点也是 option.rect.right()(第 106 行)。这 20px 的差异导致搜索结果数量文字和内容文字未居右对齐。

修复方案

将内容文字宽度计算和底线终点的右边界统一调整为 option.rect.right() - 20,与搜索数量文字的右边界一致。SearchResDelegate.cpp 改动两处:

  1. contentSize 宽度:option.rect.right() - textStartX → option.rect.right() - textStartX - 20
  2. drawBottomLine 终点:option.rect.right() → option.rect.right() - 20

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标代码为初始 UI 布局实现(commit 3412dad, 2020-11-18),非历史 bug 修复产物——本次改动不撤销任何已有修复
  • 无外部调用者依赖被改的绘制坐标(reference_count = 0),改动仅限于 paint() 方法内部

业务影响范围

影响文档查看器的搜索结果侧边栏。搜索结果列表项的内容文字和底部分割线将与搜索数量文字的右边界对齐。用户将看到正确右对齐的搜索结果内容。

验证建议

验证侧边栏搜索结果列表中搜索数量文字、内容文字和底部分割线右边界对齐。测试不同窗口宽度下的效果。

Summary by Sourcery

Align reader search result content and separators with the search count boundary.

Bug Fixes:

  • Align search result content text and separator lines with the search count text in the reader sidebar by applying the same right margin.

Chores:

  • Update the SPDX copyright year range for the search result delegate.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

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 27, 2026

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

Reviewer's Guide

This low-risk UI layout fix updates the search result delegate’s paint calculations so content text, count text, and the bottom separator share the same right boundary, improving alignment across sidebar widths.

Flow diagram for aligned search result rendering

flowchart LR
    A["SearchResDelegate.paint"] --> B["Draw count text to option.rect.right() - 20"]
    A --> C["Draw content text within contentSize.width"]
    A --> D["Draw bottom separator to option.rect.right() - 20"]
    B --> E["Shared right boundary"]
    C --> E
    D --> E
Loading

File-Level Changes

Change Details Files
Align search-result content sizing and the separator line with the count text’s 20px right inset.
  • Reduce the content text width by 20px before elision and drawing.
  • End the bottom separator 20px before the item’s right edge.
reader/sidebar/SearchResDelegate.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 ✨

1. drawPageContenttext used option.rect.right() as right boundary while
   drawSearchCount used option.rect.right() - 20, causing a 20px misalignment
2. Adjust contentSize width to use option.rect.right() - textStartX - 20
3. Adjust drawBottomLine endpoint to use option.rect.right() - 20
4. Update SPDX-FileCopyrightText year from 2023 to 2023-2026

Log: Search result content text now right-aligns with search count text in sidebar

Influence:
1. Verify search result count text and content text are right-aligned
2. Verify bottom separator line length matches content text width
3. Test with different window widths and search result counts

fix(reader): 搜索结果内容文字与数量文字右对齐

1. drawPageContenttext 使用 option.rect.right() 作为右边界,而 drawSearchCount
   使用 option.rect.right() - 20,导致两者相差 20px 未居右对齐
2. 将 contentSize 宽度调整为 option.rect.right() - textStartX - 20
3. 将 drawBottomLine 终点调整为 option.rect.right() - 20
4. 更新 SPDX-FileCopyrightText 版权年份从 2023 为 2023-2026

Log: 搜索结果内容文字与搜索数量文字在侧边栏中右对齐

Influence:
1. 验证搜索结果数量文字与内容文字右边界对齐
2. 验证底部分割线长度与内容文字宽度一致
3. 测试不同窗口宽度和搜索结果数量下的对齐效果

PMS: BUG-193245
@GongHeng2017
GongHeng2017 force-pushed the fix/193245-align-search-result branch from f091022 to 14536db Compare October 27, 2026 22:44
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了搜索结果内容与计数文本的对齐问题,通过在内容区域宽度和底部分隔线终点各缩减20像素实现右对齐。 变更范围小且聚焦,语法正确,逻辑一致,无安全漏洞。唯一建议是将魔法数字20提取为命名常量以提高可维护性。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: ['建议将魔法数字 20 提取为命名常量(如 const int rightMargin = 20;),与已有变量 margin、pagetextHeight 风格保持一致,提高可维护性。']


3. 代码性能 ✅

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

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

建议: ['将魔法数字20提取为命名常量 const int rightMargin = 20;,在 contentSize 计算和 drawLine 中统一引用,便于后续维护调整。']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 在 paint 方法开头添加命名常量
void SearchResDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    // ... 前置代码 ...
    const int rightMargin = 20;  // 右边距,与计数文本对齐

    // 内容区域宽度计算
    QSize contentSize(option.rect.right() - textStartX - rightMargin,
                      option.rect.height() - pagetextHeight - 2 * margin);
    const QString &elidedContentText = Utils::getElidedText(
        painter->fontMetrics(), contentSize, contentText, contentOption.alignment());
    painter->drawText(QRect(textStartX, option.rect.y() + margin + pagetextHeight,
                            contentSize.width(), contentSize.height()),
                      elidedContentText, contentOption);
    painter->restore();

    // 底部分隔线
    painter->save();
    int bottomlineHeight = 1;
    painter->setPen(QPen(DTK_NAMESPACE::Gui::DGuiApplicationHelper::instance()
                         ->applicationPalette().frameBorder().color(), bottomlineHeight));
    painter->drawLine(textStartX, option.rect.bottom() - bottomlineHeight,
                      option.rect.right() - rightMargin,
                      option.rect.bottom() - bottomlineHeight);
    painter->restore();
}

本报告由 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