Browse Source

HUE-7725 [autocomplete] Make sure we don't make suggestions on stale editor contents

Johan Ahlen 8 năm trước cách đây
mục cha
commit
22d93cb1bb

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

@@ -4001,8 +4001,8 @@
 
       var lastKnownLocations = {};
 
-      var getLocationsSub = huePubSub.subscribe('get.active.editor.locations', function (callback) {
-        if (self.snippet.inFocus() || self.snippet.editorMode()) {
+      var getLocationsSub = huePubSub.subscribe('get.active.editor.locations', function (callback, snippet) {
+        if (self.snippet === snippet || self.snippet.inFocus() || self.snippet.editorMode()) {
           callback(lastKnownLocations);
         }
       });
@@ -4041,6 +4041,7 @@
             type: self.snippet.type(),
             defaultDatabase: self.snippet.database(),
             locations: e.data.locations,
+            editorChangeTime: e.data.editorChangeTime,
             activeStatementLocations: e.data.activeStatementLocations,
             totalStatementCount: e.data.totalStatementCount,
             activeStatementIndex: e.data.activeStatementIndex

+ 8 - 7
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -1893,18 +1893,19 @@ var SqlAutocompleter3 = (function () {
     var self = this;
     var parseResult;
     try {
+      huePubSub.publish('get.active.editor.locations', function (locations) {
+        // This could happen in case the user is editing at the borders of the statement and the locations haven't
+        // been updated yet, in that case we have to force a location update before parsing
+        if (self.snippet.ace && self.snippet.ace() && locations && self.snippet.ace().lastChangeTime !== locations.editorChangeTime) {
+          huePubSub.publish('editor.refresh.statement.locations', self.snippet);
+        }
+      }, self.snippet);
+
       parseResult = self.parseActiveStatement();
 
       if (typeof hueDebug !== 'undefined' && hueDebug.showParseResult) {
         console.log(parseResult);
       }
-
-      // This could happen in case the user is editing at the borders of the statement and the locations haven't
-      // been updated yet, in that case we have to force a location update before parsing
-      if (!parseResult) {
-        huePubSub.publish('editor.refresh.statement.locations', self.snippet);
-        parseResult = self.parseActiveStatement();
-      }
     } catch (e) {
       if (typeof console.warn !== 'undefined') {
         console.warn(e);