Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Feb 2, 2026

  1. Added scrolledByWheel property to track mouse wheel page navigation
  2. Modified focus behavior to always focus first app when scrolling with wheel
  3. Fixed inconsistent focus positioning after wheel vs keyboard navigation
  4. Reset scrolledByWheel flag after processing to prevent stale state

Log: Improved application focus behavior when using mouse wheel to navigate pages in fullscreen mode

Influence:

  1. Test mouse wheel page navigation in fullscreen mode
  2. Verify focus correctly moves to first application after wheel scrolling
  3. Compare focus behavior between wheel scrolling and keyboard navigation
  4. Test edge cases like scrolling from first to last page and vice versa
  5. Verify focus is not lost when switching between different navigation methods

fix: 修复全屏模式下滚轮滚动时的焦点管理问题

  1. 添加 scrolledByWheel 属性来跟踪鼠标滚轮翻页操作
  2. 修改焦点行为,滚轮翻页时始终聚焦到第一个应用
  3. 修复滚轮导航和键盘导航后焦点位置不一致的问题
  4. 处理完成后重置 scrolledByWheel 标志,防止状态残留

Log: 改进了全屏模式下使用鼠标滚轮翻页时的应用焦点行为

Influence:

  1. 测试全屏模式下的鼠标滚轮翻页功能
  2. 验证滚轮翻页后焦点是否正确移动到第一个应用
  3. 比较滚轮滚动和键盘导航的焦点行为差异
  4. 测试边缘情况,如从第一页滚动到最后一页及反向操作
  5. 验证在不同导航方法切换时焦点不会丢失

PMS: BUG-337493

Summary by Sourcery

Improve focus management when navigating fullscreen pages with the mouse wheel so focus behavior matches keyboard navigation and remains consistent.

Bug Fixes:

  • Ensure wheel-based page flips in fullscreen always reset focus to the main app area instead of leaving inconsistent focus states.
  • Fix previous-page tracking logic so wheel and keyboard navigation result in consistent focus positioning across pages.
  • Prevent stale wheel-scroll state from affecting subsequent navigation by resetting the tracking flag after page changes.

1. Added scrolledByWheel property to track mouse wheel page navigation
2. Modified focus behavior to always focus first app when scrolling
with wheel
3. Fixed inconsistent focus positioning after wheel vs keyboard
navigation
4. Reset scrolledByWheel flag after processing to prevent stale state

Log: Improved application focus behavior when using mouse wheel to
navigate pages in fullscreen mode

Influence:
1. Test mouse wheel page navigation in fullscreen mode
2. Verify focus correctly moves to first application after wheel
scrolling
3. Compare focus behavior between wheel scrolling and keyboard
navigation
4. Test edge cases like scrolling from first to last page and vice versa
5. Verify focus is not lost when switching between different navigation
methods

fix: 修复全屏模式下滚轮滚动时的焦点管理问题

1. 添加 scrolledByWheel 属性来跟踪鼠标滚轮翻页操作
2. 修改焦点行为,滚轮翻页时始终聚焦到第一个应用
3. 修复滚轮导航和键盘导航后焦点位置不一致的问题
4. 处理完成后重置 scrolledByWheel 标志,防止状态残留

Log: 改进了全屏模式下使用鼠标滚轮翻页时的应用焦点行为

Influence:
1. 测试全屏模式下的鼠标滚轮翻页功能
2. 验证滚轮翻页后焦点是否正确移动到第一个应用
3. 比较滚轮滚动和键盘导航的焦点行为差异
4. 测试边缘情况,如从第一页滚动到最后一页及反向操作
5. 验证在不同导航方法切换时焦点不会丢失

PMS: BUG-337493
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要是在处理通过鼠标滚轮翻页时的焦点逻辑变更。以下是对这段代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的改进建议:

1. 语法逻辑

优点:

  • 逻辑清晰:通过引入 scrolledByWheel 标志位,能够明确区分滚轮翻页和普通翻页的行为差异。
  • 条件判断完整:在处理滚轮翻页时,正确地将焦点设置到第一个应用,并重置标志位。

改进建议:

  • 标志位生命周期管理scrolledByWheel 标志位在翻页时被设置为 true,但在 onCurrentIndexChanged 中被重置为 false。如果翻页操作没有触发 onCurrentIndexChanged(例如翻页失败或被阻止),标志位可能会一直保持 true,导致后续行为异常。建议在翻页操作完成后立即重置标志位,而不是依赖 onCurrentIndexChanged

