fix(editor): preserve scroll position after SQL execution

After DDL/DML execution via the danger confirmation dialog, the editor
scrolls to the top, making it hard to locate the executed statement.
Fix by scrolling the cursor back into view after execution completes,
using nextTick + requestAnimationFrame to wait for Splitpanes layout
stabilization.
This commit is contained in:
t8y2 2026-05-28 21:35:23 +08:00
parent 9aae48d089
commit 025b465bf1
2 changed files with 23 additions and 2 deletions

View File

@ -1469,7 +1469,15 @@ function openReplace(): boolean {
return searchPanelRef.value?.openReplace() ?? false;
}
defineExpose({ openSearch, openReplace });
function scrollCursorIntoView() {
if (!view.value || !editorViewModule) return;
const pos = view.value.state.selection.main.head;
view.value.dispatch({
effects: editorViewModule.EditorView.scrollIntoView(pos, { y: "nearest" }),
});
}
defineExpose({ openSearch, openReplace, scrollCursorIntoView });
</script>
<template>

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, ref, defineAsyncComponent, watch } from "vue";
import { computed, ref, defineAsyncComponent, watch, nextTick } from "vue";
import { useI18n } from "vue-i18n";
import {
Check,
@ -171,6 +171,19 @@ watch(
},
);
watch(
() => props.activeTab.isExecuting,
(isExecuting, wasExecuting) => {
if (!isExecuting && wasExecuting) {
nextTick(() => {
requestAnimationFrame(() => {
queryEditorRef.value?.scrollCursorIntoView();
});
});
}
},
);
// Column info panel handlers
async function onHandleClickColumn(
matchedCols: Array<{ name: string; table: string; schema?: string }>,