From 468fec80de7e32d2881eab2d7f7c40a2df872956 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 26 Apr 2020 09:26:41 +0100 Subject: [PATCH] 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 --- resources/js/components/wysiwyg-editor.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/resources/js/components/wysiwyg-editor.js b/resources/js/components/wysiwyg-editor.js index b8ce901ca..9ed00c078 100644 --- a/resources/js/components/wysiwyg-editor.js +++ b/resources/js/components/wysiwyg-editor.js @@ -98,21 +98,15 @@ function registerEditorShortcuts(editor) { // Loop through callout styles editor.shortcuts.add('meta+9', '', function() { - let selectedNode = editor.selection.getNode(); - let formats = ['info', 'success', 'warning', 'danger']; + const selectedNode = editor.selection.getNode(); + const callout = selectedNode ? selectedNode.closest('.callout') : null; - if (!selectedNode || selectedNode.className.indexOf('callout') === -1) { - editor.formatter.apply('calloutinfo'); - return; - } + const formats = ['info', 'success', 'warning', 'danger']; + const currentFormatIndex = formats.findIndex(format => callout && callout.classList.contains(format)); + const newFormatIndex = (currentFormatIndex + 1) % formats.length; + const newFormat = formats[newFormatIndex]; - for (let i = 0; i < formats.length; i++) { - 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'); + editor.formatter.apply('callout' + newFormat); }); }