Pārlūkot izejas kodu

HUE-5940 [autocomplete] Replace partial word to the right when inserting

Johan Ahlen 8 gadi atpakaļ
vecāks
revīzija
588f17d218

+ 5 - 0
desktop/core/src/desktop/static/desktop/js/ace.extended.js

@@ -38,6 +38,11 @@ try {
       return separator ? this.session.getTextRange(_r).split(separator).pop() : this.session.getTextRange(_r);
     }
 
+    editor.removeTextAfterCursor = function (length) {
+      var _r = new AceRange(this.getCursorPosition().row, this.getCursorPosition().column, this.getCursorPosition().row, this.getCursorPosition().column + length);
+      editor.getSession().getDocument().remove(_r);
+    }
+
     editor.getTextAfterCursor = function (separator) {
       var _r = new AceRange(this.getCursorPosition().row, this.getCursorPosition().column, this.session.getLength(), this.session.getRowLength(this.session.getLength()));
       return separator ? this.session.getTextRange(_r).split(separator).shift() : this.session.getTextRange(_r);

+ 5 - 1
desktop/libs/notebook/src/notebook/templates/hue_ace_autocompleter.mako

@@ -461,7 +461,11 @@ from desktop.views import _ko
             self.editor().session.remove(range);
           }
         }
-        self.editor().execCommand('insertstring', self.suggestions.filtered()[self.selectedIndex()].value);
+        var match = self.editor().getTextAfterCursor().match(/^[^\s.]+/);
+        if (match) {
+          self.editor().removeTextAfterCursor(match[0].length);
+        }
+        self.editor().insert(self.suggestions.filtered()[self.selectedIndex()].value);
         self.editor().renderer.scrollCursorIntoView();
         self.detach();
       };