mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-25 11:45:58 +00:00
Updated WYSIWYG callout shortcut to handle child elems
- Will now search for a callout on/above the selected node rather than only using the selected node. - Issues previously where callout shortcut would not cycle if called when child formatting was currently selected inside the callout. For #2061
This commit is contained in:
parent
2ec4ad1181
commit
468fec80de
@ -98,21 +98,15 @@ function registerEditorShortcuts(editor) {
|
|||||||
|
|
||||||
// Loop through callout styles
|
// Loop through callout styles
|
||||||
editor.shortcuts.add('meta+9', '', function() {
|
editor.shortcuts.add('meta+9', '', function() {
|
||||||
let selectedNode = editor.selection.getNode();
|
const selectedNode = editor.selection.getNode();
|
||||||
let formats = ['info', 'success', 'warning', 'danger'];
|
const callout = selectedNode ? selectedNode.closest('.callout') : null;
|
||||||
|
|
||||||
if (!selectedNode || selectedNode.className.indexOf('callout') === -1) {
|
const formats = ['info', 'success', 'warning', 'danger'];
|
||||||
editor.formatter.apply('calloutinfo');
|
const currentFormatIndex = formats.findIndex(format => callout && callout.classList.contains(format));
|
||||||
return;
|
const newFormatIndex = (currentFormatIndex + 1) % formats.length;
|
||||||
}
|
const newFormat = formats[newFormatIndex];
|
||||||
|
|
||||||
for (let i = 0; i < formats.length; i++) {
|
editor.formatter.apply('callout' + newFormat);
|
||||||
if (selectedNode.className.indexOf(formats[i]) === -1) continue;
|
|
||||||
let newFormat = (i === formats.length -1) ? formats[0] : formats[i+1];
|
|
||||||
editor.formatter.apply('callout' + newFormat);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editor.formatter.apply('p');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user