From 320c202b5c1aa6a41a31c3dbe0b3d7c373a91922 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 17 Oct 2023 19:54:06 +0530 Subject: [PATCH] fix empty editor formatting gets saved as draft --- src/app/organisms/room/RoomInput.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/app/organisms/room/RoomInput.tsx b/src/app/organisms/room/RoomInput.tsx index 71a8f85e71..6efbcfd188 100644 --- a/src/app/organisms/room/RoomInput.tsx +++ b/src/app/organisms/room/RoomInput.tsx @@ -54,6 +54,9 @@ import { isEmptyEditor, getBeginCommand, trimCommand, + removeAllMark, + toggleBlock, + BlockType, } from '../../components/editor'; import { EmojiBoard, EmojiBoardTab } from '../../components/emoji-board'; import { UseStateProvider } from '../../components/UseStateProvider'; @@ -182,6 +185,12 @@ export const RoomInput = forwardRef( useEffect(() => { if (!mobileOrTablet()) ReactEditor.focus(editor); return () => { + if (isEmptyEditor(editor)) { + // prevent empty editor formatting from + // saving in draft + removeAllMark(editor); + toggleBlock(editor, BlockType.Paragraph); + } const parsedDraft = JSON.parse(JSON.stringify(editor.children)); setMsgDraft(parsedDraft); resetEditor(editor);