Browse Source

[core] Pad dropped assist text with spaces if it's dropped in or next to a word

Johan Ahlen 10 năm trước cách đây
mục cha
commit
ad44fb8

+ 8 - 0
apps/beeswax/src/beeswax/templates/execute.mako

@@ -1619,6 +1619,14 @@ $(document).ready(function () {
       var position = codeMirror.coordsChar({"left": e.clientX, "top": e.clientY});
       var text = ui.helper.text();
       codeMirror.setCursor(position);
+      var value = codeMirror.getValue();
+      var index = codeMirror.indexFromPos(codeMirror.getCursor());
+      if (index > 0 && value.charAt(index - 1) !== ' ' && value.charAt(index - 1) !== '.') {
+        text = " " + text;
+      }
+      if ((index + 1) < value.length - 1  && value.charAt(index + 1) !== ' ' && text.charAt(text.length - 1) !== ' ') {
+        text += " ";
+      }
       codeMirror.replaceSelection(text);
       codeMirror.setSelection(codeMirror.getCursor());
       codeMirror.focus();

+ 9 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -2084,9 +2084,17 @@
         drop: function (e, ui) {
           var position = editor.renderer.screenToTextCoordinates(e.clientX, e.clientY);
           var text = ui.helper.text();
+          editor.moveCursorToPosition(position);
+          var before = editor.getTextBeforeCursor();
+          if (before.length > 0 && before.charAt(before.length - 1) !== ' ' && before.charAt(before.length - 1) !== '.') {
+            text = " " + text;
+          }
+          var after = editor.getTextAfterCursor();
+          if (after.length > 0 && after.charAt(0) !== ' ' && text.charAt(text.length - 1) !== ' ') {
+            text += " ";
+          }
           editor.session.insert(position, text);
           position.column += text.length;
-          editor.moveCursorToPosition(position);
           editor.clearSelection();
         }
       });