From b3264e28241698a986f656b4c5de31ea33583d21 Mon Sep 17 00:00:00 2001 From: Kevin On <40454531+kevin-on@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:15:10 +0900 Subject: [PATCH] Close popover when the content is cleared (#77) --- .../template/CreateTemplatePopoverPlugin.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/chat-view/chat-input/plugins/template/CreateTemplatePopoverPlugin.tsx b/src/components/chat-view/chat-input/plugins/template/CreateTemplatePopoverPlugin.tsx index a36157e..5449bab 100644 --- a/src/components/chat-view/chat-input/plugins/template/CreateTemplatePopoverPlugin.tsx +++ b/src/components/chat-view/chat-input/plugins/template/CreateTemplatePopoverPlugin.tsx @@ -88,6 +88,20 @@ export default function CreateTemplatePopoverPlugin({ } }, [editor, updatePopoverPosition]) + useEffect(() => { + // Update popover position when the content is cleared + // (Selection change event doesn't fire in this case) + if (!isPopoverOpen) return + const removeTextContentChangeListener = editor.registerTextContentListener( + () => { + updatePopoverPosition() + }, + ) + return () => { + removeTextContentChangeListener() + } + }, [editor, isPopoverOpen, updatePopoverPosition]) + useEffect(() => { if (!contentEditableElement) return const handleScroll = () => {