浏览代码

HUE-5066 [editor] Move cursor between () when autocompleting a udf

Johan Ahlen 9 年之前
父节点
当前提交
9836d44de1
共有 1 个文件被更改,包括 17 次插入12 次删除
  1. 17 12
      desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

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

@@ -3421,20 +3421,25 @@
       var autocompleteThrottle = -1;
       editor.commands.on("afterExec", function (e) {
         if (editor.getOption('enableLiveAutocompletion') && e.command.name === "insertstring") {
+          if (/\S+\(\)$/.test(e.args)) {
+            editor.moveCursorTo(editor.getCursorPosition().row, editor.getCursorPosition().column - 1);
+            return;
+          }
           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);
-              }
+            var textBeforeCursor = editor.getTextBeforeCursor();
+            var questionMarkMatch = textBeforeCursor.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(textBeforeCursor)) {
+              window.setTimeout(function () {
+                editor.execCommand("startAutocomplete");
+              }, 1);
+            }
           }, 400);
         }
         editor.session.getMode().$id = snippet.getAceMode(); // forces the id again because of Ace command internals