This commit is contained in:
2024-01-25 10:59:55 +08:00
parent 5631d0ba0a
commit a5134cb708
2 changed files with 21 additions and 6 deletions

View File

@@ -3,14 +3,25 @@ import { ref } from "vue"
export const insertText = ref("")
export const cTexts = [
",",
";",
",",
"&",
"{}",
" = ",
" == ",
" > ",
" < ",
" != ",
" || ",
" && ",
"()",
'printf("");',
'scanf("");',
"{\n}",
"int",
"int ",
"float ",
"%d",
"if () ",
"%.2f",
"if () {}",
" else ",
]
@@ -24,13 +35,14 @@ export const pythonTexts = [
" != ",
"print()",
"input()",
"if ",
"if :",
"else:",
"elif ",
"elif :",
"for ",
" in ",
"range():",
"while",
"[]",
"{}",
'"%.2f" % ',
]

View File

@@ -46,10 +46,13 @@ whenever(insertText, (text: string) => {
if (['"', "]", ")"].includes(text[len - 1])) delta = 1
// {}
if (text === "{}") delta = 1
// if : elif :
if (text.slice(len - 2) === " :") delta = 1
// range():
if (text.slice(len - 2) === "):") delta = 2
// printf(""); scanf("");
if (text.slice(len - 3) === '");') delta = 3
if (text === "if () {}") delta = 4
if (delta > 0) {
const pos = codeEditor.state.selection.main.head - delta
codeEditor.dispatch({