mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
only trim leading spaces for italic and bold
This commit is contained in:
parent
7be90a885c
commit
dd65e78431
1 changed files with 11 additions and 6 deletions
|
@ -37,6 +37,7 @@ class Toolbar {
|
||||||
];
|
];
|
||||||
|
|
||||||
this.addButton({
|
this.addButton({
|
||||||
|
trimLeading: true,
|
||||||
id: 'bold',
|
id: 'bold',
|
||||||
group: 'fontStyles',
|
group: 'fontStyles',
|
||||||
shortcut: 'B',
|
shortcut: 'B',
|
||||||
|
@ -44,6 +45,7 @@ class Toolbar {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addButton({
|
this.addButton({
|
||||||
|
trimLeading: true,
|
||||||
id: 'italic',
|
id: 'italic',
|
||||||
group: 'fontStyles',
|
group: 'fontStyles',
|
||||||
shortcut: 'I',
|
shortcut: 'I',
|
||||||
|
@ -134,7 +136,8 @@ class Toolbar {
|
||||||
className: button.className || button.id,
|
className: button.className || button.id,
|
||||||
icon: button.icon || button.id,
|
icon: button.icon || button.id,
|
||||||
action: button.action || 'toolbarButton',
|
action: button.action || 'toolbarButton',
|
||||||
perform: button.perform || Ember.K
|
perform: button.perform || Ember.K,
|
||||||
|
trimLeading: button.trimLeading
|
||||||
};
|
};
|
||||||
|
|
||||||
if (button.sendAction) {
|
if (button.sendAction) {
|
||||||
|
@ -355,7 +358,7 @@ export default Ember.Component.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_getSelected() {
|
_getSelected(trimLeading) {
|
||||||
if (!this.get('ready')) { return; }
|
if (!this.get('ready')) { return; }
|
||||||
|
|
||||||
const textarea = this.$('textarea.d-editor-input')[0];
|
const textarea = this.$('textarea.d-editor-input')[0];
|
||||||
|
@ -368,10 +371,12 @@ export default Ember.Component.extend({
|
||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (trimLeading) {
|
||||||
// trim leading spaces cause ** test** would be invalid
|
// trim leading spaces cause ** test** would be invalid
|
||||||
while(end > start && /\s/.test(value.charAt(start))) {
|
while(end > start && /\s/.test(value.charAt(start))) {
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const selVal = value.substring(start, end);
|
const selVal = value.substring(start, end);
|
||||||
const pre = value.slice(0, start);
|
const pre = value.slice(0, start);
|
||||||
|
@ -492,7 +497,7 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
toolbarButton(button) {
|
toolbarButton(button) {
|
||||||
const selected = this._getSelected();
|
const selected = this._getSelected(button.trimLeading);
|
||||||
const toolbarEvent = {
|
const toolbarEvent = {
|
||||||
selected,
|
selected,
|
||||||
applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey),
|
applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey),
|
||||||
|
|
Loading…
Reference in a new issue