$createNodeSelection,
$createParagraphNode, $createRangeSelection,
$getRoot,
- $getSelection, $isDecoratorNode,
+ $getSelection, $isBlockElementNode, $isDecoratorNode,
$isElementNode,
$isTextNode,
$setSelection,
}
export function $insertNewBlockNodesAtSelection(nodes: LexicalNode[], insertAfter: boolean = true) {
- const selection = $getSelection();
- const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null;
+ const selectionNodes = $getSelection()?.getNodes() || [];
+ const blockElement = selectionNodes.length > 0 ? $getNearestNodeBlockParent(selectionNodes[0]) : null;
if (blockElement) {
if (insertAfter) {
return false;
}
+export function $selectionContainsDirection(selection: BaseSelection | null, direction: 'rtl'|'ltr'): boolean {
+
+ const nodes = [
+ ...(selection?.getNodes() || []),
+ ...$getBlockElementNodesInSelection(selection)
+ ];
+
+ for (const node of nodes) {
+ if ($isBlockElementNode(node) && node.getDirection() === direction) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
export function $getBlockElementNodesInSelection(selection: BaseSelection | null): ElementNode[] {
if (!selection) {
return [];