浏览代码

[editor] Expand * to all table columns with alt/ctrl+click

Johan Ahlen 10 年之前
父节点
当前提交
78c657d01c

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

@@ -1978,7 +1978,35 @@
             var token = editor.session.getTokenAt(docPos.row, docPos.column);
 
             if (token) {
-              if (token.value.indexOf("'/") == 0 && token.value.lastIndexOf("'") == token.value.length - 1 ||
+              var self = this;
+              if (token.value === " * ") {
+                snippet.autocompleter.autocomplete(editor.getValue().substring(0, token.start + 1), editor.getValue().substring(token.start + 2), function (suggestions) {
+                  var cols = [];
+                  $.each(suggestions, function (idx, suggestion) {
+                    if (suggestion.meta === "column" && suggestion.value !== "*") {
+                      cols.push(suggestion.value);
+                    }
+                  });
+                  if (cols.length > 0) {
+                    // add highlight for the clicked token
+                    var start = token.value == " * " ? token.start + 1 : token.start;
+                    var end = token.value == " * " ? token.start + 2 : token.start + token.value.length;
+                    var range = new AceRange(docPos.row, start, docPos.row, end);
+                    token.range = range;
+                    token.columns = cols;
+                    editor.session.removeMarker(self.marker);
+                    self.marker = editor.session.addMarker(range, 'ace_bracket red');
+                    editor.renderer.setCursorStyle("pointer");
+                    self.setText(options.expandStar);
+                    if ($.totalStorage("hue.ace.showLinkTooltips") == null || $.totalStorage("hue.ace.showLinkTooltips")) {
+                      self.show(null, self.x + 10, self.y + 10);
+                    }
+                    self.link = token;
+                    self.isClearable = true
+                  }
+                });
+              }
+              else if (token.value.indexOf("'/") == 0 && token.value.lastIndexOf("'") == token.value.length - 1 ||
                   token.value.indexOf("\"/") == 0 && token.value.lastIndexOf("\"") == token.value.length - 1 ||
                   currentAssistTables[token.value]) {
                 // add highlight for the clicked token
@@ -2051,7 +2079,10 @@
       HueLink = ace.require("huelink").HueLink;
       editor.hueLink = new HueLink(editor);
       editor.hueLink.on("open", function (token) {
-        if (token.value.indexOf("'/") == 0 && token.value.lastIndexOf("'") == token.value.length - 1) {
+        if (token.value === " * " && token.columns.length > 0) {
+          editor.session.replace(token.range, token.columns.join(", "))
+        }
+        else if (token.value.indexOf("'/") == 0 && token.value.lastIndexOf("'") == token.value.length - 1) {
           window.open("/filebrowser/#" + token.value.replace(/'/gi, ""));
         }
         else if (token.value.indexOf("\"/") == 0 && token.value.lastIndexOf("\"") == token.value.length - 1) {

+ 1 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -527,6 +527,7 @@ ${ require.config() }
       <div class="ace-editor" data-bind="css: {'single-snippet-editor ace-editor-resizable' : $root.editorMode, 'active-editor': inFocus }, attr: { id: id() }, delayedOverflow, aceEditor: {
           snippet: $data,
           openIt: '${ _ko("Alt or Ctrl + Click to open it") }',
+          expandStar: '${ _ko("Alt or Ctrl + Click to replace with all columns") }',
           aceOptions: {
             showLineNumbers: $root.editorMode,
             showGutter: $root.editorMode,