2. 代码质量

优点:

  • 注释清晰:代码中添加了注释说明滚轮翻页的特殊处理逻辑,便于理解。
  • 变量命名合理:scrolledByWheel 名称直观地表达了其用途。

改进建议:

  • 代码重复:在翻页逻辑中(toPage < 0toPage > 0 两个分支),scrolledByWheel 的设置和焦点处理逻辑是重复的。可以考虑提取为函数或使用更简洁的结构。
  • 魔法值previousIndex === 0currentIndex === count - 1 是硬编码的边界条件,建议定义为常量或添加注释说明其含义。

3. 代码性能

优点:

  • 性能影响较小:新增的 scrolledByWheel 标志位和条件判断对性能影响微乎其微。

改进建议:

  • 不必要的属性访问:在 onCurrentIndexChanged 中多次访问 listviewPage.currentIndexlistviewPage.previousIndex,可以缓存这些值以减少属性访问开销(虽然 QML 的属性访问已经优化过,但缓存仍然是一个好习惯)。

4. 代码安全

优点:

  • 无明显安全问题。

改进建议:

  • 标志位同步问题scrolledByWheel 是一个布尔标志位,如果多个异步操作(如快速滚轮滚动)同时修改它,可能会导致状态不一致。建议在设置标志位时考虑线程安全或使用状态机模式。

改进后的代码示例

// 定义常量
readonly property int FIRST_PAGE_INDEX: 0
readonly property int LAST_PAGE_INDEX: listviewPage.count - 1

// 翻页逻辑
if (toPage < 0) {
    flipPageDelay.start()
    if (!searchEdit.focus) {
        baseLayer.focus = true
    }
    handleWheelScroll(listviewPage, decrementPageIndex)
} else if (toPage > 0) {
    flipPageDelay.start()
    if (!searchEdit.focus) {
        baseLayer.focus = true
    }
    handleWheelScroll(listviewPage, incrementPageIndex)
}

// 提取的滚轮翻页处理函数
function handleWheelScroll(listview, pageChangeFunc) {
    listview.scrolledByWheel = true
    pageChangeFunc(listview)
    // 立即重置标志位,避免状态不一致
    listview.scrolledByWheel = false
}

// onCurrentIndexChanged 中的逻辑
onCurrentIndexChanged: {
    if (!listviewPage.visible) {
        listviewPage.previousIndex = listviewPage.currentIndex
        return
    }

    // 缓存属性值
    const currentIndex = listviewPage.currentIndex
    const previousIndex = listviewPage.previousIndex

    if (listviewPage.scrolledByWheel) {
        gridViewContainer.setPreviousPageSwitch(false)
        listviewPage.scrolledByWheel = false
    } else if (currentIndex + 1 === previousIndex || (previousIndex === FIRST_PAGE_INDEX && currentIndex === LAST_PAGE_INDEX)) {
        gridViewContainer.setPreviousPageSwitch(true)
    } else {
        gridViewContainer.setPreviousPageSwitch(false)
    }
}

总结

这段代码整体逻辑清晰,但可以通过减少代码重复、优化标志位生命周期管理和提取常量来提高代码质量和可维护性。性能和安全方面没有明显问题,但需要注意标志位的同步问题。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, 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

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 2, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts fullscreen page navigation so that mouse wheel scrolling explicitly flags the navigation mode and ensures focus and page-switch state are handled consistently, always focusing the first app after a wheel-initiated page flip and resetting transient state afterward.

Sequence diagram for fullscreen wheel vs keyboard page navigation focus handling

sequenceDiagram
    actor User
    participant InputEventItem
    participant listviewPage
    participant gridViewContainer

    rect rgb(230,230,255)
        User->>InputEventItem: wheelScroll(up or down)
        InputEventItem->>listviewPage: scrolledByWheel = true
        InputEventItem->>listviewPage: decrementPageIndex() or incrementPageIndex()
        listviewPage-->>listviewPage: currentIndex changed
        listviewPage->>gridViewContainer: setPreviousPageSwitch(false)
        listviewPage->>listviewPage: scrolledByWheel = false
    end

    rect rgb(230,255,230)
        User->>InputEventItem: keyboardNavigation
        InputEventItem->>listviewPage: decrementPageIndex() or incrementPageIndex()
        listviewPage-->>listviewPage: currentIndex changed
        listviewPage->>gridViewContainer: setPreviousPageSwitch(true or false based on indices)
    end
Loading

