UX: skip leading spaces in selection when adding a link.

UX: skip leading spaces in selection when adding a link.

diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index 5173f41d89..e668828ccb 100644
--- a/app/assets/javascripts/discourse/components/d-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/d-editor.js.es6
@@ -99,6 +99,7 @@ class Toolbar {
         id: "link",
         group: "insertions",
         shortcut: "K",
+        trimLeading: true,
         sendAction: event => this.context.send("showLinkModal", event)
       });
     }
@@ -956,15 +957,14 @@ export default Component.extend({
       }
 
       let linkText = "";
-      this._lastSel = this._getSelected();
+      this._lastSel = toolbarEvent.selected;
 
       if (this._lastSel) {
-        linkText = this._lastSel.value.trim();
+        linkText = this._lastSel.value;
       }
 
       showModal("insert-hyperlink").setProperties({
-        linkText: linkText,
-        _lastSel: this._lastSel,
+        linkText,
         toolbarEvent
       });
     },
diff --git a/app/assets/javascripts/discourse/controllers/insert-hyperlink.js.es6 b/app/assets/javascripts/discourse/controllers/insert-hyperlink.js.es6
index b04499456b..21ea0603f8 100644
--- a/app/assets/javascripts/discourse/controllers/insert-hyperlink.js.es6
+++ b/app/assets/javascripts/discourse/controllers/insert-hyperlink.js.es6
@@ -147,7 +147,7 @@ export default Controller.extend(ModalFunctionality, {
       const origLink = this.linkUrl;
       const linkUrl =
         origLink.indexOf("://") === -1 ? `http://${origLink}` : origLink;
-      const sel = this._lastSel;
+      const sel = this.toolbarEvent.selected;
 
       if (isEmpty(linkUrl)) {
         return;

GitHub sha: 580b2898

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: