Update useFileManagerKeyboardNavigation.ts
This commit is contained in:
@@ -35,21 +35,18 @@ export function useFileManagerKeyboardNavigation(options: UseFileManagerKeyboard
|
|||||||
if (selectedIndex.value < 0 || !fileListContainerRef.value) return;
|
if (selectedIndex.value < 0 || !fileListContainerRef.value) return;
|
||||||
|
|
||||||
const container = fileListContainerRef.value;
|
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; // 索引超出范围
|
if (selectedIndex.value >= rows.length) return; // 索引超出范围
|
||||||
|
|
||||||
const selectedRow = rows[selectedIndex.value] as HTMLElement;
|
const selectedRow = rows[selectedIndex.value] as HTMLElement;
|
||||||
|
|
||||||
if (selectedRow) {
|
if (selectedRow) {
|
||||||
const containerRect = container.getBoundingClientRect();
|
// 使用 scrollIntoView 使元素可见,滚动最小距离
|
||||||
const rowRect = selectedRow.getBoundingClientRect();
|
selectedRow.scrollIntoView({
|
||||||
|
behavior: 'smooth', // 可以使用 'auto' 来实现即时滚动
|
||||||
if (rowRect.top < containerRect.top) {
|
block: 'nearest',
|
||||||
container.scrollTop -= containerRect.top - rowRect.top;
|
});
|
||||||
} else if (rowRect.bottom > containerRect.bottom) {
|
|
||||||
container.scrollTop += rowRect.bottom - containerRect.bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user