diff --git a/apps/code/src/renderer/features/message-editor/tiptap/CommandMention.ts b/apps/code/src/renderer/features/message-editor/tiptap/CommandMention.ts index 1c68e308c..4856668be 100644 --- a/apps/code/src/renderer/features/message-editor/tiptap/CommandMention.ts +++ b/apps/code/src/renderer/features/message-editor/tiptap/CommandMention.ts @@ -23,9 +23,11 @@ function createSuggestion( render: () => { let component: ReactRenderer | null = null; let popup: TippyInstance | null = null; + let dismissed = false; return { onStart: (props) => { + dismissed = false; component = new ReactRenderer(SuggestionList, { props: { items: props.items, @@ -51,6 +53,7 @@ function createSuggestion( }, onUpdate: (props) => { + if (props.items.length > 0) dismissed = false; component?.updateProps({ items: props.items, command: props.command, @@ -67,9 +70,12 @@ function createSuggestion( if (props.event.key === "Escape") { props.event.stopPropagation(); popup?.hide(); + dismissed = true; return true; } + if (dismissed) return false; + return component?.ref?.onKeyDown(props) ?? false; }, diff --git a/apps/code/src/renderer/features/message-editor/tiptap/FileMention.ts b/apps/code/src/renderer/features/message-editor/tiptap/FileMention.ts index 3ba26bed4..440fd2d28 100644 --- a/apps/code/src/renderer/features/message-editor/tiptap/FileMention.ts +++ b/apps/code/src/renderer/features/message-editor/tiptap/FileMention.ts @@ -27,9 +27,11 @@ function createSuggestion( render: () => { let component: ReactRenderer | null = null; let popup: TippyInstance | null = null; + let dismissed = false; return { onStart: (props) => { + dismissed = false; const items = props.items.length > 0 ? props.items : lastItems; component = new ReactRenderer(SuggestionList, { props: { @@ -56,6 +58,7 @@ function createSuggestion( }, onUpdate: (props) => { + if (props.items.length > 0) dismissed = false; const items = props.items.length > 0 ? props.items : lastItems; component?.updateProps({ items, @@ -73,9 +76,12 @@ function createSuggestion( if (props.event.key === "Escape") { props.event.stopPropagation(); popup?.hide(); + dismissed = true; return true; } + if (dismissed) return false; + return component?.ref?.onKeyDown(props) ?? false; }, diff --git a/apps/code/src/renderer/features/message-editor/tiptap/SuggestionList.tsx b/apps/code/src/renderer/features/message-editor/tiptap/SuggestionList.tsx index aed1a863e..3d4622f84 100644 --- a/apps/code/src/renderer/features/message-editor/tiptap/SuggestionList.tsx +++ b/apps/code/src/renderer/features/message-editor/tiptap/SuggestionList.tsx @@ -57,8 +57,11 @@ export const SuggestionList = forwardRef< return true; } if (event.key === "Enter" || event.key === "Tab") { - if (items[selectedIndex]) command(items[selectedIndex]); - return true; + if (items[selectedIndex]) { + command(items[selectedIndex]); + return true; + } + return false; } return false; }, diff --git a/apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts b/apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts index 3fc67d1c2..85165613e 100644 --- a/apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts +++ b/apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts @@ -187,9 +187,11 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) { if (isSubmitKey) { if (!view.editable || submitDisabledRef.current) return false; - const suggestionPopup = - document.querySelector("[data-tippy-root]"); - if (suggestionPopup) return false; + // tippy.js sets data-state="hidden" when hiding via .hide() + const visibleSuggestion = document.querySelector( + "[data-tippy-root] .tippy-box:not([data-state='hidden'])", + ); + if (visibleSuggestion) return false; event.preventDefault(); historyActions.reset(); submitRef.current();