diff --git a/docs/en/guide/editor.mdx b/docs/en/guide/editor.mdx index b95fdb496..07999bab8 100644 --- a/docs/en/guide/editor.mdx +++ b/docs/en/guide/editor.mdx @@ -107,6 +107,8 @@ To format on every save, enable **Reformat code** (and optionally **Optimize imp Tab placement, the tab limit and what happens when it is reached, the preview tab, sorting, and which tab is activated after one closes are set in **Settings › Editor › General › Editor Tabs**. +With tabs placed left or right, the tab column is as wide as its longest name, up to a limit. Drag the column's inner edge (or focus it and press `←` / `→`) to change the limit; it applies to every editor group and is remembered. + ## Split editors | Action | macOS | Windows / Linux | diff --git a/docs/zh/guide/editor.mdx b/docs/zh/guide/editor.mdx index cd1432f4a..9c524ba06 100644 --- a/docs/zh/guide/editor.mdx +++ b/docs/zh/guide/editor.mdx @@ -107,6 +107,8 @@ description: "多光标与选区、行编辑、剪贴板历史、代码折叠、 标签页的位置、数量上限以及达到上限后的处理方式、预览标签页、排序方式,以及关闭标签页后激活哪一个,都在 **设置 › 编辑器 › 常规 › 编辑器标签页** 中设置。 +标签页放在左侧或右侧时,标签页列的宽度随最长的名称变化,但不超过一个上限。拖动该列靠近编辑器的边缘(或聚焦后按 `←` / `→`)可以调整上限;调整对所有编辑器组生效,并会被记住。 + ## 拆分编辑器 | 操作 | macOS | Windows / Linux | diff --git a/e2e/editor.spec.ts b/e2e/editor.spec.ts index c8b6308b6..e3b7ece4a 100644 --- a/e2e/editor.spec.ts +++ b/e2e/editor.spec.ts @@ -285,3 +285,38 @@ test("vertical tabs leave a narrow editor group most of its width", async ({ wor expect(contentBox!.width).toBeGreaterThanOrEqual(paneBox!.width * 0.6 - 1); } }); + +test("dragging the vertical tab column's edge resizes it and the width is kept", async ({ workbench: page }) => { + await openFromTree(page, "settings.gradle.kts"); + const placeLeft = () => + page.evaluate(async () => { + const projectModule = "/src/platform/project.ts"; + const schemaModule = "/src/features/settings/model/schema.ts"; + const [{ useProject }, { DEFAULT_SETTINGS }] = await Promise.all([ + import(/* @vite-ignore */ projectModule), + import(/* @vite-ignore */ schemaModule), + ]); + const base = useProject.getState().settings ?? DEFAULT_SETTINGS; + useProject.setState({ + settings: { ...base, editor: { ...base.editor, tabs: { ...base.editor.tabs, placement: "left" } } }, + }); + }); + await placeLeft(); + + const strip = page.getByRole("tablist", { name: "Editor tabs" }); + const handle = page.getByRole("separator", { name: "Resize editor tabs" }); + const before = (await strip.boundingBox())!.width; + const box = (await handle.boundingBox())!; + await page.mouse.move(box.x, box.y + box.height / 2); + await page.mouse.down(); + await page.mouse.move(box.x - 60, box.y + box.height / 2, { steps: 5 }); + await page.mouse.up(); + await expect.poll(async () => (await strip.boundingBox())!.width).toBeLessThan(before - 40); + const narrowed = (await strip.boundingBox())!.width; + + // The next session starts with the dragged width. + await page.reload(); + await openFromTree(page, "settings.gradle.kts"); + await placeLeft(); + await expect.poll(async () => Math.round((await strip.boundingBox())!.width)).toBe(Math.round(narrowed)); +}); diff --git a/src/editor/core/view/EditorArea.module.css b/src/editor/core/view/EditorArea.module.css index ee4652e97..d8f69ada5 100644 --- a/src/editor/core/view/EditorArea.module.css +++ b/src/editor/core/view/EditorArea.module.css @@ -270,13 +270,29 @@ } .tabsVertical > .tabs, .tabsVertical > .tabRows { + /* Fits the labels up to the draggable limit (SideTabsResizer); the editor keeps at least 60%. */ width: max-content; - /* A narrow editor group keeps most of its width for the editor; labels truncate. */ - min-width: min(140px, 40%); - max-width: min(260px, 40%); + max-width: min(var(--side-tabs-limit, 260px), 40%); border-bottom: none; border-right: 1px solid var(--border-editor-tabs, var(--border)); } +/* A zero-width handle on the column's inner border, with a wider hit area. */ +.sideTabsResizer { + position: relative; + z-index: 1; + flex: none; + width: 0; + outline: none; +} +.sideTabsResizer::after { + content: ""; + position: absolute; + inset: 0 -3px; + cursor: ew-resize; +} +.sideTabsResizer:focus-visible::after { + background: color-mix(in srgb, var(--focus-ring) 55%, transparent); +} .tabsVertical .tabRows > .tabs { min-height: 0; border-bottom: none; @@ -285,9 +301,12 @@ flex: 1 1 auto; border-top: 1px solid var(--border-editor-tabs, var(--border)); } +.tabsRight > .sideTabsResizer { + order: 1; +} .tabsRight > .tabs, .tabsRight > .tabRows { - order: 1; + order: 2; border-right: none; border-left: 1px solid var(--border-editor-tabs, var(--border)); } diff --git a/src/editor/core/view/EditorArea.tsx b/src/editor/core/view/EditorArea.tsx index 9a8782339..959201040 100644 --- a/src/editor/core/view/EditorArea.tsx +++ b/src/editor/core/view/EditorArea.tsx @@ -64,6 +64,7 @@ import { TextEditorHost } from "./TextEditorHost"; import { FindBar } from "./FindBar"; import { EditorBanners, VirtualBanner } from "./Banner"; import { CodeBreadcrumbs } from "./StatusItems"; +import { SideTabsResizer, useSideTabsStyle } from "./SideTabsResizer"; import styles from "./EditorArea.module.css"; import { tx } from "@/platform/i18n"; @@ -252,6 +253,7 @@ function PaneView({ paneId }: { paneId: string }) { const pinnedCount = tabs.filter((t) => t.pinned).length; // Settings › Editor Tabs › Tab placement Left / Right: a vertical, scrolling column. const vertical = tabPrefs.placement === "left" || tabPrefs.placement === "right"; + const sideTabsStyle = useSideTabsStyle(); const pinnedRow = tabPrefs.pinnedSeparateRow && pinnedCount > 0 && pinnedCount < tabs.length; const dnd = useMemo(() => { // A tab released outside the window detaches into a forced new window. @@ -366,6 +368,7 @@ function PaneView({ paneId }: { paneId: string }) { vertical && styles.tabsVertical, tabPrefs.placement === "right" && styles.tabsRight, )} + style={vertical ? sideTabsStyle : undefined} data-pane-id={paneId} data-focus-scope="" aria-label={tx("Editor")} @@ -381,6 +384,7 @@ function PaneView({ paneId }: { paneId: string }) { ) : ( strip(items, dnd.all, actions) )} + {vertical && !hidden && }
(() => ({ width: load() })); + +function setSideTabsWidth(px: number) { + const width = clamp(px); + useSideTabsWidth.setState({ width }); + try { + localStorage.setItem(KEY, JSON.stringify(width)); + } catch { + // Storage unavailable: the width lasts for this session. + } +} + +/** Style for the editor pane that holds a vertical tab column. */ +export function useSideTabsStyle(): CSSProperties | undefined { + const width = useSideTabsWidth((s) => s.width); + return width == null ? undefined : ({ [LIMIT_VAR]: `${width}px` } as CSSProperties); +} + +/** The drag handle on the editor side of the tab column; render it right after the column. */ +export function SideTabsResizer({ side }: { side: "left" | "right" }) { + const sign = side === "left" ? 1 : -1; + + const onPointerDown = (e: PointerEvent) => { + const handle = e.currentTarget; + const pane = handle.parentElement; + const start = handle.previousElementSibling?.getBoundingClientRect().width; + if (e.button !== 0 || !pane || start == null) return; + // No focus ring or text selection from a mouse drag. + e.preventDefault(); + handle.setPointerCapture(e.pointerId); + const origin = e.clientX; + const previous = pane.style.getPropertyValue(LIMIT_VAR); + const releaseCursor = lockDragCursor("ew-resize"); + let next: number | null = null; + // Only this pane follows the pointer; every group takes the new width on release. + const move = (ev: globalThis.PointerEvent) => { + if (!(ev.buttons & 1)) return end(); + next = clamp(start + sign * (ev.clientX - origin)); + pane.style.setProperty(LIMIT_VAR, `${next}px`); + }; + const end = () => { + handle.removeEventListener("pointermove", move); + handle.removeEventListener("pointerup", end); + handle.removeEventListener("pointercancel", end); + releaseCursor(); + if (next != null) setSideTabsWidth(next); + else if (previous) pane.style.setProperty(LIMIT_VAR, previous); + else pane.style.removeProperty(LIMIT_VAR); + }; + handle.addEventListener("pointermove", move); + handle.addEventListener("pointerup", end); + handle.addEventListener("pointercancel", end); + }; + + const onKeyDown = (e: KeyboardEvent) => { + const dir = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0; + const width = e.currentTarget.previousElementSibling?.getBoundingClientRect().width; + if (!dir || width == null) return; + e.preventDefault(); + setSideTabsWidth(width + sign * dir * KEY_STEP); + }; + + return ( +
+ ); +} diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index a96c05802..174a0163b 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1193,6 +1193,7 @@ "Editor color scheme": "编辑器配色方案", "Editor resynchronised": "编辑器已重新同步", "Editor tabs": "编辑器标签页", + "Resize editor tabs": "调整编辑器标签页宽度", "Editor › Font": "编辑器 › 字体", "Editor › General": "编辑器 › 常规", "Effect": "效果",