Fix: Revert to 'nearest' scroll behavior to prevent unwanted jumping

This commit is contained in:
twolate0101
2025-12-10 14:08:15 +08:00
parent 91c8519c72
commit f0f78d68da

View File

@@ -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" })
});
}
}),