fix: adjust focus handling in search edit widget#3723
fix: adjust focus handling in search edit widget#3723deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Removed Qt::ActiveWindowFocusReason from the focus out event condition to prevent unnecessary widget collapse when switching windows. This improves user experience by maintaining search widget visibility during window switching operations. Log: Fixed issue where search widget would collapse unexpectedly when switching between windows Influence: 1. Test search widget behavior when clicking on popup menus 2. Verify search box remains visible when switching between application windows 3. Check that proper collapse behavior remains for other focus out reasons 4. Test with different window managers and desktop environments fix: 调整搜索编辑小部件的焦点处理 从焦点移出事件条件中移除了 Qt::ActiveWindowFocusReason,以防止在切换窗口 时不必要的控件折叠。这改善了用户通过窗口切换操作时保持搜索小部件可见性的 体验。 Log: 修复了在窗口间切换时搜索小工具意外折叠的问题 Influence: 1. 测试点击弹出菜单时的搜索小部件行为 2. 验证在切换应用程序窗口时搜索框是否保持可见 3. 检查其他焦点移出原因是否仍保持正确的折叠行为 4. 在不同窗口管理器和桌面环境中进行测试
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs 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 |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider documenting in-code (e.g., a short comment near the condition) why
Qt::ActiveWindowFocusReasonis intentionally excluded now, so future maintainers don’t reintroduce it when adjusting focus handling logic. - You might want to centralize the list of focus reasons that should not trigger collapse (e.g., via a small helper or static function) so it’s easier to extend or adjust this behavior consistently if new special cases arise.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider documenting in-code (e.g., a short comment near the condition) why `Qt::ActiveWindowFocusReason` is intentionally excluded now, so future maintainers don’t reintroduce it when adjusting focus handling logic.
- You might want to centralize the list of focus reasons that should not trigger collapse (e.g., via a small helper or static function) so it’s easier to extend or adjust this behavior consistently if new special cases arise.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts focus handling in the search edit widget so that only popup-related focus changes are exempt from collapse, preventing the widget from collapsing when the active window changes while preserving existing popup behavior. Sequence diagram for updated focus out handling in SearchEditWidgetsequenceDiagram
actor User
participant WindowManager
participant Application
participant SearchEditWidget
participant QFocusEvent
User->>SearchEditWidget: Interact with search box
rect rgb(230,230,255)
User->>WindowManager: Switch to another window
WindowManager-->>Application: Change active window
Application->>SearchEditWidget: QFocusEvent (ActiveWindowFocusReason)
SearchEditWidget->>QFocusEvent: reason()
QFocusEvent-->>SearchEditWidget: ActiveWindowFocusReason
alt reason is PopupFocusReason
SearchEditWidget->>QFocusEvent: accept()
SearchEditWidget->>SearchEditWidget: restoreFocusIfNeeded()
SearchEditWidget-->>Application: Do not collapse
else reason is ActiveWindowFocusReason
SearchEditWidget-->>Application: Proceed with default collapse handling
end
end
rect rgb(230,255,230)
User->>Application: Open popup (e.g. context menu)
Application->>SearchEditWidget: QFocusEvent (PopupFocusReason)
SearchEditWidget->>QFocusEvent: reason()
QFocusEvent-->>SearchEditWidget: PopupFocusReason
SearchEditWidget->>QFocusEvent: accept()
SearchEditWidget->>SearchEditWidget: restoreFocusIfNeeded()
SearchEditWidget-->>Application: Keep widget expanded
end
Class diagram for SearchEditWidget focus handling logicclassDiagram
class SearchEditWidget {
+handleFocusOutEvent(e: QFocusEvent*) void
-restoreFocusIfNeeded() void
}
class QFocusEvent {
+reason() QtFocusReason
+accept() void
}
class QtFocusReason {
<<enumeration>>
PopupFocusReason
ActiveWindowFocusReason
OtherReasons
}
SearchEditWidget --> QFocusEvent : uses
QFocusEvent --> QtFocusReason : returns
%% Focus handling detail
class FocusHandlingLogic {
+onFocusOut(e: QFocusEvent*) void
}
SearchEditWidget ..> FocusHandlingLogic : delegates logic
class FocusHandlingLogic {
+ignoreWhenPopup(reason: QtFocusReason) bool
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码的修改涉及 1. 代码逻辑分析原代码逻辑: if (e->reason() == Qt::PopupFocusReason || e->reason() == Qt::ActiveWindowFocusReason) {
e->accept();
restoreFocusIfNeeded();
return;
}当焦点丢失原因是 修改后代码: if (e->reason() == Qt::PopupFocusReason) {
e->accept();
restoreFocusIfNeeded();
return;
}移除了对 2. 改进意见2.1 逻辑正确性
2.2 代码可读性
2.3 代码安全性
2.4 性能影响
3. 最终建议
4. 修改后的代码示例void SearchEditWidget::handleFocusOutEvent(QFocusEvent *e)
{
if (!e) {
return;
}
// 只忽略弹出窗口导致的焦点丢失,允许窗口切换时折叠搜索框
if (e->reason() == Qt::PopupFocusReason) {
e->accept();
restoreFocusIfNeeded();
return;
}
// 其他处理逻辑...
}总结这段代码的修改主要是调整了焦点丢失事件的处理逻辑,移除了对 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Removed Qt::ActiveWindowFocusReason from the focus out event condition
to prevent unnecessary widget collapse when switching windows. This
improves user experience by maintaining search widget visibility during
window switching operations.
Log: Fixed issue where search widget would collapse unexpectedly when
switching between windows
Influence:
windows
reasons
fix: 调整搜索编辑小部件的焦点处理
从焦点移出事件条件中移除了 Qt::ActiveWindowFocusReason,以防止在切换窗口
时不必要的控件折叠。这改善了用户通过窗口切换操作时保持搜索小部件可见性的
体验。
Log: 修复了在窗口间切换时搜索小工具意外折叠的问题
Influence:
Summary by Sourcery
Bug Fixes: