From f0f78d68da8a76c4a7492f935fa59131b948eab3 Mon Sep 17 00:00:00 2001 From: twolate0101 <170792018+twolate0101@users.noreply.github.com> Date: Wed, 10 Dec 2025 14:08:15 +0800 Subject: [PATCH] Fix: Revert to 'nearest' scroll behavior to prevent unwanted jumping --- web/src/pages/CodePage.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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" }) }); } }),