Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Oct 27, 2025

  1. Add logic to automatically set ListView currentIndex to the first notification item when expanding an app group
  2. This improves keyboard navigation by moving focus to the newly expanded content
  3. Calculate the correct index by adding 1 to the expanded app index
  4. Only apply the focus change when the root view is available

feat: 设置焦点到新展开的首条通知项

  1. 添加逻辑在展开应用组时自动将 ListView 当前索引设置到第一条通知项
  2. 通过将焦点移动到新展开的内容来改进键盘导航体验
  3. 通过展开应用索引加1计算正确的索引位置
  4. 仅在根视图可用时应用焦点更改

PMS: BUG-284987

Summary by Sourcery

Set ListView.currentIndex to the first item of an expanded notification group when the root view is available to streamline keyboard navigation after expanding an app group

New Features:

  • Automatically set focus to the first notification item when expanding an app group

Enhancements:

  • Improve keyboard navigation by moving focus to newly expanded notifications

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 27, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Automatically move focus to the first expanded notification item by computing its index and updating ListView’s currentIndex when an app group is expanded.

Sequence diagram for expanding an app group and setting focus to first notification item

sequenceDiagram
    participant User as actor User
    participant "AppGroupDelegate"
    participant "notifyModel"
    participant "root.view (ListView)"
    User->>"AppGroupDelegate": Expand app group
    "AppGroupDelegate"->>"notifyModel": expandApp(expandIndex)
    alt root.view is available
        "AppGroupDelegate"->>"root.view (ListView)": Set currentIndex = expandIndex + 1
    end
Loading

File-Level Changes

Change Details Files
Automatically set focus to the first notification item upon expanding an app group
  • Introduce expandIndex variable to capture model.index
  • Invoke notifyModel.expandApp using expandIndex
  • Check for root.view existence before modifying focus
  • Calculate firstExpandedIndex as expandIndex + 1 and assign to root.view.currentIndex
panels/notification/center/NotifyViewDelegate.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `panels/notification/center/NotifyViewDelegate.qml:169-172` </location>
<code_context>
+                notifyModel.expandApp(expandIndex)
+                // 设置ListView的currentIndex到新展开的首条通知项 (将焦点设置到新展开的通知的第一项)
+                if (root.view) {
+                    let firstExpandedIndex = expandIndex + 1
+                    root.view.currentIndex = firstExpandedIndex
+                }
             }
</code_context>

<issue_to_address>
**suggestion:** Consider edge cases where expandIndex + 1 may exceed the model bounds.

Ensure firstExpandedIndex does not exceed the model's length before assigning it to root.view.currentIndex to prevent out-of-bounds errors.

```suggestion
                if (root.view) {
                    let firstExpandedIndex = expandIndex + 1
                    if (firstExpandedIndex < notifyModel.count) {
                        root.view.currentIndex = firstExpandedIndex
                    }
                }
```
</issue_to_address>

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.

Comment on lines 169 to 182
if (root.view) {
let firstExpandedIndex = expandIndex + 1
root.view.currentIndex = firstExpandedIndex
}
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider edge cases where expandIndex + 1 may exceed the model bounds.

Ensure firstExpandedIndex does not exceed the model's length before assigning it to root.view.currentIndex to prevent out-of-bounds errors.

Suggested change
if (root.view) {
let firstExpandedIndex = expandIndex + 1
root.view.currentIndex = firstExpandedIndex
}
if (root.view) {
let firstExpandedIndex = expandIndex + 1
if (firstExpandedIndex < notifyModel.count) {
root.view.currentIndex = firstExpandedIndex
}
}

{
console.log("expand")
notifyModel.expandApp(model.index)
let expandIndex = model.index
Copy link
Contributor

Choose a reason for hiding this comment

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

这个需不需要弄一个全局nextIndex的呀,我看展开,折叠,删除,都可能会需要currentIndex指向正确的index,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

似乎不需要,他折叠和删除,默认listview的焦点行为会给到下一个,焦点不会乱跳

Copy link
Contributor

Choose a reason for hiding this comment

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

会乱跑吧,你删除一个中间的试试,

@wjyrich wjyrich force-pushed the fix-bug-284987-2 branch 2 times, most recently from 33af38e to ce6eac8 Compare October 28, 2025 03:41
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

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

1. Add logic to automatically set ListView currentIndex to the first
notification item when expanding an app group
2. This improves keyboard navigation by moving focus to the newly
expanded content
3. Calculate the correct index by adding 1 to the expanded app index
4. Only apply the focus change when the root view is available

feat: 设置焦点到新展开的首条通知项

1. 添加逻辑在展开应用组时自动将 ListView 当前索引设置到第一条通知项
2. 通过将焦点移动到新展开的内容来改进键盘导航体验
3. 通过展开应用索引加1计算正确的索引位置
4. 仅在根视图可用时应用焦点更改
5.修复了删除后,焦点给到下一项
PMS: BUG-284987
@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你审查这段代码的修改。主要改动涉及通知列表项的删除和展开操作时的索引处理。让我从几个方面分析:

  1. 语法逻辑:
  • 代码语法正确,符合QML语法规范
  • 使用了let声明局部变量,符合现代JavaScript语法
  • 逻辑流程清晰,通过nextIndex属性来控制列表项的选中状态
  1. 代码质量:
  • 增加了索引保存的逻辑,提高了用户体验
  • 使用Math.min确保不会越界,处理了边界情况
  • 但代码存在一些可以优化的地方
  1. 代码性能:
  • 每次删除/展开操作都会触发视图更新,可能影响性能
  • 可以考虑批量处理多个操作
  1. 代码安全:
  • 对索引进行了边界检查,防止越界
  • 但没有对model.id的有效性进行检查

改进建议:

  1. 在NotifyView.qml中:
property int nextIndex: -1

onNextIndexChanged: {
    if (nextIndex >= 0 && count > 0) {
        // 确保nextIndex在有效范围内
        currentIndex = Math.min(nextIndex, count - 1)
    }
}
  1. 在NotifyViewDelegate.qml中:
onRemove: function () {
    console.log("remove normal", model.id)
    if (!model.id) return  // 添加id有效性检查
    
    let removeIndex = index
    notifyModel.remove(model.id)
    // 确保删除后选中项的合理性
    root.view.nextIndex = removeIndex >= root.view.count ? removeIndex - 1 : removeIndex
}

onDismiss: function () {
    console.log("dismiss normal", model.id)
    if (!model.id) return  // 添加id有效性检查
    
    let dismissIndex = index
    notifyModel.remove(model.id)
    // 确保删除后选中项的合理性
    root.view.nextIndex = dismissIndex >= root.view.count ? dismissIndex - 1 : dismissIndex
}

onExpand: function () {
    console.log("expand")
    if (!model.index && model.index !== 0) return  // 添加index有效性检查
    
    let expandIndex = model.index
    notifyModel.expandApp(expandIndex)
    // 确保展开后的索引在有效范围内
    root.view.nextIndex = Math.min(expandIndex + 1, root.view.count - 1)
}

主要改进点:

  1. 添加了更多的边界检查和有效性验证
  2. 优化了索引计算逻辑,使其更加健壮
  3. 在NotifyView中也添加了边界检查
  4. 改进了删除后的索引选择逻辑,使其更加合理
  5. 添加了更多的防御性编程措施

这些改进可以使代码更加健壮,提高用户体验,并减少潜在的bug。

@wjyrich wjyrich merged commit 71c0b3b into linuxdeepin:master Oct 28, 2025
10 of 11 checks passed
@wjyrich wjyrich deleted the fix-bug-284987-2 branch October 28, 2025 05:07
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