refactor(ckeditor): address requested changes

This commit is contained in:
Elian Doran 2026-03-05 19:28:52 +02:00
parent 65514a6fd7
commit 8128a8192a
No known key found for this signature in database

View File

@ -1,24 +1,15 @@
import { DifferItemAttribute, ModelDocumentFragment, ModelElement, ModelNode } from "ckeditor5";
import { CKTextEditor } from "src";
function isHeadingElement(node: ModelElement | ModelNode | ModelDocumentFragment | null): node is ModelElement {
return !!node
&& typeof (node as any).is === "function"
&& (node as any).is("element")
&& typeof (node as any).name === "string"
&& (node as any).name.startsWith("heading");
}
import type { DifferItemAttribute, Editor, ModelDocumentFragment, ModelElement, ModelNode } from "ckeditor5";
function hasHeadingAncestor(node: ModelElement | ModelNode | ModelDocumentFragment | null): boolean {
let current: ModelElement | ModelNode | ModelDocumentFragment | null = node;
while (current) {
if (isHeadingElement(current)) return true;
if (!!current && current.is('element') && (current as ModelElement).name.startsWith("heading")) return true;
current = current.parent;
}
return false;
}
export function attributeChangeAffectsHeading(change: DifferItemAttribute, editor: CKTextEditor): boolean {
export function attributeChangeAffectsHeading(change: DifferItemAttribute, editor: Editor): boolean {
if (change.type !== "attribute") return false;
// Fast checks on range boundaries