浏览代码

[beeswax] Fix table name autocomplete

This commit takes care of the following two issues:

- Table names had any leading 'f','r','o' or 'm' characters removed on completion after "from"
- Codemirror does not support multiple words in completion, like "from foo"
Johan Ahlen 10 年之前
父节点
当前提交
f424e76816
共有 1 个文件被更改,包括 29 次插入14 次删除
  1. 29 14
      apps/beeswax/src/beeswax/templates/execute.mako

+ 29 - 14
apps/beeswax/src/beeswax/templates/execute.mako

@@ -1519,30 +1519,45 @@ $(document).ready(function () {
     var _after = _statementAtCursor.statement.substr(_statementAtCursor.relativeIndex).replace(/;+$/, "");
 
     autocompleter.autocomplete(_before, _after, function(suggestions) {
-      CodeMirror.possibleSoloField = suggestions.length > 0;
-      CodeMirror.tableFieldMagic = false;
-      CodeMirror.fromDot = _before.match(/.*\.[^ ]*$/) != null;
+      var isFromDot = _before.match(/.*\.[^ ]*$/) != null;
       var isTable = false;
+      var tableFieldMagic = false;
+      var hasFromPrefix = false;
 
       var values = suggestions.map(function(suggestion) {
         if (suggestion.meta === "table") {
           isTable = true; // They're all tables.
-          var match = suggestion.value.match(/(\? )?f?r?o?m? ?([^ ]+)$/i);
-          if (typeof match[1] !== "undefined") {
-            CodeMirror.tableFieldMagic = true;
+          var match = suggestion.value.match(/(\? )?from ([^ ]+)$/i);
+          if (match != null) {
+            if (typeof match[1] != "undefined") {
+              tableFieldMagic = true;
+              return match[2];
+            } else {
+              hasFromPrefix = true;
+            }
           }
-          return match[2];
+          return suggestion.value;
         } else {
-          return CodeMirror.fromDot ? "." + suggestion.value : suggestion.value;
+          return isFromDot ? "." + suggestion.value : suggestion.value;
         }
-      }).join(' ');
-
-      if (isTable) {
-        CodeMirror.possibleTable = !CodeMirror.tableFieldMagic;
-        CodeMirror.catalogTables = values;
+      }).join(" ");
+
+      if (values.length > 0 && !hasFromPrefix) {
+        CodeMirror.fromDot = isFromDot;
+        CodeMirror.possibleSoloField = true;
+        CodeMirror.tableFieldMagic = tableFieldMagic;
+        CodeMirror.possibleTable = isTable && !tableFieldMagic;
+        CodeMirror.catalogTables = isTable ? values : "";
+        CodeMirror.catalogFields = isTable ? "" : values;
       } else {
-        CodeMirror.catalogFields = values;
+        CodeMirror.fromDot = false;
+        CodeMirror.possibleSoloField = false;
+        CodeMirror.tableFieldMagic = false;
+        CodeMirror.possibleTable = false;
+        CodeMirror.catalogTables = "";
+        CodeMirror.catalogFields = "";
       }
+
       CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
     });
   };