mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
feat(editor): resize the vertical editor tab column by dragging its edge (#3365)
With tabs placed left or right, the column could not be resized and was never narrower than 140 px. It now fits its longest name up to a limit (260 px by default); dragging its inner edge, or ←/→ on the focused edge, changes the limit for every editor group and it is remembered. The editor keeps at least 60% of each group. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
This commit is contained in:
@@ -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 |
|
||||
|
||||
@@ -107,6 +107,8 @@ description: "多光标与选区、行编辑、剪贴板历史、代码折叠、
|
||||
|
||||
标签页的位置、数量上限以及达到上限后的处理方式、预览标签页、排序方式,以及关闭标签页后激活哪一个,都在 **设置 › 编辑器 › 常规 › 编辑器标签页** 中设置。
|
||||
|
||||
标签页放在左侧或右侧时,标签页列的宽度随最长的名称变化,但不超过一个上限。拖动该列靠近编辑器的边缘(或聚焦后按 `←` / `→`)可以调整上限;调整对所有编辑器组生效,并会被记住。
|
||||
|
||||
## 拆分编辑器
|
||||
|
||||
| 操作 | macOS | Windows / Linux |
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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 && <SideTabsResizer side={tabPrefs.placement === "left" ? "left" : "right"} />}
|
||||
<div
|
||||
className={styles.content}
|
||||
role="tabpanel"
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Width limit of editor tabs placed left / right, as in IDEA: the column fits its
|
||||
* labels up to this limit, and dragging its inner edge sets the limit for every
|
||||
* editor group. Remembered across sessions.
|
||||
*/
|
||||
import type { CSSProperties, KeyboardEvent, PointerEvent } from "react";
|
||||
import { create } from "zustand";
|
||||
import { lockDragCursor } from "@/ui";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import styles from "./EditorArea.module.css";
|
||||
|
||||
const KEY = "openidea.editor.sideTabsWidth";
|
||||
const MIN_WIDTH = 80;
|
||||
const MAX_WIDTH = 800;
|
||||
const KEY_STEP = 16;
|
||||
/** CSS custom property read by `.tabsVertical` in EditorArea.module.css. */
|
||||
const LIMIT_VAR = "--side-tabs-limit";
|
||||
|
||||
function load(): number | null {
|
||||
try {
|
||||
const v: unknown = JSON.parse(localStorage.getItem(KEY) ?? "null");
|
||||
return typeof v === "number" && Number.isFinite(v) ? clamp(v) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function clamp(px: number) {
|
||||
return Math.round(Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, px)));
|
||||
}
|
||||
|
||||
/** `null`: the default limit from the stylesheet. */
|
||||
const useSideTabsWidth = create<{ width: number | null }>(() => ({ 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<HTMLDivElement>) => {
|
||||
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<HTMLDivElement>) => {
|
||||
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 (
|
||||
<div
|
||||
role="separator"
|
||||
aria-orientation="vertical"
|
||||
aria-label={tx("Resize editor tabs")}
|
||||
tabIndex={0}
|
||||
className={styles.sideTabsResizer}
|
||||
onPointerDown={onPointerDown}
|
||||
onKeyDown={onKeyDown}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1193,6 +1193,7 @@
|
||||
"Editor color scheme": "编辑器配色方案",
|
||||
"Editor resynchronised": "编辑器已重新同步",
|
||||
"Editor tabs": "编辑器标签页",
|
||||
"Resize editor tabs": "调整编辑器标签页宽度",
|
||||
"Editor › Font": "编辑器 › 字体",
|
||||
"Editor › General": "编辑器 › 常规",
|
||||
"Effect": "效果",
|
||||
|
||||
Reference in New Issue
Block a user