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 <81948346+anikdhabal@users.noreply.github.com>
Co-authored-by: Eunjae Lee <hey@eunjae.dev>
This commit is contained in:
ddoemonn
2025-07-09 09:39:08 +00:00
committed by GitHub
co-authored by Anik Dhabal Babu Eunjae Lee
parent 19563aa697
commit 59b55e40b5
@@ -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]);