fix: set focus to search edit when launcher becomes visible#729
Closed
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Closed
fix: set focus to search edit when launcher becomes visible#729Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
When the launcher is shown, the keyboard focus remains on the root InputEventItem instead of the search edit. This causes two issues: 1. The cursor does not appear in the search bar on each open. 2. The IME candidate window is not visible during the preedit phase (e.g. typing pinyin), because InputEventItem is not a text input widget and cannot provide cursor geometry for IME positioning. Fix by calling forceActiveFocus() on the search edit when the launcher becomes visible, for both windowed and fullscreen modes. 修复启动器显示时搜索框未获得焦点的问题。启动器打开时键盘焦点停留在根节点 InputEventItem 上而非搜索框,导致光标不在搜索栏,且中文输入法预编辑阶段 (如拼音输入时)候选框不可见。在启动器可见时对搜索框调用 forceActiveFocus() 以修复此问题,同时修复窗口模式和全屏模式。 PMS: BUG-301743
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 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 |
deepin pr auto review这份代码变更主要涉及启动器在可见性变化时的焦点管理和清理逻辑。以下是对代码的详细审查和改进建议: 代码审查1. 逻辑变更分析
2. 语法与逻辑检查
3. 代码质量
4. 性能
5. 安全性
改进建议1. 增加错误处理if (LauncherController.visible) {
if (searchEdit) { // 确保组件存在
searchEdit.forceActiveFocus()
}
return
}2. 提取公共逻辑如果多个文件中需要类似的逻辑,可以定义一个公共函数: // 在公共 JS 文件中
function handleLauncherVisibleChanged(searchEdit) {
if (LauncherController.visible) {
if (searchEdit) {
searchEdit.forceActiveFocus()
}
return
}
// 清理逻辑
searchEdit.text = ""
// 其他清理操作...
}3. 增加日志记录if (LauncherController.visible) {
console.debug("Launcher visible, forcing focus on searchEdit")
searchEdit.forceActiveFocus()
return
}4. 考虑异步加载如果 if (LauncherController.visible) {
Qt.callLater(() => {
if (searchEdit) {
searchEdit.forceActiveFocus()
}
})
return
}最终优化后的代码示例FullscreenFrame.qmlConnections {
target: LauncherController
function onVisibleChanged() {
if (LauncherController.visible) {
if (searchEdit) { // 安全检查
searchEdit.forceActiveFocus()
}
return
}
// 清理逻辑
searchEdit.text = ""
if (listviewPage.currentItem) {
// 其他清理操作...
}
}
}WindowedFrame.qmlConnections {
target: LauncherController
function onVisibleChanged() {
if (LauncherController.visible) {
if (bottomBar.searchEdit) { // 安全检查
bottomBar.searchEdit.forceActiveFocus()
}
return
}
// 清理逻辑
bottomBar.searchEdit.text = ""
// 其他清理操作...
}
}总结原代码变更逻辑正确,但可以通过增加安全检查、提取公共逻辑和日志记录来提高代码的健壮性和可维护性。改进后的代码更安全、更清晰,且易于维护。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the launcher is shown, the keyboard focus remains on the root InputEventItem instead of the search edit. This causes two issues:
Fix by calling forceActiveFocus() on the search edit when the launcher becomes visible, for both windowed and fullscreen modes.
修复启动器显示时搜索框未获得焦点的问题。启动器打开时键盘焦点停留在根节点
InputEventItem 上而非搜索框,导致光标不在搜索栏,且中文输入法预编辑阶段
(如拼音输入时)候选框不可见。在启动器可见时对搜索框调用 forceActiveFocus()
以修复此问题,同时修复窗口模式和全屏模式。
PMS: BUG-301743