From 640f9a4f2cd89b84946c6b3ccebf10c8ed14323f Mon Sep 17 00:00:00 2001 From: Ivan Starkov Date: Sun, 22 Dec 2024 19:33:15 +0300 Subject: [PATCH] experimental: Pressing Enter within an empty list item deletes the empty item (#4641) ## Description ref #4595 ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file --- .../canvas/features/text-editor/text-editor.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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; }