Sfoglia il codice sorgente

HUE-4640 [editor] Fix for DB prefix autcomplete when typing table names after "? FROM db."

Johan Ahlen 9 anni fa
parent
commit
23a12a8
1 ha cambiato i file con 16 aggiunte e 12 eliminazioni
  1. 16 12
      desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

+ 16 - 12
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3197,20 +3197,24 @@
       });
 
       var autocompleteTemporarilyDisabled = false;
+      var autocompleteThrottle = -1;
       editor.commands.on("afterExec", function (e) {
         if (editor.getOption('enableLiveAutocompletion') && e.command.name === "insertstring") {
-          var questionMarkMatch = editor.getTextBeforeCursor().match(/select \? from \S+[^.]$/i);
-          if (questionMarkMatch) {
-            editor.moveCursorTo(editor.getCursorPosition().row, editor.getCursorPosition().column - questionMarkMatch[0].length + 8);
-            editor.removeTextBeforeCursor(1);
-            window.setTimeout(function () {
-              editor.execCommand("startAutocomplete");
-            }, 1);
-          } else if (/\.$/.test(editor.getTextBeforeCursor())) {
-            window.setTimeout(function () {
-              editor.execCommand("startAutocomplete");
-            }, 1);
-          }
+          window.clearTimeout(autocompleteThrottle);
+          autocompleteThrottle = window.setTimeout(function () {
+              var questionMarkMatch = editor.getTextBeforeCursor().match(/select \? from \S+[^.]$/i);
+              if (questionMarkMatch && $('.ace_autocomplete:visible').length === 0) {
+                editor.moveCursorTo(editor.getCursorPosition().row, editor.getCursorPosition().column - questionMarkMatch[0].length + 8);
+                editor.removeTextBeforeCursor(1);
+                window.setTimeout(function () {
+                  editor.execCommand("startAutocomplete");
+                }, 1);
+              } else if (/\.$/.test(editor.getTextBeforeCursor())) {
+                window.setTimeout(function () {
+                  editor.execCommand("startAutocomplete");
+                }, 1);
+              }
+          }, 400);
         }
         editor.session.getMode().$id = snippet.getAceMode(); // forces the id again because of Ace command internals
         // if it's pig and before it's LOAD ' we disable the autocomplete and show a filechooser btn