Skip to content

Commit

Permalink
refactor: update for varible
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 2, 2023
1 parent 19f20be commit 2242128
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
21 changes: 21 additions & 0 deletions editor/src/components/editor/action/command-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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", {
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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;
}
},
Expand Down
29 changes: 1 addition & 28 deletions editor/src/components/editor/intelli/menu/menu-bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -147,7 +120,7 @@ export const MenuBubble = ({ editor }: {
variant={'soft'}
onClick={(event) => {
setIsOpen(false);
menu.action?.(editor)
editor.chain().callLlm(menu);
}}
>
{menu.name}
Expand Down

0 comments on commit 2242128

Please sign in to comment.