lookingGlass: Handle completions asynchronously

They will actually become asynchronous in a following commit,
prepare for that.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2842>
This commit is contained in:
Florian Müllner 2023-07-13 01:52:06 +02:00 committed by Marge Bot
parent 03025d7cff
commit 561d0d3758

View File

@ -94,30 +94,29 @@ var AutoComplete = class AutoComplete extends Signals.EventEmitter {
} }
} }
async _handleCompletions(text, time) {
const [completions, attrHead] =
await JsParse.getCompletions(text, commandHeader, AUTO_COMPLETE_GLOBAL_KEYWORDS);
const tabType = (time - this._lastTabTime) < AUTO_COMPLETE_DOUBLE_TAB_DELAY
? 'double' : 'single';
this._processCompletionRequest({
tabType,
completions,
attrHead,
});
this._lastTabTime = time;
}
_entryKeyPressEvent(actor, event) { _entryKeyPressEvent(actor, event) {
let cursorPos = this._entry.clutter_text.get_cursor_position(); let cursorPos = this._entry.clutter_text.get_cursor_position();
let text = this._entry.get_text(); let text = this._entry.get_text();
if (cursorPos != -1) if (cursorPos != -1)
text = text.slice(0, cursorPos); text = text.slice(0, cursorPos);
if (event.get_key_symbol() == Clutter.KEY_Tab) { if (event.get_key_symbol() === Clutter.KEY_Tab)
let [completions, attrHead] = JsParse.getCompletions(text, commandHeader, AUTO_COMPLETE_GLOBAL_KEYWORDS); this._handleCompletions(text, event.get_time()).catch(logError);
let currTime = global.get_current_time();
if ((currTime - this._lastTabTime) < AUTO_COMPLETE_DOUBLE_TAB_DELAY) {
this._processCompletionRequest({
tabType: 'double',
completions,
attrHead,
});
} else {
this._processCompletionRequest({
tabType: 'single',
completions,
attrHead,
});
}
this._lastTabTime = currTime;
}
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_PROPAGATE;
} }