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
This commit is contained in:
Dan Brown 2024-04-29 17:44:56 +01:00
parent 6b681961e5
commit 06bb55184c
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View 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);
}
}
}
});