Преглед на файлове

HUE-7062 [dashboard] Move formula editor cursor between the parentheses and trigger autocomplete when inserting functions

Johan Ahlen преди 8 години
родител
ревизия
099a8a0

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

@@ -4516,7 +4516,7 @@
         });
 
         disposeFunctions.push(function () {
-          editor.off('input', mousemoveListener);
+          editor.off('input', inputListener);
         });
 
         var mouseoutListener = function (e) {

+ 13 - 0
desktop/core/src/desktop/templates/ko_components/ko_simple_ace_editor.mako

@@ -650,6 +650,19 @@ from desktop.views import _ko
           }
           editor.completer.exactMatch = false;
           editor.useHueAutocompleter = true;
+
+          var afterExecListener = editor.commands.on('afterExec', function (e) {
+            if (e.command.name === "insertstring" && /\S+\(\)$/.test(e.args)) {
+              editor.moveCursorTo(editor.getCursorPosition().row, editor.getCursorPosition().column - 1);
+              window.setTimeout(function () {
+                editor.execCommand("startAutocomplete");
+              }, 1);
+            }
+          });
+
+          self.disposeFunctions.push(function () {
+            editor.commands.off('afterExec', afterExecListener);
+          });
         }
 
         var inputListener = editor.on('input', function () {