fix(settings): reset scroll on tab switch

This commit is contained in:
zipg authored and GitHub committed 2026-07-30 00:07:27 +08:00
1 parent eafc497563
commit 0edba2f023
2 files changed
+19 -1

No files matched your search

@@ -1337,6 +1337,7 @@ function setSidebarActivation(value: "single" | "double") {
} }
const activeSettingsTab = ref("appearance"); const activeSettingsTab = ref("appearance");
const settingsContentScrollRef = ref<HTMLElement | null>(null);
const isWeb = !isTauriRuntime(); const isWeb = !isTauriRuntime();
const appSupportInfo = ref<AppSupportInfo | null>(null); const appSupportInfo = ref<AppSupportInfo | null>(null);
const appSupportInfoLoading = ref(false); const appSupportInfoLoading = ref(false);
@@ -1382,6 +1383,12 @@ function settingsCategoryButton(value: SettingsCategory): string {
].join(" "); ].join(" ");
} }
async function resetSettingsContentScroll() {
await nextTick();
const scroller = settingsContentScrollRef.value;
if (scroller) scroller.scrollTop = 0;
}
function openExternalUrl(url: string) { function openExternalUrl(url: string) {
if (isTauriRuntime()) { if (isTauriRuntime()) {
import("@tauri-apps/plugin-shell").then(({ open }) => open(url)); import("@tauri-apps/plugin-shell").then(({ open }) => open(url));
@@ -2024,6 +2031,7 @@ watch(snippetProvider, (provider) => {
}); });
watch(activeSettingsTab, async (tab) => { watch(activeSettingsTab, async (tab) => {
void resetSettingsContentScroll();
if (tab === "mcp" && !mcpStatus.value && !mcpStatusLoading.value) void refreshMcpStatus(); if (tab === "mcp" && !mcpStatus.value && !mcpStatusLoading.value) void refreshMcpStatus();
if (tab === "ai" && aiIsCliProvider.value) void ensureCliMcpStatus(); if (tab === "ai" && aiIsCliProvider.value) void ensureCliMcpStatus();
if (tab === "ai") { if (tab === "ai") {
@@ -3130,7 +3138,7 @@ onUnmounted(cleanupPreviewEditor);
</nav> </nav>
<div class="min-w-0 flex-1 overflow-hidden px-1 flex flex-col"> <div class="min-w-0 flex-1 overflow-hidden px-1 flex flex-col">
<div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1 pr-2"> <div ref="settingsContentScrollRef" class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1 pr-2">
<section v-if="activeSettingsTab === 'editor'" class="flex flex-col gap-5 py-2"> <section v-if="activeSettingsTab === 'editor'" class="flex flex-col gap-5 py-2">
<div class="grid gap-4 md:grid-cols-[1fr_auto]"> <div class="grid gap-4 md:grid-cols-[1fr_auto]">
<!-- Font Family --> <!-- Font Family -->
+10
View File
@@ -617,6 +617,16 @@ test("shows persisted UI scales that are not available as presets", () => {
assert.match(source, /<SelectValue>\{\{ Math\.round\(editUiScale \* 100\) \}\}%<\/SelectValue>/); assert.match(source, /<SelectValue>\{\{ Math\.round\(editUiScale \* 100\) \}\}%<\/SelectValue>/);
}); });
test("settings page resets content scroll when switching categories", () => {
const source = readFileSync("apps/desktop/src/components/editor/EditorSettingsDialog.vue", "utf8");
assert.match(source, /const settingsContentScrollRef = ref<HTMLElement \| null>\(null\)/);
assert.match(source, /function resetSettingsContentScroll\(\)/);
assert.match(source, /if \(scroller\) scroller\.scrollTop = 0/);
assert.match(source, /watch\(activeSettingsTab, async \(tab\) => \{\s+void resetSettingsContentScroll\(\);/);
assert.match(source, /ref="settingsContentScrollRef" class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden/);
});
test("defaults SQL formatter settings", () => { test("defaults SQL formatter settings", () => {
assert.deepEqual(DEFAULT_EDITOR_SETTINGS.sqlFormatter, DEFAULT_SQL_FORMATTER_SETTINGS); assert.deepEqual(DEFAULT_EDITOR_SETTINGS.sqlFormatter, DEFAULT_SQL_FORMATTER_SETTINGS);
assert.deepEqual(normalizeEditorSettings({}).sqlFormatter, DEFAULT_EDITOR_SETTINGS.sqlFormatter); assert.deepEqual(normalizeEditorSettings({}).sqlFormatter, DEFAULT_EDITOR_SETTINGS.sqlFormatter);