Skip to content

fix(vnote): keep ctrl multi-selection count in sync#406

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:bug-fix-7-10
Jul 13, 2026
Merged

fix(vnote): keep ctrl multi-selection count in sync#406
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:bug-fix-7-10

Conversation

@dengzhongyuan365-dev

@dengzhongyuan365-dev dengzhongyuan365-dev commented Jul 13, 2026

Copy link
Copy Markdown
Member

Update selected note indexes before selectSize on Ctrl+click so onSelectSizeChanged reads the latest selection and multi-choice count matches highlighted items.

Ctrl+点击多选时先更新 selectedNoteItem,再同步 selectSize,
避免 onSelectSizeChanged 读取旧选中状态导致右侧统计数量错误。

Log: 修复Ctrl多选笔记后右侧统计数量与实际选中数量不一致
PMS: BUG-369995
Influence: Ctrl多选和取消选中时,左侧列表选中状态与右侧多选统计保持一致。

Summary by Sourcery

Bug Fixes:

  • Fix mismatch between the right-side multi-selection count and the actual notes selected when using Ctrl to add or remove selections.

Update selected note indexes before selectSize on Ctrl+click so
onSelectSizeChanged reads the latest selection and multi-choice
count matches highlighted items.

Ctrl+点击多选时先更新 selectedNoteItem,再同步 selectSize,
避免 onSelectSizeChanged 读取旧选中状态导致右侧统计数量错误。

Log: 修复Ctrl多选笔记后右侧统计数量与实际选中数量不一致
PMS: BUG-369995
Influence: Ctrl多选和取消选中时,左侧列表选中状态与右侧多选统计保持一致。
@sourcery-ai

sourcery-ai Bot commented Jul 13, 2026

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

Reviewer's Guide

Synchronizes the multi-selection count with the actual selected notes when using Ctrl+click in the note list, ensuring the right-side multi-select statistics stay consistent with the highlighted items.

Sequence diagram for Ctrl+click multi-selection count sync

sequenceDiagram
    actor User
    participant ItemListView
    participant validSelectedNoteIndexes
    participant StatsPanel

    User->>ItemListView: Ctrl_click(index)
    ItemListView->>ItemListView: selectedNoteItem.slice()
    ItemListView->>ItemListView: splice_or_push_index
    ItemListView->>validSelectedNoteIndexes: validSelectedNoteIndexes()
    validSelectedNoteIndexes-->>ItemListView: selectedIndexes
    ItemListView->>ItemListView: selectSize = selectedIndexes.length
    ItemListView->>StatsPanel: onSelectSizeChanged(selectSize)
Loading

File-Level Changes

Change Details Files
Ensure Ctrl+click multi-selection count is derived from the actual selected note indexes rather than manually incrementing or decrementing.
  • Refactor Ctrl+click branch to remove direct increment/decrement of the selection count.
  • Update the selected note list first when toggling items with Ctrl+click.
  • Recompute the selection size using validSelectedNoteIndexes() after updating the selected items so onSelectSizeChanged sees the correct count.
src/gui/mainwindow/ItemListView.qml

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 left some high level feedback:

  • Now that selectSize is derived from validSelectedNoteIndexes().length, consider removing any other code paths that manually increment/decrement selectSize so it is consistently treated as a derived value from the selected indexes.
  • If validSelectedNoteIndexes() is non-trivial, you might want to cache or centralize the selection update logic so that recalculating selectSize on every Ctrl-click does not duplicate work or introduce subtle inconsistencies elsewhere.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that `selectSize` is derived from `validSelectedNoteIndexes().length`, consider removing any other code paths that manually increment/decrement `selectSize` so it is consistently treated as a derived value from the selected indexes.
- If `validSelectedNoteIndexes()` is non-trivial, you might want to cache or centralize the selection update logic so that recalculating `selectSize` on every Ctrl-click does not duplicate work or introduce subtle inconsistencies elsewhere.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了多选状态下计数器与实际选中项不同步的问题,逻辑正确且简化了状态管理。
移除手动维护计数的冗余逻辑,改为通过函数动态计算,代码质量优秀且无安全风险。

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

src/gui/mainwindow/ItemListView.qmlQt.ControlModifier 分支中,移除了手动 selectSize--selectSize++ 的逻辑,改为通过 validSelectedNoteIndexes().length 统一计算。这消除了原先因外部修改或无效索引导致的状态不同步问题,逻辑完全正确。
潜在问题:无
建议:无需修改

  • 2.代码质量(优秀)✓

移除了 if/else 语句中不必要的花括号,使代码更加简洁。同时,使用单一函数调用替代分散的状态维护,降低了代码的圈复杂度,提升了可维护性。
潜在问题:无
建议:无需修改

  • 3.代码性能(无性能问题)✓

多选操作属于用户交互级别的低频事件,每次点击调用 validSelectedNoteIndexes().length 计算选中数量带来的性能开销极小,不会对界面响应造成影响。
潜在问题:无
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改仅涉及前端界面多选状态管理逻辑的调整,不涉及任何外部输入解析、网络请求或系统命令调用,不存在安全攻击面。

  • 建议:无需安全修复

■ 【改进建议代码示例】

// 当前代码已修复原有逻辑缺陷,无需进一步修改。保持现有实现即可。
case Qt.ControlModifier:
    var nextSelection = selectedNoteItem.slice();
    var pos = nextSelection.indexOf(index);
    if (pos != -1)
        nextSelection.splice(pos, 1);
    else
        nextSelection.push(index);
    selectedNoteItem = nextSelection;
    selectSize = validSelectedNoteIndexes().length;
    break;

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

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

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 933fdc3 into linuxdeepin:develop/snipe Jul 13, 2026
23 checks passed
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