@@ -2,6 +2,7 @@ import { Commands, Dispatch, Extension } from "@tiptap/react";
2
2
import { Editor } from "@tiptap/core" ;
3
3
import { Transaction } from "prosemirror-state" ;
4
4
import {
5
+ DefinedVariable ,
5
6
FacetType , OutputForm ,
6
7
PromptAction ,
7
8
} from "@/types/custom-action.type" ;
@@ -56,6 +57,7 @@ export const CommandFunctions = Extension.create({
56
57
( action : PromptAction ) =>
57
58
async ( { tr, commands, editor } : { tr : Transaction ; commands : Commands , editor : Editor } ) => {
58
59
// do execute action
60
+ editor . setEditable ( false )
59
61
const actionExecutor = new ActionExecutor ( action , editor ) ;
60
62
actionExecutor . compile ( ) ;
61
63
let prompt = action . compiledTemplate ;
@@ -78,13 +80,16 @@ export const CommandFunctions = Extension.create({
78
80
}
79
81
} ) ) ;
80
82
83
+ editor . setEditable ( true ) ;
81
84
return undefined ;
82
85
83
86
case OutputForm . TEXT :
84
87
const text = await fetch ( "/api/completion/yiyan" , {
85
88
method : "POST" ,
86
89
body : JSON . stringify ( { prompt : prompt } ) ,
87
90
} ) . then ( it => it . text ( ) ) ;
91
+
92
+ editor . setEditable ( true ) ;
88
93
return text ;
89
94
90
95
default :
@@ -95,6 +100,8 @@ export const CommandFunctions = Extension.create({
95
100
96
101
const posInfo = actionExecutor . position ( editor . state . selection ) ;
97
102
editor . chain ( ) . focus ( ) . insertContentAt ( posInfo , msg ) . run ( ) ;
103
+
104
+ editor . setEditable ( true ) ;
98
105
return undefined ;
99
106
}
100
107
} ,
@@ -111,12 +118,14 @@ export const CommandFunctions = Extension.create({
111
118
callQuickAction :
112
119
( text : string ) =>
113
120
( { editor } : { editor : Editor } ) => {
121
+ editor . setEditable ( false ) ;
114
122
editor . commands . callLlm ( < PromptAction > {
115
123
name : text ,
116
- template : text ,
124
+ template : `You are an assistant to help user write article. Here is user command:` + text + `\n Here is some content ###Article title: {{ ${ DefinedVariable . TITLE } }}, Before Content: {{ ${ DefinedVariable . BEFORE_CURSOR } }}###` ,
117
125
facetType : FacetType . QUICK_INSERT ,
118
126
outputForm : OutputForm . STREAMING ,
119
127
} ) ;
128
+ editor . setEditable ( true ) ;
120
129
} ,
121
130
replaceRange :
122
131
( text : string ) =>
0 commit comments