Skip to content

Commit

Permalink
fix empty editor formatting gets saved as draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbura committed Oct 17, 2023
1 parent 7ecceed commit 320c202
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app/organisms/room/RoomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -182,6 +185,12 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
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);
Expand Down

0 comments on commit 320c202

Please sign in to comment.