skip current file addition when there is content in editor

This commit is contained in:
uinstinct 2025-07-11 10:20:48 +05:30
parent 5e253c0e14
commit dfbc0253b2

View file

@ -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",
);