From dd65e784311da0628d900977952f828e45646843 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 10 Mar 2016 23:54:33 +1100 Subject: [PATCH] only trim leading spaces for italic and bold --- .../discourse/components/d-editor.js.es6 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index d04e3f7547d..8c3548472c1 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -37,6 +37,7 @@ class Toolbar { ]; this.addButton({ + trimLeading: true, id: 'bold', group: 'fontStyles', shortcut: 'B', @@ -44,6 +45,7 @@ class Toolbar { }); this.addButton({ + trimLeading: true, id: 'italic', group: 'fontStyles', shortcut: 'I', @@ -134,7 +136,8 @@ class Toolbar { className: button.className || button.id, icon: button.icon || button.id, action: button.action || 'toolbarButton', - perform: button.perform || Ember.K + perform: button.perform || Ember.K, + trimLeading: button.trimLeading }; if (button.sendAction) { @@ -355,7 +358,7 @@ export default Ember.Component.extend({ }); }, - _getSelected() { + _getSelected(trimLeading) { if (!this.get('ready')) { return; } const textarea = this.$('textarea.d-editor-input')[0]; @@ -368,9 +371,11 @@ export default Ember.Component.extend({ end--; } - // trim leading spaces cause ** test** would be invalid - while(end > start && /\s/.test(value.charAt(start))) { - start++; + if (trimLeading) { + // trim leading spaces cause ** test** would be invalid + while(end > start && /\s/.test(value.charAt(start))) { + start++; + } } const selVal = value.substring(start, end); @@ -492,7 +497,7 @@ export default Ember.Component.extend({ actions: { toolbarButton(button) { - const selected = this._getSelected(); + const selected = this._getSelected(button.trimLeading); const toolbarEvent = { selected, applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey),