From cd6b6161296907f5bb386e75a23e8f6b0ef9c32e Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Thu, 25 Jan 2024 10:08:10 +0800 Subject: [PATCH] fix --- src/composables/helper.ts | 2 ++ src/mobile/Content.vue | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/composables/helper.ts b/src/composables/helper.ts index c5efcaf..9691ca6 100644 --- a/src/composables/helper.ts +++ b/src/composables/helper.ts @@ -30,4 +30,6 @@ export const pythonTexts = [ " in ", "range():", "while", + "[]", + "{}", ] diff --git a/src/mobile/Content.vue b/src/mobile/Content.vue index b580e90..e040326 100644 --- a/src/mobile/Content.vue +++ b/src/mobile/Content.vue @@ -39,23 +39,25 @@ function onReady(view: EditorView) { whenever(insertText, (text: string) => { if (!codeEditor) return codeEditor.dispatch(codeEditor.state.replaceSelection(text)) - codeEditor.focus() // 保持光标选中状态 // 处理换行或者移动光标 let delta = 0 - if (text === '""' || text === "''") delta = 1 - if (text[text.length - 1] === ")") delta = 1 - if (text[text.length - 1] === ":" && text[text.length - 2] === ")") { - delta = 2 - } + const len = text.length + // "", [], () + if (['"', "]", ")"].includes(text[len - 1])) delta = 1 + // {} + if (text === "{}") delta = 1 + // range(): + if (text.slice(len - 2) === "):") delta = 2 if (delta > 0) { - const newPos = codeEditor.state.selection.ranges[0].from - delta + const pos = codeEditor.state.selection.main.head - delta codeEditor.dispatch({ selection: { - anchor: newPos, - head: newPos, + anchor: pos, + head: pos, }, }) } + codeEditor.focus() // 保持光标选中状态 insertText.value = "" })