Skip to content

Commit

Permalink
WYSIWYG: Fixed unexpected clearing of table cell styles
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ssddanbrown committed Apr 29, 2024
1 parent 6b68196 commit 06bb551
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions resources/js/wysiwyg/fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
}
});
Expand Down

0 comments on commit 06bb551

Please sign in to comment.