Skip to content

fix: Fixed issue where the focus did not start from the current page when entering the secondary interface#3005

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
pengfeixx:fix-311355
Feb 5, 2026
Merged

fix: Fixed issue where the focus did not start from the current page when entering the secondary interface#3005
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
pengfeixx:fix-311355

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Feb 5, 2026

Fixed issue where the focus did not start from the current page when entering the secondary interface

Log: Fixed issue where the focus did not start from the current page when entering the secondary interface
pms: BUG-311355

Summary by Sourcery

Adjust focus behavior when entering secondary pages so the right view focus can be optionally skipped for specific pages.

Bug Fixes:

  • Ensure the right-side content view does not steal focus when entering secondary pages where the current page should retain focus, such as the system page.

Enhancements:

  • Introduce a skipRightViewFocus property on DccApp and use it to control whether the right view auto-focuses on load.
  • Update focus policies in DccRightView and DccItem to improve keyboard focus handling when navigating between pages.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 5, 2026

Reviewer's Guide

Introduces a new DccApp flag and QML focus handling changes so that when entering the secondary interface, keyboard focus starts at the correct page instead of the first right‑panel item, with a special case for the system page.

Sequence diagram for secondary interface focus handling

sequenceDiagram
    actor User
    participant SecondPage
    participant DccApp
    participant DccRightView
    participant DccItem

    User->>SecondPage: navigateToSecondaryInterface(activeObj)
    SecondPage->>SecondPage: ensure activeObj.page
    SecondPage->>DccApp: setSkipRightViewFocus(activeObj.name == system)
    DccApp-->>SecondPage: skipRightViewFocusChanged(skip)
    SecondPage->>DccRightView: rightView.replace(mainView, dccObj, animationMode)

    activate DccRightView
    DccRightView->>DccRightView: Component.onCompleted
    DccRightView->>DccRightView: showScrollBarTimer.start()
    DccRightView->>DccApp: read skipRightViewFocus

    alt skipRightViewFocus is false
        DccRightView->>DccRightView: control.forceActiveFocus()
        DccRightView-->>User: keyboard focus on rightView root
        DccRightView->>DccItem: item receives focus via navigation
    else skipRightViewFocus is true (system page)
        DccRightView-->>User: focus remains on current page context
    end
Loading

Updated class diagram for DccApp focus management flag

classDiagram
    class DccApp {
        +QVector~DccObject*~ currentObjects
        +QVector~DccObject*~ triggeredObjects
        +AnimationMode m_animationMode
        +bool m_skipRightViewFocus
        +int width()
        +int height()
        +int sidebarWidth()
        +void setSidebarWidth(int width)
        +AnimationMode animationMode()
        +void setAnimationMode(AnimationMode mode)
        +bool skipRightViewFocus()
        +void setSkipRightViewFocus(bool skip)
        +void currentObjectsChanged(QVector~DccObject*~ currentObjects)
        +void triggeredObjectsChanged(QVector~DccObject*~ triggeredObjects)
        +void activeItemChanged(QQuickItem* item)
        +void animationModeChanged(AnimationMode mode)
        +void skipRightViewFocusChanged(bool skipRightViewFocus)
    }

    class DccObject
    class QQuickItem

    DccApp --> DccObject : uses
    DccApp --> QQuickItem : activeItemChanged parameter
Loading

File-Level Changes

Change Details Files
Add a DccApp property to control whether the right view should grab initial focus.
  • Declare a new Q_PROPERTY skipRightViewFocus with getter, setter, and change signal on DccApp.
  • Implement setSkipRightViewFocus to update the internal flag and emit skipRightViewFocusChanged when the value changes.
  • Add a private bool m_skipRightViewFocus member with default false.
src/dde-control-center/plugin/dccapp.h
src/dde-control-center/plugin/dccapp.cpp
Adjust QML focus behavior of the right-side view and its items so that focus starts appropriately when opening the secondary page.
  • Enable activeFocusOnTab on DccRightView and, on Component.onCompleted, forceActiveFocus on the control only when DccApp.skipRightViewFocus is false.
  • Disable activeFocusOnTab on individual DccItem delegates so they no longer automatically take focus via tab navigation.
  • When activating a second-page object in SecondPage.qml, set DccApp.skipRightViewFocus based on whether the active object is the "system" page so that this page can manage focus differently.
src/dde-control-center/plugin/DccRightView.qml
src/dde-control-center/plugin/DccItem.qml
src/dde-control-center/plugin/SecondPage.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 - I've left some high level feedback:

  • The Component.onCompleted block in DccRightView.qml only checks DccApp.skipRightViewFocus once on creation; if this flag changes later (e.g. when switching between different secondary pages), the focus behavior will not update—consider reacting to skipRightViewFocusChanged or binding focus logic to the property instead of a one-shot check.
  • Using the literal string "system" in SecondPage.qml to decide whether to skip right view focus makes the behavior fragile; consider basing this on a typed property/flag of activeObj or a central enum-like definition instead of a magic string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `Component.onCompleted` block in `DccRightView.qml` only checks `DccApp.skipRightViewFocus` once on creation; if this flag changes later (e.g. when switching between different secondary pages), the focus behavior will not update—consider reacting to `skipRightViewFocusChanged` or binding focus logic to the property instead of a one-shot check.
