✨ option to configure how context provider is displayed inline
This commit is contained in:
parent
7ad086a0fe
commit
f8e968c037
6 changed files with 24 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ class CodebaseContextProvider extends BaseContextProvider {
|
|||
displayTitle: "Codebase",
|
||||
description: "Automatically find relevant files",
|
||||
type: "normal",
|
||||
renderInlineAs: "",
|
||||
};
|
||||
|
||||
async getContextItems(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class CustomContextProviderClass implements IContextProvider {
|
|||
displayTitle: this.custom.displayTitle || this.custom.title,
|
||||
description: this.custom.description || "",
|
||||
type: this.custom.type || "normal",
|
||||
renderInlineAs: this.custom.renderInlineAs,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -97,6 +97,7 @@ export interface ContextProviderDescription {
|
|||
title: string;
|
||||
displayTitle: string;
|
||||
description: string;
|
||||
renderInlineAs?: string;
|
||||
type: ContextProviderType;
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +117,7 @@ export interface CustomContextProvider {
|
|||
title: string;
|
||||
displayTitle?: string;
|
||||
description?: string;
|
||||
renderInlineAs?: string;
|
||||
type?: ContextProviderType;
|
||||
getContextItems(
|
||||
query: string,
|
||||
|
|
|
|||
|
|
@ -106,6 +106,20 @@ export const Mention = Node.create<MentionOptions>({
|
|||
},
|
||||
},
|
||||
|
||||
renderInlineAs: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute("data-renderInlineAs"),
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.renderInlineAs) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
"data-renderInlineAs": attributes.renderInlineAs,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
query: {
|
||||
default: null,
|
||||
parseHTML: (element) => element.getAttribute("data-query"),
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ export function getMentionSuggestion(
|
|||
id: provider.title,
|
||||
title: provider.displayTitle,
|
||||
label: provider.displayTitle,
|
||||
renderInlineAs: provider.renderInlineAs,
|
||||
type: "contextProvider" as ComboBoxItemType,
|
||||
contextProvider: provider,
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -151,11 +151,12 @@ function resolveParagraph(p: JSONContent): [string, MentionAttrs[], string] {
|
|||
let slashCommand = undefined;
|
||||
for (const child of p.content || []) {
|
||||
if (child.type === "text") {
|
||||
text += child.text;
|
||||
text += text === "" ? child.text.trimStart() : child.text;
|
||||
} else if (child.type === "mention") {
|
||||
if (!["codebase"].includes(child.attrs.id)) {
|
||||
text += child.attrs.label;
|
||||
}
|
||||
text +=
|
||||
typeof child.attrs.renderInlineAs === "string"
|
||||
? child.attrs.renderInlineAs
|
||||
: child.attrs.label;
|
||||
contextItems.push(child.attrs);
|
||||
} else if (child.type === "slashcommand") {
|
||||
if (typeof slashCommand === "undefined") {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue