🐛 Fix applyStylesTo entire selection

This commit is contained in:
Aitor Moreno
2025-12-03 11:07:33 +01:00
parent 9f567c3bf4
commit 0d21e52068
2 changed files with 7 additions and 6 deletions

View File

@@ -339,14 +339,15 @@ export function setStylesFromObject(element, allowedStyles, styleObject) {
continue; continue;
} }
let styleValue = styleObject[styleName]; let styleValue = styleObject[styleName];
if (!styleValue)
continue;
if (styleName === "font-family") { if (styleName === "font-family") {
styleValue = sanitizeFontFamily(styleValue); styleValue = sanitizeFontFamily(styleValue);
} }
if (styleValue) {
setStyle(element, styleName, styleValue, styleUnit); setStyle(element, styleName, styleValue, styleUnit);
} }
}
return element; return element;
} }

View File

@@ -1974,7 +1974,7 @@ export class SelectionController extends EventTarget {
// the styles are applied to the current caret // the styles are applied to the current caret
else if ( else if (
this.startOffset === this.endOffset && this.startOffset === this.endOffset &&
this.endOffset === endNode.nodeValue.length this.endOffset === endNode.nodeValue?.length
) { ) {
const newTextSpan = createVoidTextSpan(newStyles); const newTextSpan = createVoidTextSpan(newStyles);
this.endTextSpan.after(newTextSpan); this.endTextSpan.after(newTextSpan);
@@ -2026,14 +2026,14 @@ export class SelectionController extends EventTarget {
(this.#textNodeIterator.currentNode !== startNode && (this.#textNodeIterator.currentNode !== startNode &&
this.#textNodeIterator.currentNode !== endNode) || this.#textNodeIterator.currentNode !== endNode) ||
(this.#textNodeIterator.currentNode === endNode && (this.#textNodeIterator.currentNode === endNode &&
endOffset === endNode.nodeValue.length) endOffset === endNode.nodeValue?.length)
) { ) {
setTextSpanStyles(textSpan, newStyles); setTextSpanStyles(textSpan, newStyles);
// If we're at end node // If we're at end node
} else if ( } else if (
this.#textNodeIterator.currentNode === endNode && this.#textNodeIterator.currentNode === endNode &&
endOffset < endNode.nodeValue.length && endOffset < endNode.nodeValue?.length &&
endOffset > 0 endOffset > 0
) { ) {
const newTextSpan = splitTextSpan(textSpan, endOffset); const newTextSpan = splitTextSpan(textSpan, endOffset);