Class diagram for updated fullscreen listviewPage focus state

classDiagram
    class FullscreenFrame {
    }

    class InputEventItem {
        +handleWheelScroll()
        +decrementPageIndex(listviewPage)
        +incrementPageIndex(listviewPage)
    }

    class listviewPage {
        +int previousIndex
        +bool scrolledByWheel
        +int currentIndex
        +int count
        +onCurrentIndexChanged()
    }

    class gridViewContainer {
        +setPreviousPageSwitch(isPreviousSwitch bool)
    }

    FullscreenFrame *-- InputEventItem
    FullscreenFrame *-- listviewPage
    FullscreenFrame *-- gridViewContainer

    InputEventItem --> listviewPage : updatePageIndex
    listviewPage --> gridViewContainer : setPreviousPageSwitch
Loading

File-Level Changes

Change Details Files
Track when page navigation is triggered by mouse wheel scrolling and ensure focus is reset appropriately before changing pages.
  • Set a transient flag when mouse wheel input is used to flip pages up or down.
  • Preserve search field focus while re-focusing the base layer when flipping pages with the mouse.
qml/FullscreenFrame.qml
Add state to the page list to distinguish wheel-based navigation and adjust focus and previous-page-switch behavior accordingly.
  • Introduce a scrolledByWheel boolean property on the page list to record wheel-based navigation.
  • On page change completion, check scrolledByWheel and, if set, force previousPageSwitch to false so focus moves to the first app instead of preserving previous-page focus.
  • Reset scrolledByWheel to false after handling to avoid stale navigation mode affecting subsequent interactions.
qml/FullscreenFrame.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

@wjyrich wjyrich merged commit dde8f4c into linuxdeepin:master Feb 2, 2026
9 of 10 checks passed
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 - I've found 1 issue, and left some high level feedback:

  • Using a persistent scrolledByWheel flag on listviewPage to control the next currentIndex change makes the state a bit fragile; consider passing this context through the page flip function or via a dedicated signal/handler so the focus behavior is explicitly tied to a single navigation event instead of relying on a transient property that could be left true by future changes.
  • When scrolledByWheel is true you currently skip the previousIndex comparison logic entirely; if there are scenarios where wheel-triggered navigation should still respect the previous/next-page distinction, it may be clearer to factor the logic so the wheel-specific behavior (focus to first app) is applied in addition to, rather than instead of, the previousPageSwitch calculation where appropriate.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using a persistent `scrolledByWheel` flag on `listviewPage` to control the next `currentIndex` change makes the state a bit fragile; consider passing this context through the page flip function or via a dedicated signal/handler so the focus behavior is explicitly tied to a single navigation event instead of relying on a transient property that could be left true by future changes.
- When `scrolledByWheel` is true you currently skip the `previousIndex` comparison logic entirely; if there are scenarios where wheel-triggered navigation should still respect the previous/next-page distinction, it may be clearer to factor the logic so the wheel-specific behavior (focus to first app) is applied in addition to, rather than instead of, the `previousPageSwitch` calculation where appropriate.

## Individual Comments

### Comment 1
<location> `qml/FullscreenFrame.qml:434` </location>
<code_context>
                                 if (listviewPage.currentIndex === listviewPage.previousIndex) {
</code_context>

<issue_to_address>
**issue (bug_risk):** `scrolledByWheel` can remain stale when `currentIndex` doesn’t change, causing misclassification on the next index change.

In the early-return path where `currentIndex === previousIndex`, `scrolledByWheel` isn’t reset. If a wheel event sets `scrolledByWheel = true` but doesn’t change the index (e.g., trying to scroll past the first/last page), the flag leaks into the next index change and incorrectly marks it as wheel-driven. Please reset `listviewPage.scrolledByWheel` in this branch (or any short-circuit path) so the flag only applies to the wheel event that actually changes the index.
</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.

@@ -431,7 +434,11 @@ InputEventItem {
listviewPage.previousIndex = listviewPage.currentIndex
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): scrolledByWheel can remain stale when currentIndex doesn’t change, causing misclassification on the next index change.

In the early-return path where currentIndex === previousIndex, scrolledByWheel isn’t reset. If a wheel event sets scrolledByWheel = true but doesn’t change the index (e.g., trying to scroll past the first/last page), the flag leaks into the next index change and incorrectly marks it as wheel-driven. Please reset listviewPage.scrolledByWheel in this branch (or any short-circuit path) so the flag only applies to the wheel event that actually changes the index.

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