diff --git a/gui/src/components/mainInput/TipTapEditor/utils/insertCurrentFileContextMention.ts b/gui/src/components/mainInput/TipTapEditor/utils/insertCurrentFileContextMention.ts index 5f5284d52..fd48239ff 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/insertCurrentFileContextMention.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/insertCurrentFileContextMention.ts @@ -2,15 +2,39 @@ import { Editor } from "@tiptap/core"; import { ContextProviderDescription } from "core"; import { Mention } from "../extensions"; +function isEditorContentEmpty(editor: Editor): boolean { + const editorContent = editor.getJSON(); + + if (!editorContent.content || editorContent.content.length === 0) { + return true; + } + + const firstNode = editorContent.content[0]; + if ( + firstNode.type === "paragraph" && + (firstNode.content || []).length === 0 + ) { + return true; + } + + return false; +} + /** * inserts the current file context as a removable mention in the editor area * + * skips if there is any other content in the editor + * * uses tiptap's `create` method to create a new node under the hood */ export function insertCurrentFileContextMention( editor: Editor, contextProviders: ContextProviderDescription[], ) { + if (!isEditorContentEmpty(editor)) { + return; + } + const foundCurrentFileProvider = contextProviders.find( (provider) => provider.title === "currentFile", );