Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

页签可拖到别的页签组或聊天区的边

Dashd61cb3fc322e
diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
index f1faf29b8a..9dc378f0c2 100644
--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
@@ -61,6 +61,7 @@ import { browserWebviewPool } from '@/features/right-sidebar/lib/browserWebviewP
import { findGlobalTab, setActiveGlobalTabId } from '@/features/right-sidebar/globalTabs';
import { TabGroupHostProvider, type TabGroupHostValue } from '@/features/right-sidebar/tabGroupHost';
import { useTabGroupPanes } from '@/features/right-sidebar/tabGroupPanes';
+import { TabDragController } from '@/features/right-sidebar/TabDragController';
import {
markAllPtyDetached,
markPtyDetached,
@@ -1785,6 +1786,11 @@ export function MainLayout() {
sidebarBlockRef={sidebarBlockRef}
enabled={rightSidebarAvailable && !isRightSidebarMaximized}
/>
+ {/* 页签拖到别的组 / 聊天区边缘(页签条内部的重排仍归 SortableList)。 */}
+ <TabDragController
+ sessionId={rightSidebarSessionId}
+ enabled={rightSidebarAvailable && !isRightSidebarMaximized && !isSettingsRoute}
+ />
{/* 意识面板「点图看大图」承接端:main 拦下面板 /preview/ 导航过闸后
推送到本窗口,这里弹标准 ImageLightbox(整窗一份,纯监听无 UI)。
sessionId = 当前聊天会话 → lightbox 里「发送到对话」可用。 */}
diff --git a/apps/desktop/src/renderer/components/sidebar/SortableList.tsx b/apps/desktop/src/renderer/components/sidebar/SortableList.tsx
index 2f531da5e7..c1ab853f17 100644
--- a/apps/desktop/src/renderer/components/sidebar/SortableList.tsx
+++ b/apps/desktop/src/renderer/components/sidebar/SortableList.tsx
@@ -62,6 +62,23 @@
import { useEffect, useMemo, useRef, type AriaRole, type ReactNode } from 'react';
import Sortable, { type SortableEvent } from 'sortablejs';
+/**
+ * 外部接管:别的手势控制器(页签拖到别的组 / 聊天区边缘)在拖动中途要接走指针时,
+ * 让当前活跃的 Sortable 实例按"被动取消"收尾(复位 DOM、不提交重排)。
+ * 与窗口失焦兜底同一条清理路径。没有活跃实例时 no-op。
+ */
+let externalAbortRequested = false;
+export function cancelActiveSortable(): void {
+ if (!Sortable.active) return;
+ externalAbortRequested = true;
+ try {
+ document.dispatchEvent(new Event('pointercancel'));
+ } catch {
+ document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, cancelable: true }));
+ }
+ externalAbortRequested = false;
+}
+
export interface SortableListProps<T> {
/** 列表项数据(按当前希望渲染的顺序传入)。 */
items: readonly T[];
@@ -190,7 +207,7 @@ export function SortableList<T>({
document.body.classList.remove(SORTING_BODY_CLASS);
onDragActiveChangeRef.current?.(false);
- const aborted = abortNextEndRef.current;
+ const aborted = abortNextEndRef.current || externalAbortRequested;
abortNextEndRef.current = false;
const dropDisposition = nativeDropDispositionRef.current;
nativeDropDispositionRef.current = null;
diff --git a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
index 3cae1d56f0..60e863eb60 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
@@ -78,11 +78,11 @@ import {
mergeAvailableTabOrder,
projectAvailableTabs,
} from './tabAvailability';
+import { moveTabToGroup } from './moveTab';
import {
DEFAULT_TAB_GROUP,
getGroupActiveTabId,
setGroupActiveTabId,
- setTabGroup,
tabGroupOf,
subscribeTabGroups,
useTabGroupAssignments,
@@ -602,10 +602,7 @@ export function RightSidebarShell({
// tabGroupPanes 按在场判定处理。
const handleMoveTab = useCallback(
(tabId: string, target: TabGroupId) => {
- if (target === groupId) return;
- setTabGroup(tabId, target);
- setGroupActiveTabId(target, sessionId, tabId);
- if (isGlobalTabId(tabId)) setActiveGlobalTabId(tabId);
+ if (target !== groupId) moveTabToGroup(tabId, target, sessionId);
},
[groupId, sessionId],
);
diff --git a/apps/desktop/src/renderer/features/right-sidebar/TabBar.tsx b/apps/desktop/src/renderer/features/right-sidebar/TabBar.tsx
index 449c32731d..4d1201d3cf 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/TabBar.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/TabBar.tsx
@@ -384,6 +384,8 @@ export function TabStrip({
return (
<div
data-testid="right-sidebar-tab-strip"
+ // 页签拖到别的组(TabDragController):本条是哪个组的落点 / 起点。
+ data-tab-group-strip={groupId}
className={cn(
'relative flex min-w-0 flex-1 gap-1',
pillVariant === 'chip' ? 'items-center' : 'items-end',
@@ -667,6 +669,7 @@ function TabPill({
<div
ref={pillRef}
data-pinned={pinned || undefined}
+ data-tab-pill={tab.id}
onContextMenu={onContextMenu}
// 中键(滚轮键)关闭当前 tab —— 对齐浏览器等多 tab 应用的通用习惯。
// auxclick 对所有非主键(中/右键)都会触发,这里只认中键(button === 1);
diff --git a/apps/desktop/src/renderer/features/right-sidebar/TabDragController.tsx b/apps/desktop/src/renderer/features/right-sidebar/TabDragController.tsx
new file mode 100644
index 0000000000..3d3c318f81
--- /dev/null
+++ b/apps/desktop/src/renderer/features/right-sidebar/TabDragController.tsx
@@ -0,0 +1,306 @@
+/**
+ * TabDragController —— 把页签拖到别的页签组 / 聊天区的某条边。
+ *
+ * 页签条内部的重排由 SortableList(SortableJS fallback 模式)负责;本控制器只在
+ * 指针**拖出页签条**后接管:取消 Sortable 的这次拖动(复位 DOM、不提交重排),
+ * 浮起一张页签拖影,点亮可落的目标:
+ * - 其它组的页签条(整条 = 落点,落下 = 搬到那一组);
+ * - 聊天区的四条边(各一道边带,落下 = 搬到对应边的组;右边带 = 右侧栏,收着时会展开)。
+ * 松手落在亮区才搬(moveTabToGroup),否则什么都不发生;Esc 取消。
+ *
+ * 性能口径同 PanelDragController:起拖时量一次几何;pointermove 热路径直改拖影
+ * transform、只有落点变化才 setState;拖动期间 body 停止指针命中(webview 穿透)。
+ * 只挂在主窗口(MainLayout);弹出窗口不分组。
+ */
+
+import { useEffect, useRef, useState, type ReactNode } from 'react';
+import { createPortal } from 'react-dom';
+
+import { cancelActiveSortable } from '@/components/sidebar/SortableList';
+import { moveTabToGroup } from './moveTab';
+import { TAB_GROUP_IDS, type TabGroupId } from './tabGroups';
+
+interface RectLike {
+ left: number;
+ top: number;
+ width: number;
+ height: number;
+}
+
+export interface TabDropZone {
+ group: TabGroupId;
+ rect: RectLike;
+}
+
+/** 指针离开页签条多远(px)算"拖出去了",此前都归 Sortable 的条内重排。 */
+const LEAVE_STRIP_MARGIN_PX = 14;
+/** 聊天区边带厚度:短边的 22%,夹到 [72, 180] px。 */
+const EDGE_BAND_RATIO = 0.22;
+const EDGE_BAND_MIN_PX = 72;
+const EDGE_BAND_MAX_PX = 180;
+const ZONE_INSET_PX = 6;
+
+function bandThickness(size: number): number {
+ return Math.min(EDGE_BAND_MAX_PX, Math.max(EDGE_BAND_MIN_PX, size * EDGE_BAND_RATIO));
+}
+
+/**
+ * 纯函数:聊天区矩形 → 四条边带(排除 exclude 里的组,通常是源组)。角落归先列的边
+ * (左右优先于上下),由 pickTabDropZone 的先到先得决定。
+ */
+export function computeChatEdgeZones(
+ chatRect: RectLike,
+ exclude: ReadonlySet<TabGroupId> = new Set(),
+): TabDropZone[] {
+ if (!(chatRect.width > 0 && chatRect.height > 0)) return [];
+ const t = bandThickness(Math.min(chatRect.width, chatRect.height));
+ const zones: TabDropZone[] = [];
+ const push = (group: TabGroupId, rect: RectLike) => {
+ if (!exclude.has(group)) zones.push({ group, rect });
+ };
+ push('left', { left: chatRect.left, top: chatRect.top, width: t, height: chatRect.height });
+ push('right', {
+ left: chatRect.left + chatRect.width - t,
+ top: chatRect.top,
+ width: t,
+ height: chatRect.height,
+ });
+ push('top', { left: chatRect.left, top: chatRect.top, width: chatRect.width, height: t });
+ push('bottom', {
+ left: chatRect.left,
+ top: chatRect.top + chatRect.height - t,
+ width: chatRect.width,
+ height: t,
+ });
+ return zones;
+}
+
+/** 纯函数:指针落在哪个落点里(先到先得);都不在 → null。 */
+export function pickTabDropZone(
+ x: number,
+ y: number,
+ zones: readonly TabDropZone[],
+): TabDropZone | null {
+ for (const zone of zones) {
+ const { left, top, width, height } = zone.rect;
+ if (x >= left && x <= left + width && y >= top && y <= top + height) return zone;
+ }
+ return null;
+}
+
+function rectOf(el: Element): RectLike {
+ const r = el.getBoundingClientRect();
+ return { left: r.left, top: r.top, width: r.width, height: r.height };
+}
+
+function insetRect(rect: RectLike): RectLike {
+ return {
+ left: rect.left + ZONE_INSET_PX,
+ top: rect.top + ZONE_INSET_PX,
+ width: Math.max(0, rect.width - ZONE_INSET_PX * 2),
+ height: Math.max(0, rect.height - ZONE_INSET_PX * 2),
+ };
+}
+
+/** 起拖时一次性收集全部落点:其它组的页签条 + 聊天区边带。 */
+function collectZones(sourceGroup: TabGroupId): TabDropZone[] {
+ const zones: TabDropZone[] = [];
+ for (const strip of document.querySelectorAll<HTMLElement>('[data-tab-group-strip]')) {
+ const group = strip.getAttribute('data-tab-group-strip');
+ if (!group || group === sourceGroup) continue;
+ if (!(TAB_GROUP_IDS as readonly string[]).includes(group)) continue;
+ const rect = rectOf(strip);
+ if (rect.width < 24 || rect.height < 12) continue; // 收起 / 不在场的条不是落点
+ zones.push({ group: group as TabGroupId, rect });
+ }
+ const chat = document.querySelector('[data-panel-drag-root="chat-main"]');
+ if (chat) zones.push(...computeChatEdgeZones(rectOf(chat), new Set([sourceGroup])));
+ return zones;
+}
+
+interface DragRenderState {
+ label: string;
+ zone: TabDropZone | null;
+}
+
+interface TabDragControllerProps {
+ /** 当前任务;搬任务页签后让它在目标组被选中要用。 */
+ sessionId: string | null;
+ /** 内容区在聊天路由上且非撑满态时开启。 */
+ enabled: boolean;
+}
+
+export function TabDragController({ sessionId, enabled }: TabDragControllerProps): ReactNode {
+ const [drag, setDrag] = useState<DragRenderState | null>(null);
+ const activeRef = useRef(false);
+ const ghostRef = useRef<HTMLDivElement | null>(null);
+ const pointRef = useRef({ x: 0, y: 0 });
+ const cleanupRef = useRef<(() => void) | null>(null);
+ const sessionIdRef = useRef(sessionId);
+ sessionIdRef.current = sessionId;
+
+ useEffect(() => {
+ if (!enabled) return;
+
+ const moveGhost = (x: number, y: number) => {
+ pointRef.current = { x, y };
+ const node = ghostRef.current;
+ if (node) node.style.transform = `translate3d(${x}px, ${y}px, 0)`;
+ };
+
+ const takeOver = (
+ tabId: string,
+ sourceGroup: TabGroupId,
+ label: string,
+ x: number,
+ y: number,
+ ) => {
+ const zones = collectZones(sourceGroup);
+ if (zones.length === 0) return false;
+ cancelActiveSortable();
+ activeRef.current = true;
+ let current: TabDropZone | null = null;
+ pointRef.current = { x, y };
+ setDrag({ label, zone: null });
+ document.body.classList.add('resizing-pane');
+ const prevUserSelect = document.body.style.userSelect;
+ const prevPointerEvents = document.body.style.pointerEvents;
+ const prevCursor = document.documentElement.style.cursor;
+ document.body.style.userSelect = 'none';
+ document.body.style.pointerEvents = 'none';
+ document.documentElement.style.cursor = 'grabbing';
+ window.getSelection()?.removeAllRanges();
+
+ const onMove = (e: PointerEvent) => {
+ moveGhost(e.clientX, e.clientY);
+ const next = pickTabDropZone(e.clientX, e.clientY, zones);
+ if (next !== current) {
+ current = next;
+ setDrag({ label, zone: next });
+ }
+ };
+ const finish = (commit: boolean) => {
+ activeRef.current = false;
+ setDrag(null);
+ document.body.classList.remove('resizing-pane');
+ document.body.style.userSelect = prevUserSelect;
+ document.body.style.pointerEvents = prevPointerEvents;
+ document.documentElement.style.cursor = prevCursor;
+ document.removeEventListener('pointermove', onMove);
+ document.removeEventListener('pointerup', onUp);
+ document.removeEventListener('pointercancel', onCancel);
+ window.removeEventListener('keydown', onKey, true);
+ cleanupRef.current = null;
+ if (commit && current) moveTabToGroup(tabId, current.group, sessionIdRef.current);
+ // 松手落点下方可能是按钮:吞掉紧随其后的那一次 click。
+ const swallow = (ce: MouseEvent) => {
+ ce.preventDefault();
+ ce.stopPropagation();
+ };
+ window.addEventListener('click', swallow, { capture: true, once: true });
+ window.setTimeout(
+ () =>
+ window.removeEventListener('click', swallow, { capture: true } as EventListenerOptions),
+ 100,
+ );
+ };
+ const onUp = () => finish(true);
+ const onCancel = () => finish(false);
+ const onKey = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') finish(false);
+ };
+ document.addEventListener('pointermove', onMove);
+ document.addEventListener('pointerup', onUp);
+ document.addEventListener('pointercancel', onCancel);
+ window.addEventListener('keydown', onKey, true);
+ cleanupRef.current = () => finish(false);
+ return true;
+ };
+
+ const onPointerDown = (e: PointerEvent) => {
+ if (activeRef.current || e.button !== 0) return;
+ const target = e.target as HTMLElement | null;
+ const pill = target?.closest<HTMLElement>('[data-tab-pill]');
+ if (!pill || target?.closest('[data-no-drag]')) return;
+ const strip = pill.closest<HTMLElement>('[data-tab-group-strip]');
+ const sourceGroup = strip?.getAttribute('data-tab-group-strip');
+ if (!strip || !sourceGroup || !(TAB_GROUP_IDS as readonly string[]).includes(sourceGroup))
+ return;
+ const tabId = pill.getAttribute('data-tab-pill');
+ if (!tabId) return;
+ const stripRect = strip.getBoundingClientRect();
+ const label = pill.textContent?.trim() ?? '';
+
+ const onMove = (me: PointerEvent) => {
+ const outside =
+ me.clientY < stripRect.top - LEAVE_STRIP_MARGIN_PX ||
+ me.clientY > stripRect.bottom + LEAVE_STRIP_MARGIN_PX ||
+ me.clientX < stripRect.left - LEAVE_STRIP_MARGIN_PX ||
+ me.clientX > stripRect.right + LEAVE_STRIP_MARGIN_PX;
+ if (!outside) return;
+ stop();
+ takeOver(tabId, sourceGroup as TabGroupId, label, me.clientX, me.clientY);
+ };
+ const stop = () => {
+ document.removeEventListener('pointermove', onMove);
+ document.removeEventListener('pointerup', stop);
+ document.removeEventListener('pointercancel', stop);
+ };
+ document.addEventListener('pointermove', onMove);
+ document.addEventListener('pointerup', stop);
+ document.addEventListener('pointercancel', stop);
+ };
+
+ document.addEventListener('pointerdown', onPointerDown, true);
+ return () => {
+ document.removeEventListener('pointerdown', onPointerDown, true);
+ cleanupRef.current?.();
+ };
+ }, [enabled]);
+
+ if (!drag) return null;
+ const zone = drag.zone ? insetRect(drag.zone.rect) : null;
+ return createPortal(
+ <>
+ {zone && (
+ <div
+ aria-hidden
+ data-testid="tab-drop-zone"
+ className="pointer-events-none fixed z-[9998] rounded-xl border animate-fade-in"
+ style={{
+ left: zone.left,
+ top: zone.top,
+ width: zone.width,
+ height: zone.height,
+ background: 'color-mix(in srgb, var(--focus-ring) 10%, transparent)',
+ borderColor: 'color-mix(in srgb, var(--focus-ring) 55%, transparent)',
+ }}
+ />
+ )}
+ <div
+ aria-hidden
+ ref={(node) => {
+ ghostRef.current = node;
+ if (node) {
+ node.style.transform = `translate3d(${pointRef.current.x}px, ${pointRef.current.y}px, 0)`;
+ }
+ }}
+ className="pointer-events-none fixed left-0 top-0 z-[9999] will-change-transform"
+ >
+ <div
+ className="flex h-[30px] max-w-[220px] items-center rounded-lg border px-2.5 text-12 font-medium text-[var(--text-primary)] animate-fade-in"
+ style={{
+ transform: 'translate(-50%, -140%)',
+ background: 'var(--surface-elevated)',
+ borderColor: drag.zone ? 'var(--focus-ring)' : 'var(--border-default)',
+ boxShadow: 'var(--shadow-menu)',
+ opacity: 0.95,
+ }}
+ >
+ <span className="truncate">{drag.label}</span>
+ </div>
+ </div>
+ </>,
+ document.body,
+ );
+}
diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
index 1670b1b520..0db3afb964 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
@@ -440,17 +440,18 @@ describe('RightSidebarShell empty state', () => {
expect(stripOf(left).textContent).toContain('rightSidebar.tabs.kinds.browser'),
);
expect(stripOf(right).textContent).not.toContain('rightSidebar.tabs.kinds.browser');
- // 左侧组里它是激活页签(组内记忆),右侧组仍显示任务级激活页签。
+ // 搬过去的页签在左侧组被选中并成为任务级激活页签;右侧组回落到自己剩下的页签。
+ await waitFor(() => expect(getBucket('s1').activeTabId).toBe('tab-web'));
expect(stripOf(left).querySelector('.group')?.className).toContain('font-medium');
expect(
right.getByText('rightSidebar.tabs.kinds.fileBrowser').closest('.group')?.className,
).toContain('font-medium');
- // 在左侧组点它:任务级激活位照常落库。
+ // 在右侧组点文件页签:任务级激活位照常落库。
tabsIpc.setActive.mockClear();
- fireEvent.click(left.getByText('rightSidebar.tabs.kinds.browser'));
+ fireEvent.click(right.getByText('rightSidebar.tabs.kinds.fileBrowser'));
await waitFor(() => expect(tabsIpc.setActive).toHaveBeenCalled());
- expect(getBucket('s1').activeTabId).toBe('tab-web');
+ expect(getBucket('s1').activeTabId).toBe('tab-files');
// 右侧组「关闭其他」只关本组的页签(本组只剩文件页签,无其它可关)。
fireEvent.contextMenu(right.getByText('rightSidebar.tabs.kinds.fileBrowser').closest('.group')!);
diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/TabDragController.test.ts b/apps/desktop/src/renderer/features/right-sidebar/__tests__/TabDragController.test.ts
new file mode 100644
index 0000000000..04eb1258e4
--- /dev/null
+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/TabDragController.test.ts
@@ -0,0 +1,40 @@
+/**
+ * 测试价值
+ * - 生产入口与可观察结果:页签拖拽落点的纯判定(computeChatEdgeZones / pickTabDropZone);
+ * 可观察的是聊天区四条边带的位置与厚度、源组所在边不成为落点、角落按先到先得归左右边、
+ * 边带外返回 null。亮区与提交共用同一判定,所见即所得。
+ * - Bug / 规则依据:页签可拖到聊天区任一边(页签组模型);边带太薄抓不住、太厚会盖住聊天正文。
+ * - 现有覆盖缺口:新模块。
+ * - 最小失败输入:一个 1000×800 的聊天区矩形。
+ * - tier:unit。
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { computeChatEdgeZones, pickTabDropZone } from '../TabDragController';
+
+describe('computeChatEdgeZones / pickTabDropZone', () => {
+ const chat = { left: 100, top: 50, width: 1000, height: 800 };
+
+ it('四条边带厚度取短边 22% 并夹到 [72,180];排除源组所在的边', () => {
+ const zones = computeChatEdgeZones(chat, new Set(['right']));
+ expect(zones.map((z) => z.group)).toEqual(['left', 'top', 'bottom']);
+ const left = zones.find((z) => z.group === 'left')!.rect;
+ expect(left).toEqual({ left: 100, top: 50, width: 176, height: 800 });
+ const bottom = zones.find((z) => z.group === 'bottom')!.rect;
+ expect(bottom).toEqual({ left: 100, top: 674, width: 1000, height: 176 });
+
+ const tiny = computeChatEdgeZones({ left: 0, top: 0, width: 200, height: 200 });
+ expect(tiny[0].rect.width).toBe(72);
+ expect(computeChatEdgeZones({ left: 0, top: 0, width: 0, height: 0 })).toEqual([]);
+ });
+
+ it('命中按先到先得:角落归左右边;边带外与无落点返回 null', () => {
+ const zones = computeChatEdgeZones(chat);
+ expect(pickTabDropZone(150, 60, zones)?.group).toBe('left');
+ expect(pickTabDropZone(600, 60, zones)?.group).toBe('top');
+ expect(pickTabDropZone(1090, 840, zones)?.group).toBe('right');
+ expect(pickTabDropZone(600, 400, zones)).toBeNull();
+ expect(pickTabDropZone(600, 400, [])).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/renderer/features/right-sidebar/moveTab.ts b/apps/desktop/src/renderer/features/right-sidebar/moveTab.ts
new file mode 100644
index 0000000000..df149fdeb3
--- /dev/null
+++ b/apps/desktop/src/renderer/features/right-sidebar/moveTab.ts
@@ -0,0 +1,33 @@
+/**
+ * moveTabToGroup —— 把一个页签(任务页签或全局页签)搬到另一个页签组的统一入口。
+ * 右键菜单「移到 …」与拖拽落点都走这里:改组归属、让它在目标组里被选中。
+ * 组 pane 的出现 / 隐藏由 tabGroupPanes 按在场判定处理,这里不碰布局树。
+ */
+
+import { createLogger } from '@/lib/logger';
+import { isGlobalTabId, setActiveGlobalTabId } from './globalTabs';
+import { requestRightSidebarVisibility } from './lib/sidebarCommands';
+import { setActiveTab } from './store';
+import { getTabGroup, setGroupActiveTabId, setTabGroup, type TabGroupId } from './tabGroups';
+
+const log = createLogger('rightSidebar.moveTab');
+
+export function moveTabToGroup(
+ tabId: string,
+ target: TabGroupId,
+ sessionId: string | null,
+): boolean {
+ if (getTabGroup(tabId) === target) return false;
+ setTabGroup(tabId, target);
+ setGroupActiveTabId(target, sessionId, tabId);
+ if (isGlobalTabId(tabId)) {
+ setActiveGlobalTabId(tabId);
+ } else if (sessionId) {
+ void setActiveTab(sessionId, tabId).catch((err) => {
+ log.warn('activate moved tab failed', { sessionId, tabId, err });
+ });
+ }
+ // 搬回右侧组而右侧栏正收着:展开它,否则页签"消失"了。
+ if (target === 'right') requestRightSidebarVisibility('open', { animate: true });
+ return true;
+}