- Using the literal string `"system"` in `SecondPage.qml` to decide whether to skip right view focus makes the behavior fragile; consider basing this on a typed property/flag of `activeObj` or a central enum-like definition instead of a magic string.

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.

if (activeObj.page === null) {
activeObj.page = rightLayout
}
DccApp.skipRightViewFocus = (activeObj.name === "system")
Copy link
Contributor

Choose a reason for hiding this comment

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

如果tab点了个性化,再点回系统,岂不是系统的一级页面的焦点就不会自动跳转了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果tab点了个性化,再点回系统,岂不是系统的一级页面的焦点就不会自动跳转了

是的,系统界面的焦点从主窗口开始,其他的界面焦点从右侧区域开始

…when entering the secondary interface

Fixed issue where the focus did not start from the current page when entering the secondary interface

Log: Fixed issue where the focus did not start from the current page when entering the secondary interface
pms: BUG-311355
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码变更主要涉及两个QML文件的修改,主要目的是调整焦点管理行为。以下是针对语法逻辑、代码质量、代码性能和代码安全的详细审查意见:

1. 语法逻辑

DccItem.qml 修改:

- activeFocusOnTab: true
+ activeFocusOnTab: false
  • 分析: 将 activeFocusOnTabtrue 改为 false,意味着该控件不再响应 Tab 键的焦点切换。
  • 问题: 如果 DccItem 是列表项,禁用 Tab 键焦点可能导致用户无法通过键盘导航到这些项,影响可访问性(Accessibility)。
  • 建议: 确保禁用 Tab 焦点后,用户仍能通过其他方式(如方向键)导航到这些项。如果这是设计意图,建议添加注释说明原因。

SecondPage.qml 修改:

+ if (activeObj.name !== "system") {
+     list.forceActiveFocus()
+ }
  • 分析: 在切换页面后,如果当前对象不是 "system",则强制 list 获取焦点。
  • 问题:
    • forceActiveFocus() 是一个强制操作,可能会干扰用户的焦点预期。
    • 条件判断仅基于 activeObj.name !== "system",逻辑较为单一。如果未来有其他特殊对象需要类似处理,可能需要扩展条件。
  • 建议:
    • 考虑使用更明确的焦点管理策略,例如基于对象类型或属性而非名称字符串。
    • 添加注释说明为何 "system" 对象需要特殊处理。

2. 代码质量

  • 命名和注释:
    • activeObj.name 使用字符串比较,容易出错(如拼写错误或未来名称变更)。建议使用枚举或常量代替硬编码字符串。
    • 缺少注释说明修改意图,建议添加注释解释为何禁用 Tab 焦点或强制焦点。
  • 可维护性:
    • 如果 activeObj.name 的判断逻辑可能变化,建议提取为独立函数或属性,便于维护。

3. 代码性能

  • 焦点操作:
    • forceActiveFocus() 可能会触发额外的布局或渲染操作,频繁调用可能影响性能。但在此场景中(页面切换时调用一次)影响较小。
    • 禁用 activeFocusOnTab 可能减少焦点计算开销,但影响微乎其微。

4. 代码安全

  • 焦点劫持风险:
    • forceActiveFocus() 可能被视为焦点劫持行为,尤其是在用户未预期的情况下。建议确保这是用户友好的行为(例如明确用户操作后)。
  • 硬编码字符串:
    • activeObj.name !== "system" 依赖字符串比较,如果 name 属性可能被外部修改,可能存在安全风险(如注入攻击)。建议验证输入或使用更安全的比较方式。

综合改进建议

  1. DccItem.qml:

    • 如果禁用 Tab 焦点是必要的,建议添加注释说明原因:
      // 禁用 Tab 焦点以支持自定义键盘导航逻辑
      activeFocusOnTab: false
  2. SecondPage.qml:

    • 避免硬编码字符串,改用更安全的比较方式:
      // 非 system 对象需要强制焦点到列表
      if (activeObj.name !== DccConstants.SystemObjectName) {
          list.forceActiveFocus()
      }
    • 或提取为独立属性/函数:
      property bool shouldFocusList: activeObj.name !== "system"
      
      if (shouldFocusList) {
          list.forceActiveFocus()
      }
  3. 可访问性:

    • 确保键盘导航逻辑完整,避免用户无法通过键盘操作某些控件。建议测试键盘导航流程。

总结

这段代码的修改主要是调整焦点管理逻辑,但存在以下潜在问题:

  1. 禁用 Tab 焦点可能影响可访问性。
  2. 强制焦点操作可能干扰用户体验。
  3. 硬编码字符串比较不够健壮。

建议添加注释、优化条件判断逻辑,并确保键盘导航的完整性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@pengfeixx
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Feb 5, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 8f00ec9 into linuxdeepin:master Feb 5, 2026
16 of 18 checks passed
@pengfeixx pengfeixx deleted the fix-311355 branch February 5, 2026 06:28
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.

4 participants