diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 0757d60f8d7..83675997432 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -441,7 +441,7 @@ export default Ember.Component.extend({ }).join("\n"); }, - _applySurround(sel, head, tail, exampleKey) { + _applySurround(sel, head, tail, exampleKey, opts) { const pre = sel.pre; const post = sel.post; @@ -453,6 +453,16 @@ export default Ember.Component.extend({ const example = I18n.t(`composer.${exampleKey}`); 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); + + if (pre.slice(-hlen) === hval && post.slice(0, tail.length) === tail) { + this.set('value', `${pre.slice(0, -hlen)}${sel.value}${post.slice(tail.length)}`); + this._selectText(sel.start - hlen, sel.value.length); + } else { + this.set('value', `${pre}${hval}${sel.value}${tail}${post}`); + this._selectText(sel.start + hlen, sel.value.length); + } } else { const lines = sel.value.split("\n"); @@ -521,7 +531,7 @@ export default Ember.Component.extend({ const toolbarEvent = { selected, selectText: (from, length) => this._selectText(from, length), - applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey), + applySurround: (head, tail, exampleKey, opts) => this._applySurround(selected, head, tail, exampleKey, opts), applyList: (head, exampleKey) => this._applyList(selected, head, exampleKey), addText: text => this._addText(selected, text), getText: () => this.get('value'), diff --git a/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 b/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 index e7164334cef..ca9cbbda66a 100644 --- a/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 +++ b/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6 @@ -18,8 +18,9 @@ function initializeDetails(api) { this.get("toolbarEvent").applySurround( `[details=${I18n.t("composer.details_title")}]`, "[/details]", - "details_text") - ; + "details_text", + { multiline: false } + ); } } });