From 3e1e0ea9bdfe2aebf4e222b21f8348001e1bc8cb Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 7 Apr 2025 10:40:55 -0700 Subject: [PATCH] Update editorConfig.ts --- .../TipTapEditor/utils/editorConfig.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 8addede87..e50769ac8 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -1,4 +1,4 @@ -import { Editor } from "@tiptap/core"; +import { Editor, JSONContent } from "@tiptap/core"; import Document from "@tiptap/extension-document"; import History from "@tiptap/extension-history"; import Image from "@tiptap/extension-image"; @@ -48,6 +48,28 @@ export function getPlaceholderText( : "Ask a follow-up"; } +/** + * Checks if the editor content is valid for submission. + * A valid submission can contain either text content or prompt/code blocks + * + * @param json The editor JSON content + * @returns true if the content is valid for submission, false otherwise + */ +export function hasValidEditorContent(json: JSONContent): boolean { + // Check for prompt or code blocks + const hasPromptOrCodeBlock = json.content?.some( + (c) => + c.type === ContinueExtensions.PromptBlock.name || + c.type === ContinueExtensions.CodeBlock.name, + ); + + // Check for text content + const hasTextContent = json.content?.some((c) => c.content); + + // Content is valid if it has either text or special blocks + return hasTextContent || hasPromptOrCodeBlock || false; +} + /** * This function is called only once, so we need to use refs to pass in the latest values */ @@ -367,8 +389,8 @@ export function createEditorConfig(options: { const json = editor.getJSON(); - // Don't do anything if input box is empty - if (!json.content?.some((c) => c.content)) { + // Don't do anything if input box doesn't have valid content + if (!hasValidEditorContent(json)) { return; }