The key focus in the 'Type to search' box is lost when entering the first character with some input methods
Affected version
Provide at least the following information:
- OS: Fedora 40
- Affected GNOME Shell version: 46
- Does this issue appear in XOrg and/or Wayland: XOrg and Wayland
- Does this issue happen without extensions: Yes
Bug summary
The key focus in the 'Type to search' box is lost when entering the first character with some input methods that use surrounding text.
Steps to reproduce
ibus-hiragana:
With- Type 'kanji' to enter 'かんじ' in the 'Type to search' box.
- Hit space key to replace 'かんじ' with '漢字'.
ibus-bamboo:
With- Select the 'Surrounding Text' mode from the keyboard menu in the top bar.
- Type 'Dd' to enter 'Đ' in the 'Type to search' box.
What happened
In both cases, the 'Type to search' box loses the key focus and becomes empty. There should have been '漢字' or 'Đ' in the box, though.
Relevant logs, screenshots, screencasts etc.
These input methods use ibus_engine_delete_surrounding_text() and ibus_engine_commit_text() as a pair to replace the character(s) before the cursor with the another character(s).
For instance, in the case of ibus-bamboo, when the second 'd' is typed, it removes the previous 'D' with ibus_engine_delete_surrounding_text(), and then inserts 'Đ' with ibus_engine_commit_text(). When the letter 'D' is removed, the function _searchCancelled() is called from _onTextChanged() in searchController.js. As a result, _setSearchActive(false) is invoked, emitting the 'search-active' signal. The emitted signal reaches _onSearchChanged() in overviewControls.js. When _searchController.ease() completes, reset() in searchController.js is called, causing the key focus to be lost.
However, ibus-bamboo still needs to commit 'Đ', and it encounters the following error:
gnome-shell[3372]: clutter_input_focus_set_surrounding: assertion 'clutter_input_focus_is_focused (focus)' failed
This situation is almost identical to what is described in the comment of the _searchCancelled() function in searchController.js. A possible fix for this issue would be the patch shown below:
--- a/js/ui/searchController.js
+++ b/js/ui/searchController.js
@@ -178,7 +178,7 @@ export const SearchController = GObject.registerClass({
// Don't drop the key focus on Clutter's side if anything but the
// overview has pushed a modal (e.g. system modals when activated using
// the overview).
- if (Main.modalCount <= 1)
+ if (Main.modalCount <= 1 && this._text.text !== '')
global.stage.set_key_focus(null);
this._entry.text = '';
Also note that mutter#3440 has to be fixed to test this issue.