mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-12-04 08:42:31 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80961021fa | ||
|
|
4da23b18ed | ||
|
|
2b03d5aa9d |
No files matched your search
+44
-31
@@ -1,6 +1,7 @@
|
||||
import { Folder, FolderLock, Lock, Menu, MoreHorizontal, Plus, Settings, Sparkles } from 'lucide-react';
|
||||
import { Folder, FolderLock, Lock, Menu, Plus, Settings, Sparkles } from 'lucide-react';
|
||||
import React, { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
||||
import { activeTabStore, fromEditorTabId, isEditorTabId, toEditorTabId } from '../application/state/activeTabStore';
|
||||
import { applySessionPresentation } from '../application/state/sessionPresentationStore';
|
||||
import { topTabsSessionsEqual } from '../domain/topTabsSessionsEqual';
|
||||
import { isHostTreeWorkTabSurface } from '../application/app/workTabSurface';
|
||||
import { buildTabShortcutNumberById } from '../application/app/tabShortcutTargets';
|
||||
@@ -35,6 +36,8 @@ import { GlobalSftpTransferCenter } from './GlobalSftpTransferCenter';
|
||||
import { TopTabsQuickControls } from './TopTabsQuickControls';
|
||||
import {
|
||||
ActiveTabAutoScroller,
|
||||
formatSessionTopTabLabel,
|
||||
resolveWorkspaceTopTabLabel,
|
||||
EditorTopTab,
|
||||
LogViewTopTab,
|
||||
PluginViewTopTab,
|
||||
@@ -53,6 +56,7 @@ import {
|
||||
scheduleAfterInstantThemeSwitch,
|
||||
scheduleChromeLayoutAnimation,
|
||||
} from '../application/state/useActiveChromeTheme';
|
||||
import { TopTabOverflowMenu, type OverflowTab } from './top-tabs/TopTabOverflowMenu';
|
||||
import { useTopTabLifecycleAnimations } from './top-tabs/useTopTabLifecycleAnimations';
|
||||
|
||||
// Helper styles for Electron drag regions (use type assertion to include non-standard WebkitAppRegion)
|
||||
@@ -856,6 +860,42 @@ const TopTabsInner: React.FC<TopTabsProps> = ({
|
||||
}).filter(Boolean);
|
||||
}, [orderedTabs, editorTabMap, pluginViewTabMap, orphanSessionMap, workspaceMap, logViewMap, workspacePaneCounts]);
|
||||
|
||||
const getOverflowTabs = (): OverflowTab[] => {
|
||||
const tabs: OverflowTab[] = [{ id: 'vault', label: 'Vaults' }];
|
||||
if (showSftpTab) tabs.push({ id: 'sftp', label: 'SFTP' });
|
||||
for (const item of orderedTabItems) {
|
||||
if (!item) continue;
|
||||
const { id } = item;
|
||||
switch (item.type) {
|
||||
case 'session':
|
||||
tabs.push({ id, label: formatSessionTopTabLabel(applySessionPresentation(item.session), dynamicTabTitleMode) });
|
||||
break;
|
||||
case 'workspace':
|
||||
tabs.push({ id, label: resolveWorkspaceTopTabLabel(item.workspace, workspaceTabSessions.get(id)?.sessions ?? [], dynamicTabTitleMode) });
|
||||
break;
|
||||
case 'editor': {
|
||||
const editor = item.editorTab;
|
||||
tabs.push({
|
||||
id,
|
||||
label: (editorTabFileNameCounts.get(editor.fileName) ?? 0) > 1 ? editor.remotePath : editor.fileName,
|
||||
activate: editor.placement === 'window' ? () => onFocusEditorWindowTab?.(editor.id) : undefined,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'pluginView':
|
||||
tabs.push({ id, label: item.pluginViewTab.title });
|
||||
break;
|
||||
case 'logView': {
|
||||
const { protocol, hostname } = item.logView.log;
|
||||
const host = protocol === 'local' || hostname === 'localhost' ? t('tabs.logLocal') : hostname;
|
||||
tabs.push({ id, label: `${t('tabs.logPrefix')} ${host}` });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tabs;
|
||||
};
|
||||
|
||||
// Bulk-close menu items shared by session and workspace context menus.
|
||||
// Anchor is the tab the user right-clicked on (matches VSCode/JetBrains UX).
|
||||
const renderBulkCloseItems = useCallback((anchorId: string) => {
|
||||
@@ -1210,17 +1250,11 @@ const TopTabsInner: React.FC<TopTabsProps> = ({
|
||||
)}
|
||||
|
||||
<div className="relative min-w-0 flex-1 flex app-drag" style={dragRegionStyle}>
|
||||
{/* Left fade mask */}
|
||||
{canScrollLeft && (
|
||||
<div
|
||||
className="absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10"
|
||||
style={{ background: 'linear-gradient(to right, var(--top-tabs-bg, hsl(var(--secondary))), transparent)' }}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Scrollable container */}
|
||||
<div
|
||||
ref={tabsContainerRef}
|
||||
data-fade-left={canScrollLeft || undefined}
|
||||
data-fade-right={canScrollRight || undefined}
|
||||
className="top-tab-scroll-viewport min-w-0 flex items-end gap-0 overflow-x-auto scrollbar-none app-no-drag max-w-full"
|
||||
style={{ scrollbarWidth: 'none', msOverflowStyle: 'none', ...noDragRegionStyle }}
|
||||
onClick={handleScrollableTabClick}
|
||||
@@ -1255,14 +1289,6 @@ const TopTabsInner: React.FC<TopTabsProps> = ({
|
||||
{/* Keep unused space and the drag handle outside the scroll viewport's exclusion. */}
|
||||
<div className="flex-1 app-drag" style={dragRegionStyle} />
|
||||
<div className="min-w-[20px] h-7 app-drag flex-shrink-0 self-end" style={dragRegionStyle} />
|
||||
|
||||
{/* Right fade mask */}
|
||||
{canScrollRight && (
|
||||
<div
|
||||
className="absolute right-0 top-0 bottom-0 w-8 pointer-events-none z-10"
|
||||
style={{ background: 'linear-gradient(to left, var(--top-tabs-bg, hsl(var(--secondary))), transparent)' }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -1270,20 +1296,7 @@ const TopTabsInner: React.FC<TopTabsProps> = ({
|
||||
{/* More tabs button - only when overflowing */}
|
||||
{hasOverflow && (
|
||||
<div className="contents" data-section="top-tabs-toolbar-actions">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 flex-shrink-0 app-no-drag self-end rounded-none"
|
||||
style={{ color: 'var(--top-tabs-muted, hsl(var(--muted-foreground)))' }}
|
||||
onClick={onOpenQuickSwitcher}
|
||||
>
|
||||
<MoreHorizontal size={14} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{t('topTabs.moreTabs')}</TooltipContent>
|
||||
</Tooltip>
|
||||
<TopTabOverflowMenu getTabs={getOverflowTabs} onOpenQuickSwitcher={onOpenQuickSwitcher} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { I18nProvider } from '../../application/i18n/I18nProvider';
|
||||
import { activeTabStore } from '../../application/state/activeTabStore';
|
||||
import { createDomRenderer, dispatchDomEvent, installDomEnvironment } from '../test-support/renderReactDom';
|
||||
import { TopTabOverflowMenu } from './TopTabOverflowMenu';
|
||||
|
||||
test('overflow menu selects an existing tab, focuses detached editors and retains the quick switcher', async t => {
|
||||
const dom = installDomEnvironment();
|
||||
t.after(dom.cleanup);
|
||||
const oldElement = Object.getOwnPropertyDescriptor(globalThis, 'Element');
|
||||
const oldRaf = Object.getOwnPropertyDescriptor(globalThis, 'requestAnimationFrame');
|
||||
Object.defineProperty(globalThis, 'Element', { configurable: true, value: dom.window.Element });
|
||||
Object.defineProperty(globalThis, 'requestAnimationFrame', {
|
||||
configurable: true, value: (callback: FrameRequestCallback) => setTimeout(() => callback(0), 0),
|
||||
});
|
||||
t.after(() => {
|
||||
if (oldElement) Object.defineProperty(globalThis, 'Element', oldElement);
|
||||
else Reflect.deleteProperty(globalThis, 'Element');
|
||||
if (oldRaf) Object.defineProperty(globalThis, 'requestAnimationFrame', oldRaf);
|
||||
else Reflect.deleteProperty(globalThis, 'requestAnimationFrame');
|
||||
});
|
||||
const renderer = await createDomRenderer(dom.document);
|
||||
const previous = activeTabStore.getActiveTabId();
|
||||
let focused = 0;
|
||||
let openedSwitcher = 0;
|
||||
const tabs = [
|
||||
{ id: 'vault', label: 'Vaults' },
|
||||
{ id: 's1', label: 'Test SSH' },
|
||||
{ id: 'editor:1', label: 'Detached editor', activate: () => { focused++; } },
|
||||
];
|
||||
const click = (selector: string) => {
|
||||
const element = dom.document.querySelector(selector);
|
||||
assert.ok(element, selector);
|
||||
return dispatchDomEvent(element, new dom.window.MouseEvent('click', { bubbles: true }));
|
||||
};
|
||||
try {
|
||||
activeTabStore.setActiveTabId('vault');
|
||||
await renderer.render(<I18nProvider locale="en">
|
||||
<TopTabOverflowMenu getTabs={() => tabs} onOpenQuickSwitcher={() => { openedSwitcher++; }} />
|
||||
</I18nProvider>);
|
||||
const trigger = 'button[aria-haspopup="menu"]';
|
||||
await click(trigger);
|
||||
const options = [...dom.document.querySelectorAll('[role="menuitemradio"]')];
|
||||
assert.deepEqual(options.map(option => option.textContent), tabs.map(tab => tab.label));
|
||||
assert.equal(options[0].getAttribute('aria-checked'), 'true');
|
||||
await click('[title="Test SSH"]');
|
||||
assert.equal(activeTabStore.getActiveTabId(), 's1');
|
||||
assert.equal(dom.document.querySelector('[role="menu"]'), null);
|
||||
|
||||
await click(trigger);
|
||||
await click('[title="Detached editor"]');
|
||||
assert.equal(focused, 1);
|
||||
assert.equal(activeTabStore.getActiveTabId(), 's1');
|
||||
|
||||
await click(trigger);
|
||||
await click('[role="menuitem"]');
|
||||
assert.equal(openedSwitcher, 1);
|
||||
assert.equal(dom.document.querySelector('[role="menu"]'), null);
|
||||
} finally {
|
||||
await renderer.unmount();
|
||||
activeTabStore.setActiveTabId(previous);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Check, MoreVertical, Plus } from 'lucide-react';
|
||||
import React, { useState } from 'react';
|
||||
import { useI18n } from '../../application/i18n/I18nProvider';
|
||||
import { activeTabStore, useActiveTabId } from '../../application/state/activeTabStore';
|
||||
import { useSessionPresentationVersion } from '../../application/state/sessionPresentationStore';
|
||||
import { Button } from '../ui/button';
|
||||
import { Dropdown, DropdownContent, DropdownTrigger } from '../ui/dropdown';
|
||||
|
||||
export interface OverflowTab {
|
||||
id: string;
|
||||
label: string;
|
||||
activate?: () => void;
|
||||
}
|
||||
|
||||
const itemClass = 'flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-foreground/10 focus-visible:bg-foreground/10';
|
||||
|
||||
function TabChoices({ getTabs, onClose }: { getTabs: () => OverflowTab[]; onClose: () => void }) {
|
||||
const activeId = useActiveTabId();
|
||||
useSessionPresentationVersion();
|
||||
return getTabs().map(({ id, label, activate }) => (
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={id === activeId}
|
||||
className={itemClass}
|
||||
onClick={() => {
|
||||
onClose();
|
||||
if (activate) activate();
|
||||
else activeTabStore.setActiveTabId(id);
|
||||
}}
|
||||
>
|
||||
<span className="w-4 shrink-0">{id === activeId && <Check size={14} />}</span>
|
||||
<span className="truncate" title={label}>{label}</span>
|
||||
</button>
|
||||
));
|
||||
}
|
||||
|
||||
export function TopTabOverflowMenu({ getTabs, onOpenQuickSwitcher }: {
|
||||
getTabs: () => OverflowTab[];
|
||||
onOpenQuickSwitcher: () => void;
|
||||
}) {
|
||||
const { t } = useI18n();
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<Dropdown open={open} onOpenChange={setOpen}>
|
||||
<DropdownTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-5 flex-shrink-0 app-no-drag self-end top-tab-utility-btn"
|
||||
style={{ color: 'var(--top-tabs-muted, hsl(var(--muted-foreground)))' }}
|
||||
aria-haspopup="menu"
|
||||
data-state={open ? 'open' : 'closed'}
|
||||
aria-expanded={open}
|
||||
aria-label={t('topTabs.moreTabs')}
|
||||
title={t('topTabs.moreTabs')}
|
||||
>
|
||||
<MoreVertical size={14} />
|
||||
</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownContent align="end" keyboardNavigation className="app-no-drag w-64 max-h-[65vh] overflow-y-auto">
|
||||
<TabChoices getTabs={getTabs} onClose={() => setOpen(false)} />
|
||||
<button type="button" role="menuitem" className={`${itemClass} mt-1 border-t`} onClick={() => {
|
||||
setOpen(false);
|
||||
onOpenQuickSwitcher();
|
||||
}}>
|
||||
<Plus size={14} />{t('topTabs.openQuickSwitcher')}
|
||||
</button>
|
||||
</DropdownContent>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
@@ -733,6 +733,21 @@ html[data-theme-transition] *::after {
|
||||
app-region: none;
|
||||
}
|
||||
|
||||
/* Fade the clipped tabs into the title bar at the viewport edge, before the drag handle. */
|
||||
.top-tab-scroll-viewport[data-fade-left] {
|
||||
--tab-fade-left: min(2.25rem, 25%);
|
||||
}
|
||||
|
||||
.top-tab-scroll-viewport[data-fade-right] {
|
||||
--tab-fade-right: min(2.25rem, 25%);
|
||||
}
|
||||
|
||||
.top-tab-scroll-viewport:is([data-fade-left], [data-fade-right]) {
|
||||
mask-image: linear-gradient(to right,
|
||||
transparent, black var(--tab-fade-left, 0px),
|
||||
black calc(100% - var(--tab-fade-right, 0px)), transparent);
|
||||
}
|
||||
|
||||
/* Removing the Windows titlebar drag space moves tabs and caption controls up to the physical top edge. */
|
||||
html.platform-win32 [data-top-tabs-root][data-remove-top-tabs-drag-area="true"] [data-section="top-tabs-toolbar-row"] {
|
||||
height: 1.75rem;
|
||||
|
||||
Reference in new issue
Block a user