fix
This commit is contained in:
@@ -30,4 +30,6 @@ export const pythonTexts = [
|
|||||||
" in ",
|
" in ",
|
||||||
"range():",
|
"range():",
|
||||||
"while",
|
"while",
|
||||||
|
"[]",
|
||||||
|
"{}",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -39,23 +39,25 @@ function onReady(view: EditorView) {
|
|||||||
whenever(insertText, (text: string) => {
|
whenever(insertText, (text: string) => {
|
||||||
if (!codeEditor) return
|
if (!codeEditor) return
|
||||||
codeEditor.dispatch(codeEditor.state.replaceSelection(text))
|
codeEditor.dispatch(codeEditor.state.replaceSelection(text))
|
||||||
codeEditor.focus() // 保持光标选中状态
|
|
||||||
// 处理换行或者移动光标
|
// 处理换行或者移动光标
|
||||||
let delta = 0
|
let delta = 0
|
||||||
if (text === '""' || text === "''") delta = 1
|
const len = text.length
|
||||||
if (text[text.length - 1] === ")") delta = 1
|
// "", [], ()
|
||||||
if (text[text.length - 1] === ":" && text[text.length - 2] === ")") {
|
if (['"', "]", ")"].includes(text[len - 1])) delta = 1
|
||||||
delta = 2
|
// {}
|
||||||
}
|
if (text === "{}") delta = 1
|
||||||
|
// range():
|
||||||
|
if (text.slice(len - 2) === "):") delta = 2
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
const newPos = codeEditor.state.selection.ranges[0].from - delta
|
const pos = codeEditor.state.selection.main.head - delta
|
||||||
codeEditor.dispatch({
|
codeEditor.dispatch({
|
||||||
selection: {
|
selection: {
|
||||||
anchor: newPos,
|
anchor: pos,
|
||||||
head: newPos,
|
head: pos,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
codeEditor.focus() // 保持光标选中状态
|
||||||
insertText.value = ""
|
insertText.value = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user