Files
Netcatty/components/terminalTopTabsTheme.ts
T
陈大猫 86a815ad46 [codex] Optimize terminal tab switching (#1003)
* Optimize terminal tab switching

* Reduce themed tab switch repaint work
2026-05-18 22:19:54 +08:00

53 lines
1.5 KiB
TypeScript

import { collectSessionIds } from "../domain/workspace";
import type { Workspace } from "../types";
export type TopTabsSidePanelTab = "sftp" | "scripts" | "theme" | "ai" | null;
type ScopedTopTabsThemeInput = {
activeSidePanelTab: TopTabsSidePanelTab;
activeThemePreviewId: string | null;
activeWorkspace: Workspace | null | undefined;
followAppTerminalTheme: boolean;
isVisible: boolean;
previewTargetSessionId: string | null;
previewedOrVisibleThemeId: string;
resolveSessionThemeId: (sessionId: string) => string | null;
};
export function getScopedTopTabsThemeId({
activeSidePanelTab,
activeThemePreviewId,
activeWorkspace,
followAppTerminalTheme,
isVisible,
previewTargetSessionId,
previewedOrVisibleThemeId,
resolveSessionThemeId,
}: ScopedTopTabsThemeInput): string | null {
if (activeSidePanelTab === "theme" && previewTargetSessionId && activeThemePreviewId) {
return activeThemePreviewId;
}
if (!isVisible || followAppTerminalTheme || !activeWorkspace || activeWorkspace.viewMode === "focus") {
return null;
}
const sessionIds = collectSessionIds(activeWorkspace.root);
if (sessionIds.length < 2) return null;
let firstThemeId: string | null = null;
for (const sessionId of sessionIds) {
const themeId = resolveSessionThemeId(sessionId);
if (!themeId) continue;
if (firstThemeId == null) {
firstThemeId = themeId;
continue;
}
if (themeId !== firstThemeId) {
return previewedOrVisibleThemeId;
}
}
return null;
}