fix(sidebar): scroll to newly created groups

This commit is contained in:
t8y2 2026-05-30 16:09:34 +08:00
parent a9e7f3946d
commit 6b8ca6af87
1 changed files with 28 additions and 1 deletions

View File

@ -163,9 +163,36 @@ const activeTab = computed(() => queryStore.tabs.find((tab) => tab.id === queryS
const pendingRenameGroupId = ref<string | null>(null);
function createNewGroup() {
async function scrollToSidebarNode(nodeId: string) {
await nextTick();
const index = flatNodes.value.findIndex((item) => item.id === nodeId);
const scroller = currentTreeScroller();
if (!scroller || index < 0) return;
const nextScrollTop = scrollTopForSidebarNode({
index,
currentScrollTop: scroller.scrollTop,
viewportHeight: scroller.clientHeight,
});
if (nextScrollTop !== scroller.scrollTop) {
scroller.scrollTop = nextScrollTop;
}
}
async function createNewGroup() {
const groupId = store.createConnectionGroup(t("connectionGroup.newGroupDefault"));
pendingRenameGroupId.value = groupId;
store.selectedTreeNodeId = groupId;
if (isFiltering.value) {
searchQuery.value = "";
deferredSearchQuery.value = "";
clearSearchScopeFilter();
}
await scrollToSidebarNode(groupId);
store.selectedTreeNodeId = groupId;
}
function onSearchToggle(node: TreeNode) {