Skip to content

Commit 06bb551

Browse files
committed
WYSIWYG: Fixed unexpected clearing of table cell styles
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
1 parent 6b68196 commit 06bb551

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

resources/js/wysiwyg/fixes.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ export function handleEmbedAlignmentChanges(editor) {
2929

3030
editor.on('FormatApply', event => {
3131
const isAlignment = event.format.startsWith('align');
32-
if (!event.node || !event.node.matches('.mce-preview-object')) {
32+
const isElement = event.node instanceof editor.dom.doc.defaultView.HTMLElement;
33+
if (!isElement || !isAlignment || !event.node.matches('.mce-preview-object')) {
3334
return;
3435
}
3536

3637
const realTarget = event.node.querySelector('iframe, video');
37-
if (isAlignment && realTarget) {
38+
if (realTarget) {
3839
const className = (editor.formatter.get(event.format)[0]?.classes || [])[0];
3940
const toAdd = !realTarget.classList.contains(className);
4041

@@ -94,10 +95,12 @@ export function handleTableCellRangeEvents(editor) {
9495
// are selected. Here we watch for clear formatting events, so some manual
9596
// cleanup can be performed.
9697
const attrsToRemove = ['class', 'style', 'width', 'height'];
97-
editor.on('FormatRemove', () => {
98-
for (const cell of selectedCells) {
99-
for (const attr of attrsToRemove) {
100-
cell.removeAttribute(attr);
98+
editor.on('ExecCommand', event => {
99+
if (event.command === 'RemoveFormat') {
100+
for (const cell of selectedCells) {
101+
for (const attr of attrsToRemove) {
102+
cell.removeAttribute(attr);
103+
}
101104
}
102105
}
103106
});

0 commit comments

Comments
 (0)