fix: Fix the issue where tab cannot select focus#2900
Conversation
Fix the issue where tab cannot select focus Log: Fix the issue where tab cannot select focus pms: BUG-311339
deepin pr auto review我来对这个git diff进行详细的代码审查:
Keys.onUpPressed: {
const prevItem = nextItemInFocusChain(false)
if (prevItem) prevItem.forceActiveFocus(Qt.BacktabFocusReason)
}
Keys.onDownPressed: {
const nextItem = nextItemInFocusChain(true)
if (nextItem) nextItem.forceActiveFocus(Qt.TabFocusReason)
}这样可以避免可选链操作符可能带来的兼容性问题。
property bool keyProcessing: false
Keys.onUpPressed: {
if (keyProcessing) return
keyProcessing = true
const prevItem = nextItemInFocusChain(false)
if (prevItem) prevItem.forceActiveFocus(Qt.BacktabFocusReason)
keyProcessingTimer.restart()
}
Timer {
id: keyProcessingTimer
interval: 50
onTriggered: keyProcessing = false
}
Keys.onReturnPressed: {
if (rightLoader.item && typeof rightLoader.item.clicked === 'function') {
rightLoader.item.clicked()
}
}
Accessible.name: model.item.name
Accessible.description: model.item.description
onActiveFocusChanged: {
if (activeFocus) {
// 添加视觉反馈
}
}
总体来说,这些改动提高了应用的可访问性,使键盘用户能够更好地导航和使用界面。建议在实施时进行充分的测试,确保所有交互场景都能正常工作。 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnables keyboard Tab/arrow navigation and activation within control center item delegates while preventing focus from landing on icon-only controls that shouldn’t be tabbable, and ensures the dock plugin area page’s parent item is not tabbable by default. Sequence diagram for key event handling in DccEditorItem focus navigationsequenceDiagram
actor User
participant DccEditorItem
participant FocusChain
participant RightLoader
participant RightLoaderItem
User->>DccEditorItem: Press_Tab
DccEditorItem->>FocusChain: nextItemInFocusChain(true)
FocusChain-->>DccEditorItem: nextItem
DccEditorItem->>FocusChain: nextItem.forceActiveFocus(Qt.TabFocusReason)
User->>DccEditorItem: Press_Up
DccEditorItem->>FocusChain: nextItemInFocusChain(false)
FocusChain-->>DccEditorItem: previousItem
DccEditorItem->>FocusChain: previousItem.forceActiveFocus(Qt.BacktabFocusReason)
User->>DccEditorItem: Press_Return_or_Enter
DccEditorItem->>RightLoader: access_item
alt RightLoader_has_item
RightLoader->>RightLoaderItem: clicked()
else RightLoader_item_missing
RightLoader-->>DccEditorItem: no_action
end
Flow diagram for focus eligibility and tab behavior in control center and dock plugin areaflowchart TD
A_Start[Start key navigation] --> B_CheckItemType{Is focused item a DccEditorItem or DccItem?}
B_CheckItemType -->|Yes| C_FocusAllowed[activeFocusOnTab true]
B_CheckItemType -->|No| D_CheckIconOrParent{Is item DccCheckIcon or PluginArea_parent_item?}
D_CheckIconOrParent -->|Yes| E_FocusBlocked[activeFocusOnTab false]
D_CheckIconOrParent -->|No| F_DefaultFocusBehavior[Use_default_QML_focus_behavior]
C_FocusAllowed --> G_KeyPressed{Key pressed?}
G_KeyPressed -->|Tab_or_Down| H_MoveNext[nextItemInFocusChain true and forceActiveFocus Qt_TabFocusReason]
G_KeyPressed -->|Backtab_or_Up| I_MovePrevious[nextItemInFocusChain false and forceActiveFocus Qt_BacktabFocusReason]
G_KeyPressed -->|Enter_or_Return| J_TryActivateRightLoader{Does rightLoader_have_item?}
J_TryActivateRightLoader -->|Yes| K_InvokeClick[rightLoader.item.clicked]
J_TryActivateRightLoader -->|No| L_NoAction[No action]
H_MoveNext --> M_End[End key handling]
I_MovePrevious --> M_End
K_InvokeClick --> M_End
L_NoAction --> M_End
E_FocusBlocked --> M_End
F_DefaultFocusBehavior --> M_End
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The use of optional chaining in
nextItemInFocusChain(false)?.forceActiveFocus(...)may not be supported by all QML/JS versions; consider using an explicit null check before callingforceActiveFocusto avoid runtime issues. - In the
Keys.onReturnPressed/Keys.onEnterPressedhandlers, guard not only againstrightLoader.itembeing null but also ensure thatrightLoader.item.clickedactually exists before invoking it, to avoid potential runtime errors when the loaded item lacks aclickedhandler. - If the intent is for the Up/Down key handlers to fully control focus navigation, consider explicitly accepting the key events (e.g., via the event parameter) to prevent unintended propagation and duplicate focus changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The use of optional chaining in `nextItemInFocusChain(false)?.forceActiveFocus(...)` may not be supported by all QML/JS versions; consider using an explicit null check before calling `forceActiveFocus` to avoid runtime issues.
- In the `Keys.onReturnPressed`/`Keys.onEnterPressed` handlers, guard not only against `rightLoader.item` being null but also ensure that `rightLoader.item.clicked` actually exists before invoking it, to avoid potential runtime errors when the loaded item lacks a `clicked` handler.
- If the intent is for the Up/Down key handlers to fully control focus navigation, consider explicitly accepting the key events (e.g., via the event parameter) to prevent unintended propagation and duplicate focus changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Fix the issue where tab cannot select focus
Log: Fix the issue where tab cannot select focus
pms: BUG-311339
Summary by Sourcery
Improve keyboard focus handling for control center items and dock plugin area pages.
Bug Fixes: