diff --git a/editor/src/components/editor/action/command-functions.ts b/editor/src/components/editor/action/command-functions.ts index bab0ffc..2a8a553 100644 --- a/editor/src/components/editor/action/command-functions.ts +++ b/editor/src/components/editor/action/command-functions.ts @@ -2,6 +2,7 @@ import { Commands, Dispatch, Extension } from "@tiptap/react"; import { Editor } from "@tiptap/core"; import { Transaction } from "prosemirror-state"; import { + ChangeForm, DefinedVariable, FacetType, OutputForm, PromptAction, @@ -80,6 +81,11 @@ export const CommandFunctions = Extension.create({ } console.info("compiledTemplate: \n\n", prompt); + if (action.changeForm == ChangeForm.DIFF) { + // @ts-ignore + editor.commands?.setTrackChangeStatus(true) + } + switch (action.outputForm) { case OutputForm.STREAMING: const response = await fetch("/api/completion/yiyan", { @@ -96,6 +102,11 @@ export const CommandFunctions = Extension.create({ editor.setEditable(true); + if (action.changeForm == ChangeForm.DIFF) { + // @ts-ignore + editor.commands?.setTrackChangeStatus(false) + } + return undefined; case OutputForm.DIFF: @@ -106,6 +117,11 @@ export const CommandFunctions = Extension.create({ }).then(it => it.text()); editor.setEditable(true); + if (action.changeForm == ChangeForm.DIFF) { + // @ts-ignore + editor.commands?.setTrackChangeStatus(false) + } + return text; default: @@ -118,6 +134,11 @@ export const CommandFunctions = Extension.create({ editor.chain().focus().insertContentAt(posInfo, msg).run(); editor.setEditable(true); + if (action.changeForm == ChangeForm.DIFF) { + // @ts-ignore + editor.commands?.setTrackChangeStatus(false) + } + return undefined; } }, diff --git a/editor/src/components/editor/intelli/menu/menu-bubble.tsx b/editor/src/components/editor/intelli/menu/menu-bubble.tsx index 49f4633..a505ab2 100644 --- a/editor/src/components/editor/intelli/menu/menu-bubble.tsx +++ b/editor/src/components/editor/intelli/menu/menu-bubble.tsx @@ -21,33 +21,6 @@ export const MenuBubble = ({ editor }: { function buildMenus(): PromptAction[] { const originMenus = editor?.commands?.getAiActions(FacetType.BUBBLE_MENU) || []; - originMenus.map((menu, index) => { - if (menu.i18Name) { - menu.name = t(menu.name) - } - - menu.action = async () => { - // @ts-ignore - const selection = editor.state.selection - let posInfo = new ActionExecutor(menu, editor).position(selection); - - if (menu.changeForm == ChangeForm.DIFF) { - // @ts-ignore - editor.commands?.setTrackChangeStatus(true) - } - - menu.outputForm = OutputForm.DIFF - const output = await editor.commands?.callLlm(menu) - - editor.chain().focus().insertContentAt(posInfo, output!!).run(); - - if (menu.changeForm == ChangeForm.DIFF) { - // @ts-ignore - editor.commands?.setTrackChangeStatus(false) - } - } - }); - return originMenus } @@ -147,7 +120,7 @@ export const MenuBubble = ({ editor }: { variant={'soft'} onClick={(event) => { setIsOpen(false); - menu.action?.(editor) + editor.chain().callLlm(menu); }} > {menu.name}