DEV: add useBlockMode option for toolbar button text selection

DEV: add useBlockMode option for toolbar button text selection

Allows buttons to switch selection to block mode if needed.

diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index ed6ced3..ccafc0b 100644
--- a/app/assets/javascripts/discourse/components/d-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/d-editor.js.es6
@@ -601,7 +601,13 @@ export default Ember.Component.extend({
       this.set("value", `${pre}${hval}${example}${tail}${post}`);
       this._selectText(pre.length + hlen, example.length);
     } else if (opts && !opts.multiline) {
-      const [hval, hlen] = getHead(head);
+      let [hval, hlen] = getHead(head);
+
+      if (opts.useBlockMode && sel.value.split("\n").length > 1) {
+        hval += "\n";
+        hlen += 1;
+        tail = `\n${tail}`;
+      }
 
       if (pre.slice(-hlen) === hval && post.slice(0, tail.length) === tail) {
         this.set(

GitHub sha: 6e3e0685

1 Like

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