From 94413018f6b61a5a2082ce5a2ecd13f33752a58c Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 5 Dec 2023 19:07:55 +0530 Subject: [PATCH] chore: add newlines before/after table if required --- .../Components/SuperEditor/Plugins/TablePlugin.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/TablePlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/TablePlugin.tsx index 90dd7ef9e..e65cdc865 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/TablePlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/TablePlugin.tsx @@ -7,7 +7,7 @@ */ import { INSERT_TABLE_COMMAND, TableNode, TableRowNode } from '@lexical/table' -import { LexicalEditor } from 'lexical' +import { $createParagraphNode, LexicalEditor } from 'lexical' import { useEffect, useState } from 'react' import Button from '../Lexical/UI/Button' import { DialogActions } from '../Lexical/UI/Dialog' @@ -62,6 +62,13 @@ export function RemoveBrokenTablesPlugin() { if (!node.getFirstChild()) { node.remove() } + const hasNextSibling = !!node.getNextSibling() + const hasPreviousSibling = !!node.getPreviousSibling() + if (!hasNextSibling) { + node.insertAfter($createParagraphNode()) + } else if (!hasPreviousSibling) { + node.insertBefore($createParagraphNode()) + } }), ) }, [editor])