From 4eaae312ad98e19bbae8502dc472fd028adb2315 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Wed, 30 Apr 2025 14:15:17 +0800 Subject: [PATCH] Update useFileManagerKeyboardNavigation.ts --- .../useFileManagerKeyboardNavigation.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/frontend/src/composables/file-manager/useFileManagerKeyboardNavigation.ts b/packages/frontend/src/composables/file-manager/useFileManagerKeyboardNavigation.ts index a2a6dbc..ae85417 100644 --- a/packages/frontend/src/composables/file-manager/useFileManagerKeyboardNavigation.ts +++ b/packages/frontend/src/composables/file-manager/useFileManagerKeyboardNavigation.ts @@ -35,21 +35,18 @@ export function useFileManagerKeyboardNavigation(options: UseFileManagerKeyboard if (selectedIndex.value < 0 || !fileListContainerRef.value) return; const container = fileListContainerRef.value; - // 使用 querySelectorAll 获取所有行,包括 '..' - const rows = container.querySelectorAll('tr.file-row'); + // 使用更通用的选择器获取所有数据行 + const rows = container.querySelectorAll('tbody > tr'); // Changed selector if (selectedIndex.value >= rows.length) return; // 索引超出范围 const selectedRow = rows[selectedIndex.value] as HTMLElement; if (selectedRow) { - const containerRect = container.getBoundingClientRect(); - const rowRect = selectedRow.getBoundingClientRect(); - - if (rowRect.top < containerRect.top) { - container.scrollTop -= containerRect.top - rowRect.top; - } else if (rowRect.bottom > containerRect.bottom) { - container.scrollTop += rowRect.bottom - containerRect.bottom; - } + // 使用 scrollIntoView 使元素可见,滚动最小距离 + selectedRow.scrollIntoView({ + behavior: 'smooth', // 可以使用 'auto' 来实现即时滚动 + block: 'nearest', + }); } };