Elffuss BraidHub

kikocis/continue public

972ea8cfaef0 · 1.1 KiBRawPermalink
1import { Editor } from "@tiptap/core";
2import { ContextProviderDescription } from "core";
3import * as ContinueExtensions from "../extensions";
4
5/**
6 * inserts the current file context as a removable mention in the editor area
7 *
8 * uses tiptap's `create` method to create a new node under the hood
9 */
10export function insertCurrentFileContextMention(
11 editor: Editor,
12 contextProviders: ContextProviderDescription[],
13) {
14 const foundCurrentFileProvider = contextProviders.find(
15 (provider) => provider.title === "currentFile",
16 );
17
18 if (foundCurrentFileProvider) {
19 const node = editor.schema.nodes[ContinueExtensions.Mention.name].create({
20 name: foundCurrentFileProvider.displayTitle,
21 description: foundCurrentFileProvider.description,
22 id: foundCurrentFileProvider.title,
23 label: foundCurrentFileProvider.displayTitle,
24 renderInlineAs: foundCurrentFileProvider.renderInlineAs,
25 type: foundCurrentFileProvider.type,
26 itemType: "contextProvider",
27 });
28
29 editor
30 .chain()
31 .insertContent([node.toJSON(), { type: "text", text: " " }]) // add a space after the mention
32 .run();
33 }
34}