feat: optimize tab result lifecycle caching

This commit is contained in:
t8y2 committed 2026-06-06 20:30:35 +08:00
1 parent b226b445d6
commit 2b5300722f
22 files changed
+1125 -56

No files matched your search

+10 -3
View File
@@ -1766,6 +1766,8 @@ function markGridScrolling() {
function onScrollerScroll(e: Event) {
syncHeaderScroll(e);
const target = e.target;
recordScrollPosition(target instanceof HTMLElement ? { top: target.scrollTop, left: target.scrollLeft } : undefined);
markGridScrolling();
}
@@ -2125,6 +2127,7 @@ const {
exitTransaction,
startEdit,
commitEdit,
commitEditFromBlur,
applyCellValue,
cancelEdit,
onEditKeydown,
@@ -2147,6 +2150,7 @@ const {
getResetScrollAfterResult,
clearResetScrollAfterResult,
cleanupFrames,
recordScrollPosition,
} = editor;
const saveActionMode = computed(() =>
@@ -3415,6 +3419,7 @@ function onCanvasScroll(event: Event) {
const gutter = scrollbarGutterWidth(scroller);
if (gridScrollbarGutter.value !== gutter) gridScrollbarGutter.value = gutter;
if (headerRef.value && headerRef.value.scrollLeft !== scrollLeft) headerRef.value.scrollLeft = scrollLeft;
recordScrollPosition({ top: scrollTop, left: scrollLeft });
markGridScrolling();
scheduleCanvasDraw();
}
@@ -4606,6 +4611,8 @@ function updateTransposeViewport() {
function onTransposeScroll() {
updateTransposeViewport();
const el = transposeScrollElement();
recordScrollPosition(el ? { top: el.scrollTop, left: el.scrollLeft } : undefined);
markGridScrolling();
}
@@ -6312,7 +6319,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
autocorrect="off"
spellcheck="false"
class="cell-edit-input absolute inset-0 bg-background border-2 border-primary px-1.5 py-0 text-xs leading-[26px] outline-none z-10"
@blur="commitEdit"
@blur="commitEditFromBlur"
@click.stop
@keydown.stop="onEditKeydown"
@paste.stop
@@ -6948,7 +6955,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
autocorrect="off"
spellcheck="false"
class="cell-edit-input absolute inset-0 bg-background border-2 border-primary px-2.5 py-0 text-xs leading-[22px] outline-none z-10"
@blur="commitEdit"
@blur="commitEditFromBlur"
@click.stop
@keydown.stop="onEditKeydown"
@paste.stop
@@ -7123,7 +7130,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
autocorrect="off"
spellcheck="false"
class="cell-edit-input absolute inset-0 bg-background border-2 border-primary px-2.5 py-0 text-xs leading-[22px] outline-none z-10"
@blur="commitEdit"
@blur="commitEditFromBlur"
@click.stop
@keydown.stop="onEditKeydown"
@paste.stop
@@ -229,17 +229,19 @@ function tabMenuIcon(tab: QueryTab) {
return Code2;
}
function activateTab(tabId: string) {
tabScrollBehavior.value = "auto";
queryStore.activeTabId = tabId;
emit("close-driver-store");
}
function handleTabClick(tab: QueryTab) {
if (tabDrag.state.wasDragged) return;
activateTab(tab.id);
}
function handleTabMouseDown(event: MouseEvent, tabId: string) {
if (event.button === 0) {
dispatchBeforeTabSwitch(tabId);
event.preventDefault();
}
tabDrag.startDrag(event, tabId);
}
function tabDropStyle(tabId: string) {
if (!tabDrag.state.active) return {};
if (tabDrag.state.draggedId === tabId) return { opacity: 0.4 };
@@ -266,6 +268,20 @@ const tabOverflowControlClass = computed(() =>
? "h-full w-8 border-r border-border/80 dark:border-border/45 bg-background/80 text-foreground/75 hover:bg-accent hover:text-foreground disabled:cursor-default disabled:opacity-40"
: "h-7 w-7 rounded-md border border-border/60 bg-background text-foreground/70 hover:border-border hover:text-foreground",
);
function dispatchBeforeTabSwitch(tabId: string) {
if (tabId === queryStore.activeTabId) return;
window.dispatchEvent(
new CustomEvent("dbx:before-tab-switch", { detail: { tabId, fromTabId: queryStore.activeTabId } }),
);
}
function activateTab(tabId: string) {
dispatchBeforeTabSwitch(tabId);
tabScrollBehavior.value = "auto";
queryStore.activeTabId = tabId;
emit("close-driver-store");
}
</script>
<template>
@@ -331,7 +347,7 @@ const tabOverflowControlClass = computed(() =>
@click="handleTabClick(tab)"
@dblclick.stop="startRenameTab(tab)"
@mousedown.middle.prevent="queryStore.closeTab(tab.id)"
@mousedown="tabDrag.startDrag($event, tab.id)"
@mousedown="handleTabMouseDown($event, tab.id)"
@mouseenter="tabDrag.updateTarget($event, tab.id)"
@mousemove="tabDrag.updateTarget($event, tab.id)"
@mouseleave="tabDrag.clearTarget(tab.id)"