@@ -19,6 +19,10 @@ import { Codemirror } from 'vue-codemirror'
1919import jsonlint from ' jsonlint-mod'
2020
2121import CodeMirror from ' codemirror'
22+ import { json , jsonLanguage } from " @codemirror/lang-json"
23+ import { LanguageSupport } from " @codemirror/language"
24+ import { CompletionContext } from " @codemirror/autocomplete"
25+ import type { Completion } from " @codemirror/autocomplete"
2226import ' codemirror/lib/codemirror.css'
2327import ' codemirror/addon/merge/merge.js'
2428import ' codemirror/addon/merge/merge.css'
@@ -30,6 +34,36 @@ window.DIFF_DELETE = -1;
3034window .DIFF_INSERT = 1 ;
3135window .DIFF_EQUAL = 0 ;
3236
37+ const templateFuncs = ref ([] as Completion [])
38+ function myCompletions(context : CompletionContext ) {
39+ if (templateFuncs .value .length == 0 ) {
40+ API .FunctionsQuery (" " , " template" , (e ) => {
41+ if (e .data ) {
42+ e .data .forEach ((item : any ) => {
43+ templateFuncs .value .push ({
44+ label: item .key ,
45+ type: " text" ,
46+ } as Completion )
47+ })
48+ }
49+ })
50+ }
51+
52+ let word = context .matchBefore (/ \w * / ) || {
53+ from: " " ,
54+ to: " "
55+ }
56+ if (word .from == word .to && ! context .explicit )
57+ return null
58+ return {
59+ from: word .from ,
60+ options: templateFuncs .value
61+ }
62+ }
63+ const jsonComplete = new LanguageSupport (jsonLanguage , jsonLanguage .data .of (
64+ {autocomplete: myCompletions }
65+ ))
66+
3367const { t } = useI18n ()
3468
3569const props = defineProps ({
@@ -1141,6 +1175,8 @@ Magic.AdvancedKeys([{
11411175 <Codemirror v-if =" bodyType === 3 || bodyType === 5 || bodyType === 6"
11421176 @blur =" jsonFormat(-1)"
11431177 v-model =" testCaseWithSuite.data.request.body"
1178+ style =" height : var (--payload-editor-height );"
1179+ :extensions =" [json(), jsonComplete]"
11441180 :disabled =" isHistoryTestCase" />
11451181 <el-table :data =" testCaseWithSuite.data.request.form" style =" width : 100% " v-if =" bodyType === 4" >
11461182 <el-table-column label =" Key" width =" 180" >
0 commit comments