7 LexicalEditor, TextFormatType
9 import {LexicalElementNodeCreator, LexicalNodeMatcher} from "./nodes";
10 import {$getNearestBlockElementAncestorOrThrow} from "@lexical/utils";
11 import {$setBlocksType} from "@lexical/selection";
12 import {TextNodeThemeClasses} from "lexical/LexicalEditor";
14 export function selectionContainsNodeType(selection: BaseSelection|null, matcher: LexicalNodeMatcher): boolean {
19 for (const node of selection.getNodes()) {
24 for (const parent of node.getParents()) {
25 if (matcher(parent)) {
34 export function selectionContainsTextFormat(selection: BaseSelection|null, format: TextFormatType): boolean {
39 for (const node of selection.getNodes()) {
40 if ($isTextNode(node) && node.hasFormat(format)) {
48 export function toggleSelectionBlockNodeType(editor: LexicalEditor, matcher: LexicalNodeMatcher, creator: LexicalElementNodeCreator) {
50 const selection = $getSelection();
51 const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null;
52 if (selection && matcher(blockElement)) {
53 $setBlocksType(selection, $createParagraphNode);
55 $setBlocksType(selection, creator);