fix: allow manual virtual tree scrolling

This commit is contained in:
2026-08-20 01:54:21 +00:00
parent 7d484a3998
commit 43892865c3
2 changed files with 44 additions and 5 deletions
+7 -5
View File
@@ -155,7 +155,7 @@
return state.searchQuery && state.searchExpandedKeys ? state.searchExpandedKeys : state.expandedKeys;
}
function commit() {
function commit(options = {}) {
const rows = treeApi.flattenVisibleRows(model, {
expandedKeys: effectiveExpandedKeys(),
selectedKey: state.selectedKey,
@@ -163,10 +163,11 @@
});
const activeIndex = rows.findIndex((row) => row.key === state.activeKey);
const maximumScrollTop = Math.max(0, (rows.length * rowHeight) - state.viewportHeight);
if (state.scrollTop > maximumScrollTop) {
state = Object.assign({}, state, { scrollTop: maximumScrollTop });
const clampedScrollTop = Math.max(0, Math.min(state.scrollTop, maximumScrollTop));
if (clampedScrollTop !== state.scrollTop) {
state = Object.assign({}, state, { scrollTop: clampedScrollTop });
}
if (activeIndex >= 0 && state.viewportHeight > 0) {
if (options.ensureActive === true && activeIndex >= 0 && state.viewportHeight > 0) {
const activeTop = activeIndex * rowHeight;
const activeBottom = activeTop + rowHeight;
let scrollTop = state.scrollTop;
@@ -192,7 +193,8 @@
const next = reduceSidebar(state, safeAction, visibleRows);
if (next === state) return lastSnapshot;
state = next;
return commit();
const ensureActive = safeAction.type === 'KEY' || safeAction.type === 'SET_ACTIVE';
return commit({ ensureActive });
}
async function search(query) {