Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

experimental: Pressing Enter within an empty list item deletes the empty item (#4641)

Ivan Starkov640f9a4f2cd8
diff --git a/apps/builder/app/canvas/features/text-editor/text-editor.tsx b/apps/builder/app/canvas/features/text-editor/text-editor.tsx
index 81a01dcdf6..6746fef9db 100644
--- a/apps/builder/app/canvas/features/text-editor/text-editor.tsx
+++ b/apps/builder/app/canvas/features/text-editor/text-editor.tsx
@@ -1127,7 +1127,11 @@ const RichTextContentPluginInternal = ({
.get()
.get(rootInstanceSelector[0]);
- if (currentInstance?.component === "ListItem") {
+ const rootNodeContent = $getRoot().getTextContent().trim();
+ if (
+ currentInstance?.component === "ListItem" &&
+ rootNodeContent.length > 0
+ ) {
// Instead of creating block component we need to add a new ListItem
insertListItemAt(rootInstanceSelector);
event.preventDefault();
@@ -1183,6 +1187,16 @@ const RichTextContentPluginInternal = ({
insertTemplateAt(templateSelector, rootInstanceSelector, false);
+ if (
+ currentInstance?.component === "ListItem" &&
+ rootNodeContent.length === 0
+ ) {
+ // Pressing Enter within an empty list item deletes the empty item
+ updateWebstudioData((data) => {
+ deleteInstanceMutable(data, rootInstanceSelector);
+ });
+ }
+
event.preventDefault();
return true;
}