fix: allow enter key to create new list items in editor (#22001)
* fix: allow enter key to create new list items in editor * remove: unnecessary priority set to low * remove: unnecessary priority set to low --------- Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: Eunjae Lee <[email protected]>
This commit is contained in:
1 file changed
+7
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { $isListItemNode } from "@lexical/list";
|
||||
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
||||
import {
|
||||
$createLineBreakNode,
|
||||
@@ -19,6 +20,12 @@ const CustomEnterKeyPlugin = () => {
|
||||
(event: any) => {
|
||||
const selection = $getSelection();
|
||||
if ($isRangeSelection(selection)) {
|
||||
const anchorNode = selection.anchor.getNode();
|
||||
|
||||
if ($isListItemNode(anchorNode) || $isListItemNode(anchorNode.getParent())) {
|
||||
return false; // Don't prevent default - let Lexical handle list behavior
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
const lineBreakNode = $createLineBreakNode();
|
||||
selection.insertNodes([lineBreakNode]);
|
||||
|
||||
Reference in new issue
Block a user