Порівняти коміти

..
Автор SHA1 Повідомлення Дата
l0ng-ai 4e114163d9 fix(editor): put pinned tabs in the editor tab action slot 2026-11-23 07:09:21 +08:00
16 змінених файлів з 132 додано та 112 видалено

No files matched your search

+37
Переглянути файл
@@ -88,3 +88,40 @@ test("a close button on the left keeps a narrow slot before the icon", async ({
const slot = await box(closeOf(selected));
expect(slot.x + slot.width).toBeLessThanOrEqual(label.x + 0.5);
});
test("a pinned editor tab uses the close slot and can be unpinned from it", async ({ workbench: page }) => {
await openFromTree(page, "README.md");
await openFromTree(page, "build.gradle.kts");
const strip = page.getByRole("tablist", { name: "Editor tabs" });
const unpinned = strip.getByRole("tab", { name: "build.gradle.kts", exact: true });
const pinned = strip.getByRole("tab", { name: "build.gradle.kts Pinned", exact: true });
const menu = page.getByRole("menu", { name: "Context menu" });
const pin = async () => {
await unpinned.click({ button: "right" });
await menu.getByRole("menuitem", { name: "Pin Tab", exact: true }).click();
};
await pin();
const unpin = pinned.locator("..").getByRole("button", { name: "Unpin Tab", exact: true });
for (const closeButtonPosition of ["right", "left"]) {
await setTabs(page, { closeButtonPosition });
await expect(closeOf(pinned)).toHaveCount(0);
const tab = await box(pinned.locator(".."));
const action = await box(unpin);
const label = await box(pinned.locator(":scope > span"));
const inset = closeButtonPosition === "left" ? action.x - tab.x : tab.x + tab.width - action.x - action.width;
expect(inset).toBeCloseTo(2, 0);
expect(action.width).toBeCloseTo(16, 0);
if (closeButtonPosition === "left") expect(action.x + action.width).toBeLessThanOrEqual(label.x);
else expect(action.x).toBeGreaterThanOrEqual(label.x + label.width);
}
await setTabs(page, { showCloseButton: false });
await unpin.click();
await expect(unpinned).toHaveAttribute("aria-selected", "true");
await expect(closeOf(unpinned)).toHaveCount(0);
await pin();
await pinned.click({ button: "middle" });
await expect(pinned).toHaveCount(0);
});
-60
Переглянути файл
@@ -1,66 +1,6 @@
import type { Locator } from "@playwright/test";
import { expect, stubDesktop, test } from "./fixtures";
test("Find Usages places read and write filters with the other actions", async ({ workbench: page }) => {
await stubDesktop(page);
await page.evaluate(async () => {
const modulePath = "/src/features/code-insight/usages.ts";
const { useUsagesPopup } = await import(modulePath);
const path = "/dev/acme-api/src/SettlementService.ts";
const lines = ["const current = settlement;", "settlement = next;"];
window.__ipc.handlers.fs_read_text = () => lines.join("\n");
useUsagesPopup.setState({
open: true,
anchor: { x: 100, y: 150 },
symbol: "settlement",
loading: false,
scope: "project",
groups: [
{
path,
usages: lines.map((text, line) => ({
path,
line,
col: text.indexOf("settlement"),
endCol: text.indexOf("settlement") + "settlement".length,
text,
access: line === 0 ? "read" : "write",
})),
},
],
});
});
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
const read = { name: "Show read accesses", exact: true };
const write = { name: "Show write accesses", exact: true };
const actions = popup.getByRole("button", { name: "Show Preview", exact: true }).locator("..");
await expect(popup.getByRole("option")).toHaveCount(2);
for (const width of [1120, 540]) {
await page.setViewportSize({ width, height: 640 });
expect(await actions.getByRole("toolbar", { name: "Usage access filters", exact: true }).count()).toBe(1);
await expect(actions.getByRole("button", read)).toBeInViewport({ ratio: 1 });
await expect(actions.getByRole("button", write)).toBeInViewport({ ratio: 1 });
}
await actions.getByRole("button", write).click();
await expect(popup.getByRole("option")).toHaveCount(1);
await popup.getByRole("button", { name: /Open in Find Window/ }).click();
const view = page.getByRole("region", { name: "Find Usages", exact: true });
const toolbar = view.getByRole("toolbar", { name: "Usages actions", exact: true });
const readButton = toolbar.getByRole("button", read);
const writeButton = toolbar.getByRole("button", write);
await expect(readButton).toHaveAttribute("aria-pressed", "true");
await expect(writeButton).toHaveAttribute("aria-pressed", "false");
const a = (await readButton.boundingBox())!;
const b = (await writeButton.boundingBox())!;
expect(a.x).toBeCloseTo(b.x, 0);
expect(b.y).toBeGreaterThanOrEqual(a.y + a.height);
await expect(view.locator("mark")).toHaveCount(1);
await writeButton.click();
await expect(view.locator("mark")).toHaveCount(2);
});
async function checkSize(icon: Locator, size = 16) {
const dimensions = await icon.evaluate((node) => {
const style = getComputedStyle(node);
+24
Переглянути файл
@@ -12,6 +12,30 @@ const names = [
"InvoicePublisher.ts",
];
test("a pinned editor tab can be unpinned from the hidden tabs list", async ({ workbench: page }) => {
await page.setViewportSize({ width: 700, height: 650 });
await page.evaluate(async (first) => {
const module = "/src/workbench/contributions.ts";
const { editorService } = await import(/* @vite-ignore */ module);
await editorService().openFile(`/dev/acme-api/${first}`);
}, names[0]!);
const strip = page.getByRole("tablist", { name: "Editor tabs" });
const tab = strip.getByRole("tab", { name: names[0], exact: true });
await tab.click({ button: "right" });
await page.getByRole("menuitem", { name: "Pin Tab", exact: true }).click();
await page.evaluate(async (files) => {
const module = "/src/workbench/contributions.ts";
const { editorService } = await import(/* @vite-ignore */ module);
for (const name of files) await editorService().openFile(`/dev/acme-api/${name}`);
}, names.slice(1));
await strip.evaluate((element) => (element.scrollLeft = element.scrollWidth));
await page.getByRole("button", { name: "Show Hidden Tabs" }).click();
const row = page.getByRole("grid", { name: "Hidden Editor Tabs" }).getByRole("row").filter({ hasText: names[0]! });
await expect(row.getByRole("button", { name: "Close Tab", exact: true })).toHaveCount(0);
await row.getByRole("button", { name: "Unpin Tab", exact: true }).click();
await expect(tab).toHaveCount(1);
});
test("the editor overflow lists clipped tabs and can close or open one without touching visible tabs", async ({
workbench: page,
}) => {
-4
Переглянути файл
@@ -143,10 +143,6 @@
gap: var(--space-0-5);
padding: 0 6px 0 8px;
}
.pin {
color: var(--fg-muted);
margin-left: -2px;
}
.deprecated {
text-decoration-line: line-through;
}
+3 -9
Переглянути файл
@@ -38,7 +38,6 @@ import { useFileColors } from "@/workbench/fileColors";
import { EmptyEditor } from "@/workbench/EditorArea";
import {
EmptyState,
Icon,
IconButton,
Menu,
SplitGroup,
@@ -216,7 +215,6 @@ function PaneView({ paneId }: { paneId: string }) {
? (gitRevisionOf(t.input.path)?.revision.slice(0, 8) ?? basename(dirname(t.input.path)))
: null;
const kindMark = tabTrailing(t.input, kinds);
const pin = t.pinned ? <Icon name="pin" size={11} className={styles.pin} label="Pinned" /> : null;
const file = t.input.kind === "file" && t.input.path ? files.get(t.input.path) : undefined;
const title = markModified && dirty[i] ? `*${name}` : name;
const prefix = t.input.kind === "file" && dupe ? (dupe.endsWith("/") ? dupe : `${dupe}/`) : null;
@@ -242,6 +240,7 @@ function PaneView({ paneId }: { paneId: string }) {
: tabIcon(t.input, kinds)
: undefined,
italic: t.preview,
pinned: t.pinned,
error: t.input.kind === "file" && errors[i],
modified: dirty[i],
// IDEA: hiding the close button is visual only. Keep close gestures
@@ -252,13 +251,7 @@ function PaneView({ paneId }: { paneId: string }) {
tints[i] || (fileColors && t.input.kind === "file" && t.input.path ? fileColors(t.input.path) : undefined),
tintStrength: tints[i] ? undefined : "var(--file-tint-strength)",
tooltip: virtualTooltip(t.input) ?? (showFullPathOnHover ? (t.input.path ?? name) : undefined),
trailing:
kindMark || pin ? (
<>
{kindMark}
{pin}
</>
) : undefined,
trailing: kindMark,
};
});
}, [
@@ -369,6 +362,7 @@ function PaneView({ paneId }: { paneId: string }) {
onSelect={(id) => ctrl.activate(paneId, id)}
onClose={(id) => void ctrl.closeTab(paneId, id)}
onCloseOthers={(id) => void ctrl.closeOthers(paneId, id)}
onTogglePin={(id) => ctrl.togglePin(paneId, id)}
closeOnShiftClick
onDoubleClick={(id) => {
// IDEA: a preview tab becomes a regular one; any other tab maximizes the editor.
+2 -4
Переглянути файл
@@ -2,8 +2,6 @@
display: flex;
align-items: center;
gap: var(--space-0-5);
flex: none;
}
.vertical {
flex-direction: column;
padding: 3px 6px;
flex-shrink: 0;
}
+2 -9
Переглянути файл
@@ -1,6 +1,4 @@
import { create } from "zustand";
import clsx from "clsx";
import { useTx } from "@/platform/i18n";
import { IconButton } from "@/ui";
import type { Usage } from "./usages";
import styles from "./UsageAccessFilter.module.css";
@@ -47,16 +45,11 @@ export function filterUsageAccess(items: readonly Usage[], options: UsageAccessO
export const supportsUsageAccess = (items: readonly Usage[]) => items.some((u) => u.access && u.access !== "unknown");
export function UsageAccessFilter({ items, vertical }: { items: readonly Usage[]; vertical?: boolean }) {
const tx = useTx();
export function UsageAccessFilter({ items }: { items: readonly Usage[] }) {
const options = useUsageAccessOptions();
if (!supportsUsageAccess(items)) return null;
return (
<div
className={clsx(styles.toolbar, vertical && styles.vertical)}
role={vertical ? "group" : "toolbar"}
aria-label={tx("Usage access filters")}
>
<div className={styles.toolbar} role="toolbar" aria-label="Usage access filters">
<IconButton
icon="show-read-access"
size="small"
+1 -1
Переглянути файл
@@ -176,7 +176,6 @@ function UsagesPopupInner() {
</span>
</span>
<div className={styles.actions}>
<UsageAccessFilter items={all} />
{scope && (
<Select<UsageScope>
variant="ghost"
@@ -214,6 +213,7 @@ function UsagesPopupInner() {
</button>
</div>
</div>
<UsageAccessFilter items={all} />
{note && (
<div className={styles.note} data-testid="usages-note">
{note}
+1 -3
Переглянути файл
@@ -17,11 +17,8 @@
gap: var(--space-0-5);
padding: 4px 0;
border-right: 1px solid var(--border);
overflow-y: auto;
scrollbar-width: none;
}
.toolbarSep {
flex: none;
width: 16px;
height: 1px;
margin: 3px 0;
@@ -69,6 +66,7 @@
flex: 1;
min-height: 0;
}
.body > [role="toolbar"],
.body > .summary {
flex: 0 0 auto;
}
+1 -1
Переглянути файл
@@ -284,11 +284,11 @@ export function UsagesView() {
<IconButton icon="arrow-up" action="navigate.prevOccurrence" size="small" iconSize={16} />
<IconButton icon="arrow-down" action="navigate.nextOccurrence" size="small" iconSize={16} />
<span className={styles.toolbarSep} />
<UsageAccessFilter items={allUsages} vertical />
<IconButton icon="expand-all" title="Expand All" size="small" iconSize={16} onClick={() => setAll(false)} />
<IconButton icon="collapse-all" title="Collapse All" size="small" iconSize={16} onClick={() => setAll(true)} />
</div>
<div className={styles.body} onKeyDown={onKeyDown}>
<UsageAccessFilter items={allUsages} />
{!search.loading && !search.error && search.scope === "project" && (
<div className={styles.summary}>
<T>Usages in Project Files</T>
+1 -1
Переглянути файл
@@ -53,7 +53,7 @@ it("shows a plain count for unclassified searches after a Java access mode was s
});
const view = render(<UsagesView />);
expect(screen.getByText("2 results")).toBeInTheDocument();
expect(screen.queryByRole("group", { name: "Usage access filters" })).toBeNull();
expect(screen.queryByRole("toolbar", { name: "Usage access filters" })).toBeNull();
view.unmount();
useUsageAccessOptions.setState({ read: true, write: true });
useUsages.setState({ tabs: [], active: null });
-1
Переглянути файл
@@ -1578,7 +1578,6 @@
"Read the project's resolved Maven and Gradle dependencies": "Read the project's resolved Maven and Gradle dependencies",
"Resolved Dependencies": "Resolved Dependencies",
"Usages of {symbol}": "Usages of {symbol}",
"Usage access filters": "Usage access filters",
"Read the clipboard's text and images when you run one of its commands": "Read the clipboard's text and images when you run one of its commands",
"Output: {channel}": "Output: {channel}",
"You can close this tab.": "You can close this tab.",
+9 -5
Переглянути файл
@@ -22,6 +22,7 @@ interface Props {
onSelect: (id: string) => void;
onCloseTab?: (id: string) => void;
onCloseOthers?: (id: string) => void;
onTogglePin?: (id: string) => void;
onDismiss: () => void;
}
@@ -34,6 +35,7 @@ export function HiddenTabsPopup({
onSelect,
onCloseTab,
onCloseOthers,
onTogglePin,
onDismiss,
}: Props) {
const tr = useGivenTx();
@@ -131,20 +133,22 @@ export function HiddenTabsPopup({
className={styles.list}
renderItem={(item) => {
if (!item) return null;
const close = Boolean(onCloseTab && item.closable !== false && item.showCloseButton !== false);
const unpin = item.pinned && onTogglePin;
const close = onCloseTab && item.closable !== false && item.showCloseButton !== false;
const action = (
<div role="gridcell" className={styles.action}>
{item.modified && <span className={styles.modified} aria-label={tr("Modified")} />}
{close && (
{(unpin || close) && (
<IconButton
icon="close"
title="Close Tab"
icon={unpin ? "pin" : "close"}
title={unpin ? "Unpin Tab" : "Close Tab"}
size="small"
tabIndex={-1}
onMouseDown={(event) => event.preventDefault()}
onClick={(event) => {
event.stopPropagation();
if (event.altKey && onCloseOthers) onCloseOthers(item.id);
if (unpin) unpin(item.id);
else if (event.altKey && onCloseOthers) onCloseOthers(item.id);
else onCloseTab!(item.id);
}}
/>
+11 -1
Переглянути файл
@@ -137,6 +137,16 @@
.unpin {
color: var(--fg-muted);
}
.pinModified {
position: absolute;
top: calc(50% - 7px);
inset-inline-end: 1px;
width: var(--space-1);
height: var(--space-1);
border-radius: 50%;
background: var(--accent);
pointer-events: none;
}
.tab:hover .close,
.tab:where([data-context-menu-open]) .close,
.selected .close,
@@ -301,7 +311,7 @@
width: auto;
margin: 0;
}
.editor:not(.vertical) .close {
.editor:not(.vertical) :is(.close, .unpin) {
width: 16px;
}
.editor:not(.vertical) .closeSlot .modified {
+19
Переглянути файл
@@ -199,6 +199,25 @@ describe("Tabs interactions", () => {
expect(handles[0]!.togglePinSelected()).toBe(false);
});
it("shows the modified marker in a pinned editor tab's action slot", () => {
const onTogglePin = vi.fn();
render(
<Tabs
variant="editor"
items={[{ id: "b", label: "B", text: "B", pinned: true, modified: true }]}
activeId="b"
onSelect={() => {}}
onClose={() => {}}
onTogglePin={onTogglePin}
/>,
);
const unpin = screen.getByRole("button", { name: "Unpin Tab" });
expect(within(unpin.parentElement!).getByLabelText("Modified")).toBeVisible();
expect(screen.getByRole("tab", { name: "B Pinned" })).toBeVisible();
fireEvent.click(unpin);
expect(onTogglePin).toHaveBeenCalledWith("b");
});
it("a vertical strip moves with ↑/↓, shows actions above the tabs and has no overflow dropdown", () => {
const onSelect = vi.fn();
render(
+21 -13
Переглянути файл
@@ -34,10 +34,7 @@ export interface TabItem {
text?: string;
icon?: IconName | (string & {});
closable?: boolean;
/**
* Pinned (IDEA's content tabs): with `onTogglePin`, an Unpin button takes the close
* button's place, and the strip's close gestures leave the tab alone.
*/
/** With `onTogglePin`, the tab shows Unpin in the action slot. */
pinned?: boolean;
/**
* Visual only: hide this tab's close button without disabling its close
@@ -129,7 +126,7 @@ export interface TabsProps {
onClose?: (id: string) => void;
/** Alt+click on a close button (IDEA: close all other tabs). */
onCloseOthers?: (id: string) => void;
/** Pin / Unpin Tab on the selected tab, from the container (a tool window's content tabs). */
/** Toggle the pinned state of a tab. */
onTogglePin?: (id: string) => void;
/** Shift+left-click a tab closes it (editor tabs; plain clicks still select). */
closeOnShiftClick?: boolean;
@@ -183,6 +180,7 @@ export function Tabs({
...aria
}: TabsProps) {
const vertical = orientation === "vertical";
const protectPinned = variant !== "editor" && !!onTogglePin;
const given = useGivenTx();
const scrollRef = useRef<HTMLDivElement>(null);
const tabRefs = useRef(new Map<string, HTMLButtonElement>());
@@ -194,17 +192,17 @@ export function Tabs({
const [dragging, setDragging] = useState<string | null>(null);
const register = useContext(TabStripRegistry);
const latest = useRef({ items, activeId, onClose, onTogglePin });
const latest = useRef({ items, activeId, onClose, onTogglePin, protectPinned });
useLayoutEffect(() => {
latest.current = { items, activeId, onClose, onTogglePin };
latest.current = { items, activeId, onClose, onTogglePin, protectPinned };
});
useEffect(
() =>
register?.({
closeSelected: () => {
const { items, activeId, onClose, onTogglePin } = latest.current;
const { items, activeId, onClose, protectPinned } = latest.current;
const item = items.find((it) => it.id === activeId);
if (!item || !onClose || item.closable === false || (item.pinned && onTogglePin)) return false;
if (!item || !onClose || !canCloseTab(item, protectPinned)) return false;
onClose(item.id);
return true;
},
@@ -341,7 +339,7 @@ export function Tabs({
break;
case "Delete":
case "Backspace":
if (onClose && item.closable !== false && !(item.pinned && onTogglePin)) onClose(item.id);
if (onClose && canCloseTab(item, protectPinned)) onClose(item.id);
else return;
break;
case "Tab":
@@ -399,8 +397,9 @@ export function Tabs({
const pinned = !!onTogglePin && !!item.pinned;
// Whether a tab can be closed at all (gestures and the button). A hidden
// close button is visual only: middle click, Shift+click and Delete still work.
const closable = !!onClose && item.closable !== false && !pinned;
const showClose = closable && item.showCloseButton !== false;
const closable = !!onClose && canCloseTab(item, protectPinned);
const showClose = closable && !pinned && item.showCloseButton !== false;
const pinModified = pinned && variant === "editor" && item.modified;
return (
<div
key={item.id}
@@ -476,6 +475,7 @@ export function Tabs({
id={panelIdPrefix ? `${panelIdPrefix}-tab-${item.id}` : undefined}
aria-controls={panelIdPrefix ? `${panelIdPrefix}-panel-${item.id}` : undefined}
aria-selected={selected}
aria-label={pinned && variant === "editor" && item.text ? `${item.text} ${tx("Pinned")}` : undefined}
tabIndex={selected || (!activeId && index === 0) ? 0 : -1}
className={clsx(styles.tabButton, item.dimmed && styles.dimmed)}
style={item.color ? { color: item.color } : undefined}
@@ -500,7 +500,9 @@ export function Tabs({
{typeof item.label === "string" ? <Given>{item.label}</Given> : item.label}
</span>
{item.trailing}
{item.modified && !showClose && <span className={styles.modified} aria-label={tx("Modified")} />}
{item.modified && !showClose && !pinModified && (
<span className={styles.modified} aria-label={tx("Modified")} />
)}
</button>
{pinned && (
<span className={styles.closeSlot} data-tab-close>
@@ -516,6 +518,7 @@ export function Tabs({
onTogglePin!(item.id);
}}
/>
{pinModified && <span className={styles.pinModified} aria-label={tx("Modified")} />}
</span>
)}
{showClose && (
@@ -564,6 +567,7 @@ export function Tabs({
onSelect={onSelect}
onCloseTab={onClose}
onCloseOthers={onCloseOthers}
onTogglePin={onTogglePin}
onDismiss={closeMenu}
/>
)
@@ -584,6 +588,10 @@ export function Tabs({
);
}
function canCloseTab(item: TabItem, protectPinned: boolean): boolean {
return item.closable !== false && !(protectPinned && item.pinned);
}
/** Scrolls `scroller` horizontally just enough to show all of `child`. */
export function revealHorizontally(scroller: HTMLElement, child: HTMLElement) {
const s = scroller.getBoundingClientRect();