From d6fa44cc3c5f22cca53d1d5b9cacb8e194b0601a Mon Sep 17 00:00:00 2001 From: "Md. Muhtasim Fuad Fahim" Date: Sun, 13 Oct 2024 10:21:16 +0600 Subject: [PATCH] removed the second useEffect and used mergeRegister --- .../plugins/ListMaxIndentLevelPlugin/index.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts b/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts index 0d95193b4b2..c70b1094d3b 100644 --- a/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts +++ b/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts @@ -10,6 +10,7 @@ import type {ElementNode, RangeSelection} from 'lexical'; import {$getListDepth, $isListItemNode, $isListNode} from '@lexical/list'; import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; +import {mergeRegister} from '@lexical/utils'; import { $getSelection, $isElementNode, @@ -76,19 +77,19 @@ export default function ListMaxIndentLevelPlugin({ const [editor] = useLexicalComposerContext(); useEffect(() => { - return editor.registerCommand( - INDENT_CONTENT_COMMAND, - () => $shouldPreventIndent(maxDepth), - COMMAND_PRIORITY_CRITICAL, + return mergeRegister( + editor.registerCommand( + INDENT_CONTENT_COMMAND, + () => $shouldPreventIndent(maxDepth), + COMMAND_PRIORITY_CRITICAL, + ), + editor.registerCommand( + PASTE_COMMAND, + () => $shouldPreventIndent(maxDepth), + COMMAND_PRIORITY_CRITICAL, + ), ); }, [editor, maxDepth]); - useEffect(() => { - return editor.registerCommand( - PASTE_COMMAND, - () => $shouldPreventIndent(maxDepth), - COMMAND_PRIORITY_CRITICAL, - ); - }, [editor, maxDepth]); return null; }