skip current file addition when there is content in editor
This commit is contained in:
parent
5e253c0e14
commit
dfbc0253b2
1 changed files with 24 additions and 0 deletions
|
|
@ -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",
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue