This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-09 23:28:48 -05:00
1 parent 0ff3f4e18d
commit efa8f0a96b
15 files changed
+350 -186

No files matched your search

+2 -2
View File
@@ -35,7 +35,7 @@
active: direction === 'horizontal',
onclick: () => {
setSplitDirection('horizontal');
if (!$splitActive) splitCurrentTab('horizontal');
splitCurrentTab('horizontal');
}
},
{
@@ -44,7 +44,7 @@
active: direction === 'vertical',
onclick: () => {
setSplitDirection('vertical');
if (!$splitActive) splitCurrentTab('vertical');
splitCurrentTab('vertical');
}
}
];
@@ -142,6 +142,7 @@
// Only accept tab drags (not file uploads)
if (!e.dataTransfer || !hasTabDrag(e.dataTransfer)) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = 'move';
dropHighlight = true;
}
@@ -155,8 +156,9 @@
if (!e.dataTransfer) return;
const payload = readTabDragPayload(e.dataTransfer);
if (!payload) return;
if (payload.groupId === group.id) return; // same group, ignore
e.preventDefault();
e.stopPropagation();
if (payload.groupId === group.id) return; // same group, ignore
moveTabToGroup(payload.tabId, payload.groupId, group.id);
}
@@ -208,7 +210,7 @@
const tab = contextMenu.tab;
const items: { label: string; icon?: string; onclick: () => void; divider?: boolean }[] = [];
if (isWideScreen && tab.type === 'file' && tab.filePath && !$splitActive) {
if (isWideScreen && tab.type === 'file' && tab.filePath) {
items.push({
label: $t('bar.splitRight'),
icon: 'split-horizontal',
@@ -242,7 +244,7 @@
active: direction === 'horizontal',
onclick: () => {
setSplitDirection('horizontal');
if (!$splitActive) splitCurrentTab('horizontal');
splitCurrentTab('horizontal');
}
},
{
@@ -251,7 +253,7 @@
active: direction === 'vertical',
onclick: () => {
setSplitDirection('vertical');
if (!$splitActive) splitCurrentTab('vertical');
splitCurrentTab('vertical');
}
}
];
@@ -373,8 +375,8 @@
<!-- Right-side controls -->
<div class="flex items-center gap-0.5 shrink-0">
<!-- Split button (wide screens, primary group only) -->
{#if isPrimary && isWideScreen}
<!-- Split button (wide screens) -->
{#if isWideScreen}
<button
bind:this={splitBtnEl}
class="flex items-center justify-center w-7 h-7 rounded-lg transition-colors duration-100 shrink-0
@@ -13,6 +13,7 @@
let { onsettings, onsysteminfo }: Props = $props();
let showMenu = $state(false);
let menuButtonEl: HTMLButtonElement | undefined = $state();
const FEATURE_REQUEST_URL = 'https://github.com/open-webui/computer/issues/new/choose';
function openSettings(tab?: string) {
showMenu = false;
@@ -79,6 +80,11 @@
icon: 'info',
onclick: openSystemInfo
},
{
label: $t('sidebar.suggestFeature'),
icon: 'external-link',
onclick: () => window.open(FEATURE_REQUEST_URL, '_blank', 'noopener,noreferrer')
},
{ divider: true, label: '', onclick: () => {} },
{ label: $t('sidebar.logOut'), icon: 'log-out', onclick: clearSession }
]}
@@ -24,6 +24,7 @@
"sidebar.collapse": "Einklappen",
"sidebar.noWorkspaces": "Noch keine Arbeitsbereiche",
"sidebar.settings": "Einstellungen",
"sidebar.suggestFeature": "Feedback",
"sidebar.admin": "Verwaltung",
"sidebar.logOut": "Abmelden",
"sidebar.remove": "Entfernen",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "{{count}} Dateien auf {{branch}} committen",
"git.commitToBranch": "Auf {{branch}} committen",
"git.summaryRequired": "Zusammenfassung (erforderlich)",
"git.generateMessage": "Commit-Nachricht generieren",
"git.generateMessageFailed": "Commit-Nachricht konnte nicht generiert werden",
"git.description": "Beschreibung",
"git.commit": "Committen",
"git.commitMessage": "Commit-Nachricht...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "Collapse",
"sidebar.noWorkspaces": "No workspaces yet",
"sidebar.settings": "Settings",
"sidebar.suggestFeature": "Feedback",
"sidebar.admin": "Admin",
"sidebar.logOut": "Log out",
"sidebar.remove": "Remove",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "Commit {{count}} files to {{branch}}",
"git.commitToBranch": "Commit to {{branch}}",
"git.summaryRequired": "Summary (required)",
"git.generateMessage": "Generate commit message",
"git.generateMessageFailed": "Could not generate a commit message",
"git.description": "Description",
"git.commit": "Commit",
"git.commitMessage": "Commit message...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "Contraer",
"sidebar.noWorkspaces": "Sin espacios de trabajo",
"sidebar.settings": "Configuración",
"sidebar.suggestFeature": "Comentarios",
"sidebar.admin": "Administración",
"sidebar.logOut": "Cerrar sesión",
"sidebar.remove": "Eliminar",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "Confirmar {{count}} archivos en {{branch}}",
"git.commitToBranch": "Confirmar en {{branch}}",
"git.summaryRequired": "Resumen (obligatorio)",
"git.generateMessage": "Generar mensaje de commit",
"git.generateMessageFailed": "No se pudo generar un mensaje de commit",
"git.description": "Descripción",
"git.commit": "Confirmar",
"git.commitMessage": "Mensaje de confirmación...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "Réduire",
"sidebar.noWorkspaces": "Aucun espace de travail",
"sidebar.settings": "Paramètres",
"sidebar.suggestFeature": "Commentaires",
"sidebar.admin": "Administration",
"sidebar.logOut": "Se déconnecter",
"sidebar.remove": "Supprimer",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "Valider {{count}} fichiers sur {{branch}}",
"git.commitToBranch": "Valider sur {{branch}}",
"git.summaryRequired": "Résumé (obligatoire)",
"git.generateMessage": "Générer le message de commit",
"git.generateMessageFailed": "Impossible de générer un message de commit",
"git.description": "Détails",
"git.commit": "Valider",
"git.commitMessage": "Message de validation...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "折りたたむ",
"sidebar.noWorkspaces": "ワークスペースがありません",
"sidebar.settings": "設定",
"sidebar.suggestFeature": "フィードバック",
"sidebar.admin": "管理",
"sidebar.logOut": "ログアウト",
"sidebar.remove": "削除",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "{{count}} 件のファイルを {{branch}} にコミット",
"git.commitToBranch": "{{branch}} にコミット",
"git.summaryRequired": "概要(必須)",
"git.generateMessage": "コミットメッセージを生成",
"git.generateMessageFailed": "コミットメッセージを生成できませんでした",
"git.description": "説明",
"git.commit": "コミット",
"git.commitMessage": "コミットメッセージ...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "접기",
"sidebar.noWorkspaces": "워크스페이스가 없습니다",
"sidebar.settings": "설정",
"sidebar.suggestFeature": "피드백",
"sidebar.admin": "관리",
"sidebar.logOut": "로그아웃",
"sidebar.remove": "제거",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "{{count}}개 파일을 {{branch}}에 커밋",
"git.commitToBranch": "{{branch}}에 커밋",
"git.summaryRequired": "요약 (필수)",
"git.generateMessage": "커밋 메시지 생성",
"git.generateMessageFailed": "커밋 메시지를 생성할 수 없습니다",
"git.description": "설명",
"git.commit": "커밋",
"git.commitMessage": "커밋 메시지...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "Recolher",
"sidebar.noWorkspaces": "Nenhuma área de trabalho",
"sidebar.settings": "Configurações",
"sidebar.suggestFeature": "Feedback",
"sidebar.admin": "Administração",
"sidebar.logOut": "Sair",
"sidebar.remove": "Remover",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "Commitar {{count}} arquivos em {{branch}}",
"git.commitToBranch": "Commitar em {{branch}}",
"git.summaryRequired": "Resumo (obrigatório)",
"git.generateMessage": "Gerar mensagem de commit",
"git.generateMessageFailed": "Não foi possível gerar uma mensagem de commit",
"git.description": "Descrição",
"git.commit": "Commitar",
"git.commitMessage": "Mensagem do commit...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "Свернуть",
"sidebar.noWorkspaces": "Нет рабочих областей",
"sidebar.settings": "Настройки",
"sidebar.suggestFeature": "Обратная связь",
"sidebar.admin": "Управление",
"sidebar.logOut": "Выйти",
"sidebar.remove": "Удалить",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "Закоммитить {{count}} файлов в {{branch}}",
"git.commitToBranch": "Закоммитить в {{branch}}",
"git.summaryRequired": "Описание (обязательно)",
"git.generateMessage": "Создать сообщение коммита",
"git.generateMessageFailed": "Не удалось создать сообщение коммита",
"git.description": "Описание",
"git.commit": "Коммит",
"git.commitMessage": "Сообщение коммита...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "收起",
"sidebar.noWorkspaces": "暂无工作区",
"sidebar.settings": "设置",
"sidebar.suggestFeature": "反馈",
"sidebar.admin": "管理",
"sidebar.logOut": "退出登录",
"sidebar.remove": "移除",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "提交 {{count}} 个文件到 {{branch}}",
"git.commitToBranch": "提交到 {{branch}}",
"git.summaryRequired": "摘要(必填)",
"git.generateMessage": "生成提交信息",
"git.generateMessageFailed": "无法生成提交信息",
"git.description": "描述",
"git.commit": "提交",
"git.commitMessage": "提交信息...",
@@ -24,6 +24,7 @@
"sidebar.collapse": "收合",
"sidebar.noWorkspaces": "尚無工作區",
"sidebar.settings": "設定",
"sidebar.suggestFeature": "意見回饋",
"sidebar.admin": "管理",
"sidebar.logOut": "登出",
"sidebar.remove": "移除",
@@ -180,6 +181,8 @@
"git.commitFilesToBranch_other": "提交 {{count}} 個檔案到 {{branch}}",
"git.commitToBranch": "提交到 {{branch}}",
"git.summaryRequired": "摘要(必填)",
"git.generateMessage": "產生提交訊息",
"git.generateMessageFailed": "無法產生提交訊息",
"git.description": "描述",
"git.commit": "提交",
"git.commitMessage": "提交訊息...",
+160 -25
View File
@@ -9,7 +9,7 @@
* Architecture:
* Workspace → EditorGroup[] (1 or more groups, each with independent tabs)
* Each group has its own tab list and active tab, like VS Code editor groups.
* When there are 2+ groups, a split view is rendered.
* Groups are arranged in a nested split tree, like VS Code editor groups.
*
* Multiple browser tabs can independently view different workspaces without
* interfering; each tab reads its workspace path from the URL and loads/saves
@@ -65,11 +65,28 @@ export interface EditorGroup {
tabHistory?: string[]; // MRU stack of tab IDs (most recent last)
}
export type EditorLayout = EditorGroupLeaf | EditorSplit;
export interface EditorGroupLeaf {
type: 'group';
groupId: string;
}
export interface EditorSplit {
type: 'split';
id: string;
direction: SplitDirection;
ratio: number;
first: EditorLayout;
second: EditorLayout;
}
export interface WorkspaceState {
name: string;
path: string;
groups: EditorGroup[];
activeGroupId: string;
layout: EditorLayout;
splitDirection: SplitDirection;
splitRatio: number; // 0-1, fraction for the first group
fileBrowserCwd: string;
@@ -119,12 +136,109 @@ function createDefaultWorkspace(path: string): WorkspaceState {
path,
groups: [createDefaultGroup()],
activeGroupId: 'default',
layout: { type: 'group', groupId: 'default' },
splitDirection: 'horizontal',
splitRatio: 0.5,
fileBrowserCwd: path
};
}
function splitLayout(
layout: EditorLayout,
groupId: string,
newGroupId: string,
direction: SplitDirection,
placement: 'before' | 'after' = 'after'
): EditorLayout {
if (layout.type === 'group') {
if (layout.groupId !== groupId) return layout;
const newLeaf: EditorGroupLeaf = { type: 'group', groupId: newGroupId };
return {
type: 'split',
id: nextId(),
direction,
ratio: 0.5,
first: placement === 'before' ? newLeaf : layout,
second: placement === 'before' ? layout : newLeaf
};
}
return {
...layout,
first: splitLayout(layout.first, groupId, newGroupId, direction, placement),
second: splitLayout(layout.second, groupId, newGroupId, direction, placement)
};
}
function replaceLayoutGroup(layout: EditorLayout, groupId: string, replacementId: string): EditorLayout {
if (layout.type === 'group') {
return layout.groupId === groupId ? { type: 'group', groupId: replacementId } : layout;
}
return {
...layout,
first: replaceLayoutGroup(layout.first, groupId, replacementId),
second: replaceLayoutGroup(layout.second, groupId, replacementId)
};
}
function removeLayoutGroup(layout: EditorLayout, groupId: string): EditorLayout | null {
if (layout.type === 'group') return layout.groupId === groupId ? null : layout;
const first = removeLayoutGroup(layout.first, groupId);
const second = removeLayoutGroup(layout.second, groupId);
if (!first) return second;
if (!second) return first;
return { ...layout, first, second };
}
function layoutGroupIds(layout: EditorLayout): string[] {
return layout.type === 'group'
? [layout.groupId]
: [...layoutGroupIds(layout.first), ...layoutGroupIds(layout.second)];
}
function isEditorLayout(value: unknown): value is EditorLayout {
if (!value || typeof value !== 'object') return false;
const node = value as Partial<EditorLayout>;
return node.type === 'group'
? typeof node.groupId === 'string'
: node.type === 'split' &&
typeof node.id === 'string' &&
(node.direction === 'horizontal' || node.direction === 'vertical') &&
typeof node.ratio === 'number' &&
isEditorLayout(node.first) &&
isEditorLayout(node.second);
}
function createLayout(groups: EditorGroup[], direction: SplitDirection, ratio: number): EditorLayout {
let layout: EditorLayout = { type: 'group', groupId: groups[0].id };
for (const group of groups.slice(1)) {
layout = {
type: 'split',
id: nextId(),
direction,
ratio,
first: layout,
second: { type: 'group', groupId: group.id }
};
}
return layout;
}
function normalizeLayout(
layout: unknown,
groups: EditorGroup[],
direction: SplitDirection,
ratio: number
): EditorLayout {
if (!isEditorLayout(layout)) return createLayout(groups, direction, ratio);
const ids = layoutGroupIds(layout);
const groupIds = groups.map((group) => group.id);
return ids.length === groupIds.length &&
ids.every((id) => groupIds.includes(id)) &&
new Set(ids).size === ids.length
? layout
: createLayout(groups, direction, ratio);
}
// ── Stores ──────────────────────────────────────────────────────
/** The workspace currently displayed in THIS browser tab. Null = welcome page. */
@@ -453,6 +567,7 @@ export async function loadWorkspace(path: string): Promise<void> {
path: canonicalWorkspacePath,
groups,
activeGroupId,
layout: normalizeLayout(ws.layout, groups, ws.splitDirection ?? 'horizontal', ws.splitRatio ?? 0.5),
splitDirection: ws.splitDirection ?? 'horizontal',
splitRatio: ws.splitRatio ?? 0.5,
fileBrowserCwd: ws.fileBrowserCwd ?? canonicalWorkspacePath
@@ -876,10 +991,14 @@ export function closeTab(tabId: string, groupId?: string): void {
// If active group was removed, switch to first remaining
const activeGroupStillExists = newGroups.some((g) => g.id === ws.activeGroupId);
const closedGroupStillExists = newGroups.some((g) => g.id === gid);
return {
...ws,
groups: newGroups,
layout: closedGroupStillExists
? ws.layout
: removeLayoutGroup(ws.layout, gid) ?? { type: 'group', groupId: newGroups[0].id },
activeGroupId: activeGroupStillExists ? ws.activeGroupId : newGroups[0].id
};
});
@@ -962,22 +1081,13 @@ export function clearTabEdit(tabId: string): void {
// ── Split / Editor Group actions ────────────────────────────────
/** Open a file in a new split group (creates the group if needed) */
/** Open a file in a new editor group. */
export function openInSplit(filePath: string, direction?: SplitDirection): void {
const ws = get(currentWorkspace);
if (!ws) return;
const dir = direction ?? ws.splitDirection ?? 'horizontal';
// If there's already a second group, open in it
if (ws.groups.length > 1) {
const otherGroup = ws.groups.find((g) => g.id !== ws.activeGroupId);
if (otherGroup) {
openFileTab(filePath, otherGroup.id);
return;
}
}
// Create a new group with this file
const name = getPathDisplayName(filePath, filePath);
const newTab: Tab = { id: nextId(), type: 'file', label: name, filePath };
@@ -993,6 +1103,7 @@ export function openInSplit(filePath: string, direction?: SplitDirection): void
...ws,
groups: [...ws.groups, newGroup],
activeGroupId: newGroup.id,
layout: splitLayout(ws.layout, ws.activeGroupId, newGroup.id, dir),
splitDirection: dir,
splitRatio: ws.splitRatio ?? 0.5
};
@@ -1010,15 +1121,6 @@ export function splitCurrentTab(direction?: SplitDirection): void {
const dir = direction ?? ws.splitDirection ?? 'horizontal';
// If already split, focus the other group
if (ws.groups.length > 1) {
const otherGroup = ws.groups.find((g) => g.id !== ws.activeGroupId);
if (otherGroup) {
setActiveGroup(otherGroup.id);
return;
}
}
// Copy the tab into a new group
const newTab: Tab = { ...tab, id: nextId(), permanent: false };
const newGroup: EditorGroup = {
@@ -1033,6 +1135,7 @@ export function splitCurrentTab(direction?: SplitDirection): void {
...ws,
groups: [...ws.groups, newGroup],
activeGroupId: newGroup.id,
layout: splitLayout(ws.layout, group.id, newGroup.id, dir),
splitDirection: dir,
splitRatio: ws.splitRatio ?? 0.5
};
@@ -1070,7 +1173,8 @@ export function closeGroup(groupId: string): void {
return {
...ws,
groups: newGroups,
activeGroupId: targetGroup.id
activeGroupId: targetGroup.id,
layout: removeLayoutGroup(ws.layout, groupId) ?? { type: 'group', groupId: targetGroup.id }
};
});
}
@@ -1100,10 +1204,12 @@ export function moveTabToGroup(tabId: string, fromGroupId: string, toGroupId: st
newGroups = newGroups.filter((g) => g.tabs.length > 0);
if (newGroups.length === 0) newGroups = [createDefaultGroup()];
const sourceGroupStillExists = newGroups.some((g) => g.id === fromGroupId);
const targetGroupStillExists = newGroups.some((g) => g.id === toGroupId);
return {
...ws,
groups: newGroups,
layout: sourceGroupStillExists ? ws.layout : removeLayoutGroup(ws.layout, fromGroupId) ?? ws.layout,
activeGroupId: targetGroupStillExists ? toGroupId : newGroups[0].id
};
});
@@ -1112,11 +1218,12 @@ export function moveTabToGroup(tabId: string, fromGroupId: string, toGroupId: st
export function moveTabToNewSplit(
tabId: string,
fromGroupId: string,
targetGroupId: string,
direction: SplitDirection,
placement: 'before' | 'after' = 'after'
): void {
currentWorkspace.update((ws) => {
if (!ws || ws.groups.length > 1) return ws;
if (!ws) return ws;
const fromGroup = ws.groups.find((g) => g.id === fromGroupId);
if (!fromGroup) return ws;
const tab = fromGroup.tabs.find((t) => t.id === tabId);
@@ -1132,12 +1239,25 @@ export function moveTabToNewSplit(
const tabs = g.tabs.filter((t) => t.id !== tabId);
return { ...g, tabs, activeTabId: tabs[0]?.id ?? '' };
});
const sourceGroupRemoved = groups.some((group) => group.id === fromGroupId && group.tabs.length === 0);
groups = groups.filter((g) => g.tabs.length > 0);
groups.push(newGroup);
let layout = ws.layout;
if (sourceGroupRemoved) {
layout =
fromGroupId === targetGroupId
? replaceLayoutGroup(layout, fromGroupId, newGroup.id)
: removeLayoutGroup(layout, fromGroupId) ?? layout;
}
if (!(sourceGroupRemoved && fromGroupId === targetGroupId)) {
layout = splitLayout(layout, targetGroupId, newGroup.id, direction, placement);
}
return {
...ws,
groups: placement === 'before' ? [newGroup, ...groups] : [...groups, newGroup],
groups,
activeGroupId: newGroup.id,
layout,
splitDirection: direction,
splitRatio: ws.splitRatio ?? 0.5
};
@@ -1148,8 +1268,23 @@ export function setSplitDirection(direction: SplitDirection): void {
currentWorkspace.update((ws) => (ws ? { ...ws, splitDirection: direction } : ws));
}
export function setSplitRatio(ratio: number): void {
export function setSplitRatio(splitId: string, ratio: number): void {
currentWorkspace.update((ws) =>
ws ? { ...ws, splitRatio: Math.max(0.2, Math.min(0.8, ratio)) } : ws
ws
? {
...ws,
layout: updateSplitRatio(ws.layout, splitId, ratio)
}
: ws
);
}
function updateSplitRatio(layout: EditorLayout, splitId: string, ratio: number): EditorLayout {
if (layout.type === 'group') return layout;
if (layout.id === splitId) return { ...layout, ratio: Math.max(0.2, Math.min(0.8, ratio)) };
return {
...layout,
first: updateSplitRatio(layout.first, splitId, ratio),
second: updateSplitRatio(layout.second, splitId, ratio)
};
}
+144 -153
View File
@@ -19,7 +19,7 @@
showSearch,
pwaPreferences
} from '$lib/stores';
import type { Tab, EditorGroup, SplitDirection, WorkspaceState } from '$lib/stores';
import type { Tab, EditorGroup, EditorLayout, SplitDirection, WorkspaceState } from '$lib/stores';
import { t } from '$lib/i18n';
import { get } from 'svelte/store';
import { getWelcome, getWorkspaceState } from '$lib/apis/state';
@@ -582,31 +582,34 @@
// ── Draggable divider ──────────────────────────────────────────
let isDragging = $state(false);
let containerEl: HTMLDivElement | undefined = $state();
let resizingSplit = $state<{
splitId: string;
direction: SplitDirection;
element: HTMLElement;
} | null>(null);
function handleDividerPointerDown(e: PointerEvent) {
function handleDividerPointerDown(e: PointerEvent, split: Extract<EditorLayout, { type: 'split' }>) {
e.preventDefault();
isDragging = true;
(e.target as HTMLElement).setPointerCapture(e.pointerId);
const divider = e.currentTarget as HTMLElement;
resizingSplit = { splitId: split.id, direction: split.direction, element: divider.parentElement! };
divider.setPointerCapture(e.pointerId);
}
function handleDividerPointerMove(e: PointerEvent) {
if (!isDragging || !containerEl) return;
const rect = containerEl.getBoundingClientRect();
const direction = $currentWorkspace?.splitDirection ?? 'horizontal';
if (!resizingSplit) return;
const rect = resizingSplit.element.getBoundingClientRect();
let ratio: number;
if (direction === 'horizontal') {
if (resizingSplit.direction === 'horizontal') {
ratio = (e.clientX - rect.left) / rect.width;
} else {
ratio = (e.clientY - rect.top) / rect.height;
}
setSplitRatio(ratio);
setSplitRatio(resizingSplit.splitId, ratio);
}
function handleDividerPointerUp() {
isDragging = false;
resizingSplit = null;
}
// Computed
@@ -622,16 +625,10 @@
});
const allGroups = $derived($currentWorkspace?.groups ?? []);
const splitDirection = $derived($currentWorkspace?.splitDirection ?? 'horizontal');
const splitRatio = $derived($currentWorkspace?.splitRatio ?? 0.5);
// On mobile, collapse to just the active group
const displayGroups = $derived(
isWideScreen
? allGroups
: allGroups.filter((g) => g.id === $currentWorkspace?.activeGroupId).slice(0, 1)
const layout = $derived($currentWorkspace?.layout ?? null);
const activeGroup = $derived(
allGroups.find((group) => group.id === $currentWorkspace?.activeGroupId) ?? allGroups[0] ?? null
);
const hasSplit = $derived(displayGroups.length > 1);
function getGroupActiveTab(group: EditorGroup): Tab | null {
return group.tabs.find((t) => t.id === group.activeTabId) ?? null;
@@ -644,7 +641,19 @@
type SplitDropZone = 'left' | 'right' | 'top' | 'bottom';
type TabDragPayload = { tabId: string; groupId: string };
let dragOverZone = $state<SplitDropZone | null>(null);
let dragOverZone = $state<{ groupId: string; zone: SplitDropZone } | null>(null);
$effect(() => {
const clearSplitPreview = () => (dragOverZone = null);
document.addEventListener('dragend', clearSplitPreview, true);
document.addEventListener('drop', clearSplitPreview, true);
window.addEventListener('blur', clearSplitPreview);
return () => {
document.removeEventListener('dragend', clearSplitPreview, true);
document.removeEventListener('drop', clearSplitPreview, true);
window.removeEventListener('blur', clearSplitPreview);
};
});
function hasTabDrag(dataTransfer: DataTransfer): boolean {
return dataTransfer.types.includes(TAB_DRAG_MIME) || dataTransfer.types.includes('text/tab-id');
@@ -668,11 +677,11 @@
return tabId && groupId ? { tabId, groupId } : null;
}
function getSplitDropZone(e: DragEvent): SplitDropZone | null {
if (!containerEl || !isWideScreen || hasSplit || !e.dataTransfer) return null;
function getSplitDropZone(e: DragEvent, pane: HTMLElement): SplitDropZone | null {
if (!isWideScreen || !e.dataTransfer) return null;
if (e.dataTransfer.types.includes('Files') || !hasTabDrag(e.dataTransfer)) return null;
const rect = containerEl.getBoundingClientRect();
const rect = pane.getBoundingClientRect();
if (
e.clientX < rect.left ||
e.clientX > rect.right ||
@@ -701,27 +710,29 @@
return candidates[0]?.zone ?? null;
}
function handleContainerDragOver(e: DragEvent) {
const zone = getSplitDropZone(e);
function handlePaneDragOver(e: DragEvent, groupId: string) {
const zone = getSplitDropZone(e, e.currentTarget as HTMLElement);
if (!zone) {
dragOverZone = null;
if (dragOverZone?.groupId === groupId) dragOverZone = null;
return;
}
e.preventDefault();
e.dataTransfer!.dropEffect = 'move';
dragOverZone = zone;
dragOverZone = { groupId, zone };
}
function handleContainerDragLeave(e: DragEvent) {
// Only reset if leaving the container entirely
if (containerEl && !containerEl.contains(e.relatedTarget as Node)) {
function handlePaneDragLeave(e: DragEvent, groupId: string) {
if (!(e.currentTarget as HTMLElement).contains(e.relatedTarget as Node) && dragOverZone?.groupId === groupId) {
dragOverZone = null;
}
}
function handleContainerDrop(e: DragEvent) {
const zone = dragOverZone ?? getSplitDropZone(e);
function handlePaneDrop(e: DragEvent, targetGroupId: string) {
const zone =
dragOverZone?.groupId === targetGroupId
? dragOverZone.zone
: getSplitDropZone(e, e.currentTarget as HTMLElement);
if (!zone || !e.dataTransfer) {
dragOverZone = null;
@@ -738,7 +749,7 @@
const direction: SplitDirection =
zone === 'left' || zone === 'right' ? 'horizontal' : 'vertical';
const placement = zone === 'left' || zone === 'top' ? 'before' : 'after';
moveTabToNewSplit(payload.tabId, payload.groupId, direction, placement);
moveTabToNewSplit(payload.tabId, payload.groupId, targetGroupId, direction, placement);
dragOverZone = null;
}
</script>
@@ -890,114 +901,92 @@
{:else}
<!-- Editor groups layout -->
<div
bind:this={containerEl}
class="split-container"
class:split-horizontal={splitDirection === 'horizontal'}
class:split-vertical={splitDirection === 'vertical'}
class:is-dragging={isDragging}
class:is-dragging={resizingSplit !== null}
role="presentation"
ondragover={handleContainerDragOver}
ondragleave={handleContainerDragLeave}
ondrop={handleContainerDrop}
>
{#each displayGroups as group, i (group.id)}
{@const groupTab = getGroupActiveTab(group)}
{#if i > 0}
<!-- Divider between groups -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="split-divider"
class:split-divider-h={splitDirection === 'horizontal'}
class:split-divider-v={splitDirection === 'vertical'}
onpointerdown={handleDividerPointerDown}
onpointermove={handleDividerPointerMove}
onpointerup={handleDividerPointerUp}
onpointercancel={handleDividerPointerUp}
>
<div class="split-divider-handle"></div>
</div>
{/if}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="split-pane"
class:split-pane-single={!hasSplit}
style={hasSplit
? splitDirection === 'horizontal'
? `width: ${i === 0 ? splitRatio * 100 : (1 - splitRatio) * 100}%;`
: `height: ${i === 0 ? splitRatio * 100 : (1 - splitRatio) * 100}%;`
: ''}
onclick={() => setActiveGroup(group.id)}
>
<!-- Per-group tab bar -->
<GroupTabBar {group} canClose={hasSplit} isPrimary={i === 0} />
<!-- Tab content -->
<div class="pane-content">
{#if $gitReviewOpen && i === 0}
<GitView />
{:else}
<!-- Persist all tab instances so state survives tab switches (like VS Code) -->
{#each group.tabs.filter((t) => t.type === 'file' && t.filePath) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<FileEditor filePath={tab.filePath!} tabId={tab.id} edit={tab.edit === true} />
</div>
{/each}
{#each group.tabs.filter((t) => t.type === 'chat') as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<ChatPanel
workspace={$currentWorkspace.path}
chatId={tab.path?.startsWith('new-') || tab.path?.startsWith('pending-')
? undefined
: tab.path}
tabId={tab.id}
/>
</div>
{/each}
{#each group.tabs.filter((t) => t.type === 'terminal' && t.sessionId) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<Terminal sessionId={tab.sessionId!} />
</div>
{/each}
{#each group.tabs.filter((t) => t.type === 'preview' && t.port) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<PortPreview port={tab.port!} />
</div>
{/each}
<!-- Fallback content for non-persisted states -->
{#if !groupTab || groupTab.type === 'files'}
<FileBrowser />
{:else if groupTab.type === 'terminal' && !groupTab.sessionId}
<div class="flex items-center justify-center h-full">
<Spinner size={20} />
</div>
{/if}
{/if}
</div>
</div>
{/each}
<!-- Drop zone indicators for drag-to-split -->
{#if dragOverZone === 'left'}
<div class="split-drop-zone split-drop-left"></div>
{/if}
{#if dragOverZone === 'right'}
<div class="split-drop-zone split-drop-right"></div>
{/if}
{#if dragOverZone === 'top'}
<div class="split-drop-zone split-drop-top"></div>
{/if}
{#if dragOverZone === 'bottom'}
<div class="split-drop-zone split-drop-bottom"></div>
{#if isWideScreen && layout}
{@render renderLayout(layout)}
{:else if activeGroup}
{@render renderPane(activeGroup)}
{/if}
</div>
{/if}
{#snippet renderLayout(node: EditorLayout)}
{#if node.type === 'group'}
{@const group = allGroups.find((item) => item.id === node.groupId)}
{#if group}{@render renderPane(group)}{/if}
{:else}
<div class="split-branch" class:split-branch-horizontal={node.direction === 'horizontal'} class:split-branch-vertical={node.direction === 'vertical'}>
<div class="split-branch-child" style={`flex: ${node.ratio} 1 0%;`}>
{@render renderLayout(node.first)}
</div>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="split-divider"
class:split-divider-h={node.direction === 'horizontal'}
class:split-divider-v={node.direction === 'vertical'}
onpointerdown={(event) => handleDividerPointerDown(event, node)}
onpointermove={handleDividerPointerMove}
onpointerup={handleDividerPointerUp}
onpointercancel={handleDividerPointerUp}
></div>
<div class="split-branch-child" style={`flex: ${1 - node.ratio} 1 0%;`}>
{@render renderLayout(node.second)}
</div>
</div>
{/if}
{/snippet}
{#snippet renderPane(group: EditorGroup)}
{@const groupTab = getGroupActiveTab(group)}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="split-pane"
onclick={() => setActiveGroup(group.id)}
ondragover={(event) => handlePaneDragOver(event, group.id)}
ondragleave={(event) => handlePaneDragLeave(event, group.id)}
ondrop={(event) => handlePaneDrop(event, group.id)}
>
<GroupTabBar {group} canClose={allGroups.length > 1} isPrimary={group.id === allGroups[0]?.id} />
<div class="pane-content">
{#if $gitReviewOpen && group.id === allGroups[0]?.id}
<GitView />
{:else}
{#each group.tabs.filter((tab) => tab.type === 'file' && tab.filePath) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<FileEditor filePath={tab.filePath!} tabId={tab.id} edit={tab.edit === true} />
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'chat') as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<ChatPanel workspace={$currentWorkspace!.path} chatId={tab.path?.startsWith('new-') || tab.path?.startsWith('pending-') ? undefined : tab.path} tabId={tab.id} />
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'terminal' && tab.sessionId) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<Terminal sessionId={tab.sessionId!} />
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'preview' && tab.port) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<PortPreview port={tab.port!} />
</div>
{/each}
{#if !groupTab || groupTab.type === 'files'}
<FileBrowser />
{:else if groupTab.type === 'terminal' && !groupTab.sessionId}
<div class="flex items-center justify-center h-full"><Spinner size={20} /></div>
{/if}
{/if}
</div>
{#if dragOverZone?.groupId === group.id}
<div class={`split-drop-zone split-drop-${dragOverZone.zone}`}></div>
{/if}
</div>
{/snippet}
{#if pendingIntent}
<WorkspacePicker
intent={pendingIntent}
@@ -1032,30 +1021,40 @@
color: var(--app-fg);
}
.split-horizontal {
.split-branch {
display: flex;
flex: 1;
min-width: 0;
min-height: 0;
overflow: hidden;
}
.split-branch-horizontal {
flex-direction: row;
}
.split-vertical {
.split-branch-vertical {
flex-direction: column;
}
.split-branch-child {
display: flex;
min-width: 0;
min-height: 0;
overflow: hidden;
}
/* Panes */
.split-pane {
display: flex;
flex: 1;
flex-direction: column;
position: relative;
overflow: hidden;
min-width: 0;
min-height: 0;
}
/* Single pane takes all space even while preview overlays are mounted. */
.split-pane-single {
flex: 1;
width: 100%;
height: 100%;
}
.pane-content {
flex: 1;
min-height: 0;
@@ -1131,14 +1130,6 @@
user-select: none;
}
.is-dragging.split-horizontal {
cursor: col-resize;
}
.is-dragging.split-vertical {
cursor: row-resize;
}
/* ── Drop zones for drag-to-split ─────────────────── */
.split-drop-zone {
position: absolute;