]> BookStack Code Mirror - bookstack/commitdiff
WYSIWYG: Fixed unexpected clearing of table cell styles
authorDan Brown <redacted>
Mon, 29 Apr 2024 16:44:56 +0000 (17:44 +0100)
committerDan Brown <redacted>
Mon, 29 Apr 2024 16:47:06 +0000 (17:47 +0100)
Fixes custom table cell clear-format handling since it was being called
on many format removals, not just the clear-formatting action.
This updates the code to specifically run on the RemoveFormat action
which is triggered by the clear formatting button.
Fixes #4964

resources/js/wysiwyg/fixes.js

index 7f87d4378c6c9afc3fde46c87d69122b96d84b2f..61cace66052ea53cd559738b10198e1b963b6d77 100644 (file)
@@ -29,12 +29,13 @@ export function handleEmbedAlignmentChanges(editor) {
 
     editor.on('FormatApply', event => {
         const isAlignment = event.format.startsWith('align');
-        if (!event.node || !event.node.matches('.mce-preview-object')) {
+        const isElement = event.node instanceof editor.dom.doc.defaultView.HTMLElement;
+        if (!isElement || !isAlignment || !event.node.matches('.mce-preview-object')) {
             return;
         }
 
         const realTarget = event.node.querySelector('iframe, video');
-        if (isAlignment && realTarget) {
+        if (realTarget) {
             const className = (editor.formatter.get(event.format)[0]?.classes || [])[0];
             const toAdd = !realTarget.classList.contains(className);
 
@@ -94,10 +95,12 @@ export function handleTableCellRangeEvents(editor) {
     // are selected. Here we watch for clear formatting events, so some manual
     // cleanup can be performed.
     const attrsToRemove = ['class', 'style', 'width', 'height'];
-    editor.on('FormatRemove', () => {
-        for (const cell of selectedCells) {
-            for (const attr of attrsToRemove) {
-                cell.removeAttribute(attr);
+    editor.on('ExecCommand', event => {
+        if (event.command === 'RemoveFormat') {
+            for (const cell of selectedCells) {
+                for (const attr of attrsToRemove) {
+                    cell.removeAttribute(attr);
+                }
             }
         }
     });
Morty Proxy This is a proxified and sanitized view of the page, visit original site.