Skip to content

Commit

Permalink
Refactored findNearestListItemNode using $findMatchingParent (#5419)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrAJAY1 authored Dec 26, 2023
1 parent 7eaf70c commit a06b8a1
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/lexical-list/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type {LexicalNode, Spread} from 'lexical';

import {$findMatchingParent} from '@lexical/utils';
import invariant from 'shared/invariant';

import {
Expand Down Expand Up @@ -147,20 +148,13 @@ export function isNestedListNode(
* @param node - Node to start the search.
* @returns The first ListItemNode found, or null if none exist.
*/
// TODO: rewrite with $findMatchingParent or *nodeOfType
export function findNearestListItemNode(
node: LexicalNode,
): ListItemNode | null {
let currentNode: LexicalNode | null = node;

while (currentNode !== null) {
if ($isListItemNode(currentNode)) {
return currentNode;
}
currentNode = currentNode.getParent();
}

return null;
const matchingParent = $findMatchingParent(node, (parent) =>
$isListItemNode(parent),
);
return matchingParent as ListItemNode | null;
}

/**
Expand Down

2 comments on commit a06b8a1

@vercel
Copy link

@vercel vercel bot commented on a06b8a1 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-fbopensource.vercel.app
lexicaljs.com
lexical-git-main-fbopensource.vercel.app
lexical.dev
lexicaljs.org
www.lexical.dev

@vercel
Copy link

@vercel vercel bot commented on a06b8a1 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

playground.lexical.dev
lexical-playground.vercel.app
lexical-playground-git-main-fbopensource.vercel.app
lexical-playground-fbopensource.vercel.app

Please sign in to comment.