From 561d0d37583766dd7123ca33aaad7e6f0898b65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 13 Jul 2023 01:52:06 +0200 Subject: [PATCH] lookingGlass: Handle completions asynchronously They will actually become asynchronous in a following commit, prepare for that. Part-of: --- js/ui/lookingGlass.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 05006d837..fd19e713e 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -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) { let cursorPos = this._entry.clutter_text.get_cursor_position(); let text = this._entry.get_text(); if (cursorPos != -1) text = text.slice(0, cursorPos); - if (event.get_key_symbol() == Clutter.KEY_Tab) { - let [completions, attrHead] = JsParse.getCompletions(text, commandHeader, AUTO_COMPLETE_GLOBAL_KEYWORDS); - 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; - } + if (event.get_key_symbol() === Clutter.KEY_Tab) + this._handleCompletions(text, event.get_time()).catch(logError); return Clutter.EVENT_PROPAGATE; }