Changesets · Branches · Tags · Compare
| Changeset | afb534f77e37312546ee8985592e606f106c2f63882d967f0d8f4bcbe7ccd525 |
|---|---|
| Author | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-07-11 10:20 +05:30 |
| Committer | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-07-11 10:20 +05:30 |
| Parents | d6d753418588 |
1 file changed
modified gui/src/components/mainInput/TipTapEditor/utils/insertCurrentFileContextMention.ts +24 −0
| @@ -2,15 +2,39 @@ | ||
| 2 | 2 | import { ContextProviderDescription } from "core"; |
| 3 | 3 | import { Mention } from "../extensions"; |
| 4 | 4 | |
| 5 | +function isEditorContentEmpty(editor: Editor): boolean { | |
| 6 | + const editorContent = editor.getJSON(); | |
| 7 | + | |
| 8 | + if (!editorContent.content || editorContent.content.length === 0) { | |
| 9 | + return true; | |
| 10 | + } | |
| 11 | + | |
| 12 | + const firstNode = editorContent.content[0]; | |
| 13 | + if ( | |
| 14 | + firstNode.type === "paragraph" && | |
| 15 | + (firstNode.content || []).length === 0 | |
| 16 | + ) { | |
| 17 | + return true; | |
| 18 | + } | |
| 19 | + | |
| 20 | + return false; | |
| 21 | +} | |
| 22 | + | |
| 5 | 23 | /** |
| 6 | 24 | * inserts the current file context as a removable mention in the editor area |
| 7 | 25 | * |
| 26 | + * skips if there is any other content in the editor | |
| 27 | + * | |
| 8 | 28 | * uses tiptap's `create` method to create a new node under the hood |
| 9 | 29 | */ |
| 10 | 30 | export function insertCurrentFileContextMention( |
| 11 | 31 | editor: Editor, |
| 12 | 32 | contextProviders: ContextProviderDescription[], |
| 13 | 33 | ) { |
| 34 | + if (!isEditorContentEmpty(editor)) { | |
| 35 | + return; | |
| 36 | + } | |
| 37 | + | |
| 14 | 38 | const foundCurrentFileProvider = contextProviders.find( |
| 15 | 39 | (provider) => provider.title === "currentFile", |
| 16 | 40 | ); |