فهرست منبع

HUE-4785 [editor] Favour continuous partial matches in the autocomplete results

This give priority to continuous matches over split matches inside the suggestions.
Johan Ahlen 10 سال پیش
والد
کامیت
cfbd74d
2فایلهای تغییر یافته به همراه33 افزوده شده و 20 حذف شده
  1. 0 0
      desktop/core/src/desktop/static/desktop/js/ace/ext-language_tools.js
  2. 33 20
      tools/ace-editor/lib/ace/autocomplete.js

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/ace/ext-language_tools.js


+ 33 - 20
tools/ace-editor/lib/ace/autocomplete.js

@@ -437,21 +437,32 @@ var FilteredList = function(array, filterText) {
         this.filterText = str;
         matches = this.filterCompletions(matches, this.filterText);
         matches = matches.sort(function (a, b) {
-          if (a.prioritizeScore && b.prioritizeScore) {
-            return b.score - a.score
-          } else if (a.prioritizeScore) {
-            return -1;
-          } else if (b.prioritizeScore) {
-            return 1;
-          }
-          var alpha = 0;
-          if (a.caption > b.caption) {
-            alpha = 1;
-          }
-          if (a.caption < b.caption) {
-            alpha = -1;
-          }
-          return alpha + b.exactMatch - a.exactMatch || alpha + b.score - a.score;
+            if (a.completeMatch && ! b.completeMatch) {
+                return -1;
+            } else if (! a.completeMatch && b.completeMatch) {
+                return 1;
+            } else if (a.completeMatch && b.completeMatch && a.weight && b.weight && b.weight !== a.weight) {
+                return b.weight - a.weight;
+            } else if (a.completeMatch && b.completeMatch && a.startsWith && ! b.startsWith) {
+                return -1;
+            } else if (a.completeMatch && b.completeMatch && ! a.startsWith && b.startsWith) {
+                return 1;
+            }
+            if (a.prioritizeScore && b.prioritizeScore) {
+                return b.score - a.score
+            } else if (a.prioritizeScore) {
+                return -1;
+            } else if (b.prioritizeScore) {
+                return 1;
+            }
+            var alpha = 0;
+            if (a.caption > b.caption) {
+                alpha = 1;
+            }
+            if (a.caption < b.caption) {
+                alpha = -1;
+            }
+            return alpha + b.exactMatch - a.exactMatch || alpha + b.score - a.score;
         });
 
         // make unique
@@ -476,6 +487,7 @@ var FilteredList = function(array, filterText) {
             var matchMask = 0;
             var penalty = 0;
             var index, distance;
+            var completeIndex = 0;
 
             if (this.exactMatch && item.ignoreCase) {
                 if (upper !== item.upperCaseValue.substr(0, needle.length)) {
@@ -486,9 +498,11 @@ var FilteredList = function(array, filterText) {
             } else if (this.exactMatch && needle !== caption.substr(0, needle.length)) {
                 continue loop;
             } else {
-                // caption char iteration is faster in Chrome but slower in Firefox, so lets use indexOf
+                completeIndex = caption.toUpperCase().indexOf(upper);
+                if (completeIndex > -1) {
+                    lastIndex = completeIndex - 1;
+                }
                 for (var j = 0; j < needle.length; j++) {
-                    // TODO add penalty on case mismatch
                     var i1 = caption.indexOf(lower[j], lastIndex + 1);
                     var i2 = caption.indexOf(upper[j], lastIndex + 1);
                     index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
@@ -496,9 +510,6 @@ var FilteredList = function(array, filterText) {
                         continue loop;
                     distance = index - lastIndex - 1;
                     if (distance > 0) {
-                        // first char mismatch should be more sensitive
-                        if (lastIndex === -1)
-                            penalty += 10;
                         penalty += distance;
                     }
                     matchMask = matchMask | (1 << index);
@@ -508,6 +519,8 @@ var FilteredList = function(array, filterText) {
             item.matchMask = matchMask;
             item.exactMatch = penalty ? 0 : 1;
             item.score = (item.score || 0) - penalty;
+            item.startsWith = completeIndex === 0;
+            item.completeMatch = completeIndex > -1;
             results.push(item);
         }
         return results;

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است