diff --git a/web/src/pages/CodePage.vue b/web/src/pages/CodePage.vue index c2004e3..b0de790 100644 --- a/web/src/pages/CodePage.vue +++ b/web/src/pages/CodePage.vue @@ -130,11 +130,14 @@ onMounted(() => { ".cm-scroller": { overflow: "auto" } }), EditorView.updateListener.of((update) => { + // 只有当文档内容发生改变 且 选区也改变时才触发 if (update.docChanged && update.selectionSet) { const cursorParams = update.state.selection.main.head; + update.view.dispatch({ - // 改为 "bottom":强制光标始终露出在视野底部 - effects: EditorView.scrollIntoView(cursorParams, { y: "bottom" }) + // 🌟 终极方案:只用 nearest + // 含义:确保光标在视野内。如果在,不动;如果不在,滚进来。 + effects: EditorView.scrollIntoView(cursorParams, { y: "nearest" }) }); } }),