inputMethod: Update to set_preedit_text() API change

Since IBus does not provide this information right away, we
so far cannot do much about providing a truthful anchor position
for the preedit text. But with the Mutter API in place it will
be up to this object to do so in the future.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2384>
This commit is contained in:
Carlos Garnacho 2022-07-18 15:11:49 +02:00 committed by Marge Bot
parent fa6a712a34
commit b0187d4261

View File

@ -18,6 +18,7 @@ class InputMethod extends Clutter.InputMethod {
this._currentFocus = null; this._currentFocus = null;
this._preeditStr = ''; this._preeditStr = '';
this._preeditPos = 0; this._preeditPos = 0;
this._preeditAnchor = 0;
this._preeditVisible = false; this._preeditVisible = false;
this._hidePanelId = 0; this._hidePanelId = 0;
this._ibus = IBus.Bus.new_async(); this._ibus = IBus.Bus.new_async();
@ -85,6 +86,7 @@ class InputMethod extends Clutter.InputMethod {
this._purpose = 0; this._purpose = 0;
this._preeditStr = ''; this._preeditStr = '';
this._preeditPos = 0; this._preeditPos = 0;
this._preeditAnchor = 0;
this._preeditVisible = false; this._preeditVisible = false;
} }
@ -114,24 +116,30 @@ class InputMethod extends Clutter.InputMethod {
if (preedit === '') if (preedit === '')
preedit = null; preedit = null;
const anchor = pos;
if (visible) if (visible)
this.set_preedit_text(preedit, pos, mode); this.set_preedit_text(preedit, pos, anchor, mode);
else if (this._preeditVisible) else if (this._preeditVisible)
this.set_preedit_text(null, pos, mode); this.set_preedit_text(null, pos, anchor, mode);
this._preeditStr = preedit; this._preeditStr = preedit;
this._preeditPos = pos; this._preeditPos = pos;
this._preeditAnchor = anchor;
this._preeditVisible = visible; this._preeditVisible = visible;
this._preeditCommitMode = mode; this._preeditCommitMode = mode;
} }
_onShowPreeditText() { _onShowPreeditText() {
this._preeditVisible = true; this._preeditVisible = true;
this.set_preedit_text(this._preeditStr, this._preeditPos, this._preeditCommitMode); this.set_preedit_text(
this._preeditStr, this._preeditPos, this._preeditAnchor,
this._preeditCommitMode);
} }
_onHidePreeditText() { _onHidePreeditText() {
this.set_preedit_text(null, this._preeditPos, this._preeditCommitMode); this.set_preedit_text(
null, this._preeditPos, this._preeditAnchor,
this._preeditCommitMode);
this._preeditVisible = false; this._preeditVisible = false;
} }
@ -169,7 +177,7 @@ class InputMethod extends Clutter.InputMethod {
if (this._preeditStr && this._preeditVisible) { if (this._preeditStr && this._preeditVisible) {
// Unset any preedit text // Unset any preedit text
this.set_preedit_text(null, 0, this._preeditCommitMode); this.set_preedit_text(null, 0, 0, this._preeditCommitMode);
this._preeditStr = null; this._preeditStr = null;
} }