mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-23 11:52:59 +02:00
Desktop: Fixes #2560: Add toggling functionality for bold, italics and code in Editor Toolbar (#2565)
* Add toggling functionality for bold, italics and code in Editor toolbar * Shorten code
This commit is contained in:
parent
b31721b836
commit
67e5451c7c
@ -1504,12 +1504,29 @@ class NoteTextComponent extends React.Component {
|
|||||||
this.scheduleSave();
|
this.scheduleSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleWrapSelection(strings1, strings2, defaultText) {
|
||||||
|
const selection = this.textOffsetSelection();
|
||||||
|
let string = this.state.note.body.substr(selection.start, selection.end - selection.start);
|
||||||
|
let replaced = false;
|
||||||
|
for (var i = 0; i < strings1.length; i++) {
|
||||||
|
if (string.startsWith(strings1[i]) && string.endsWith(strings1[i])) {
|
||||||
|
this.wrapSelectionWithStrings('', '', '', string.substr(strings1[i].length, selection.end - selection.start - (2 * strings1[i].length)));
|
||||||
|
replaced = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!replaced) {
|
||||||
|
this.wrapSelectionWithStrings(strings1[0], strings2[0], defaultText);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
commandTextBold() {
|
commandTextBold() {
|
||||||
this.wrapSelectionWithStrings('**', '**', _('strong text'));
|
this.toggleWrapSelection(['**'], ['**'], _('strong text'));
|
||||||
}
|
}
|
||||||
|
|
||||||
commandTextItalic() {
|
commandTextItalic() {
|
||||||
this.wrapSelectionWithStrings('*', '*', _('emphasized text'));
|
this.toggleWrapSelection(['*', '_'], ['*', '_'], _('emphasized text'));
|
||||||
}
|
}
|
||||||
|
|
||||||
commandDateTime() {
|
commandDateTime() {
|
||||||
@ -1525,9 +1542,13 @@ class NoteTextComponent extends React.Component {
|
|||||||
|
|
||||||
if (match && match.length > 0) {
|
if (match && match.length > 0) {
|
||||||
// Follow the same newline style
|
// Follow the same newline style
|
||||||
this.wrapSelectionWithStrings(`\`\`\`${match[0]}`, `${match[0]}\`\`\``);
|
if (string.startsWith('```') && string.endsWith('```')) {
|
||||||
|
this.wrapSelectionWithStrings('', '', '', string.substr(4, selection.end - selection.start - 8));
|
||||||
} else {
|
} else {
|
||||||
this.wrapSelectionWithStrings('`', '`');
|
this.wrapSelectionWithStrings(`\`\`\`${match[0]}`, `${match[0]}\`\`\``);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.toggleWrapSelection(['`'], ['`'], '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user