From 6a4a457eb9b5fa94ba6cc0f0a432f00d0162ba7d Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sun, 10 Apr 2022 00:32:39 +0200 Subject: [PATCH] Fix autocomplete --- src/js/CliAutoComplete.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/js/CliAutoComplete.js b/src/js/CliAutoComplete.js index 5e4b08b8..93abfd15 100644 --- a/src/js/CliAutoComplete.js +++ b/src/js/CliAutoComplete.js @@ -289,23 +289,32 @@ CliAutoComplete._initTextcomplete = function() { * Then add `mousemove` handler. If the mouse moves we consider that mouse interaction * is desired so we reenable the `mouseover` handler */ + + const textCompleteDropDownElement = $('.textcomplete-dropdown'); + if (!savedMouseoverItemHandler) { // save the original 'mouseover' handeler - savedMouseoverItemHandler = $._data($('.textcomplete-dropdown')[0], 'events').mouseover[0].handler; - } + try { + savedMouseoverItemHandler = $._data(textCompleteDropDownElement[0], 'events').mouseover[0].handler; + } catch (error) { + console.log(error); + } - $('.textcomplete-dropdown') - .off('mouseover') // initially disable it - .off('mousemove') // avoid `mousemove` accumulation if previous show did not trigger `mousemove` - .on('mousemove', '.textcomplete-item', function(e) { - // the mouse has moved so reenable `mouseover` - $(this).parent() + if (savedMouseoverItemHandler) { + textCompleteDropDownElement + .off('mouseover') // initially disable it + .off('mousemove') // avoid `mousemove` accumulation if previous show did not trigger `mousemove` + .on('mousemove', '.textcomplete-item', function(e) { + // the mouse has moved so reenable `mouseover` + $(this).parent() .off('mousemove') .on('mouseover', '.textcomplete-item', savedMouseoverItemHandler); - // trigger the mouseover handler to select the item under the cursor - savedMouseoverItemHandler(e); - }); + // trigger the mouseover handler to select the item under the cursor + savedMouseoverItemHandler(e); + }); + } + } }); // textcomplete autocomplete strategies