Compare commits

...
Author SHA1 Message Date
l0ng-ai 71650c50b8 feat(vcs): ⌘/Ctrl-click a repository in the log filter to see only it
The Git Log's Repository filter toggled repositories one by one, so
switching from backend to frontend meant unchecking backend first.
⌘-click (macOS) or Ctrl-click on a repository now replaces the
selection with that repository; a plain click still adds or removes it,
and each row's tooltip says so. Menu items gain an optional
modifier-click action and a row tooltip for this.

Fixes #4728
2026-11-20 17:55:20 +08:00
5 changed files with 58 additions and 13 deletions

No files matched your search

+13 -5
View File
@@ -1,5 +1,6 @@
import { tx } from "@/platform/i18n";
import { call, commands } from "@/platform/ipc";
import { isMacHost } from "@/platform/keymap";
import { Icon, IconButton, SearchField, type MenuItem } from "@/ui";
import clsx from "clsx";
import { useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -251,11 +252,18 @@ export function FilterBar() {
onOpen: (anchor: HTMLElement) =>
menuBelow(
anchor,
repositories.map((repo) => ({
label: repoName(repo),
checked: filters.repositories?.includes(repo) ?? false,
run: () => setLogFilters({ repositories: toggleRepository(filters.repositories, repo) }),
})),
repositories.map((repo) => {
const name = repoName(repo);
const modifier = isMacHost() ? "⌘" : "Ctrl";
return {
label: name,
verbatim: true,
checked: filters.repositories?.includes(repo) ?? false,
run: () => setLogFilters({ repositories: toggleRepository(filters.repositories, repo) }),
runWithModifier: () => setLogFilters({ repositories: [repo] }),
hint: tx`${modifier}+Click to only see "${name}"`,
};
}),
),
onClear: () => setLogFilters({ repositories: [] }),
},
+2 -1
View File
@@ -2788,5 +2788,6 @@
"Downloaded {files} files to {folder}": "Downloaded {files} files to {folder}",
"Download to {folder} finished with errors": "Download to {folder} finished with errors",
"Cannot download to {folder}": "Cannot download to {folder}",
"Copy the selected files and folders of a remote project to a folder on this computer": "Copy the selected files and folders of a remote project to a folder on this computer"
"Copy the selected files and folders of a remote project to a folder on this computer": "Copy the selected files and folders of a remote project to a folder on this computer",
"{modifier}+Click to only see \"{name}\"": "{modifier}+Click to only see \"{name}\""
}
+2 -1
View File
@@ -9151,5 +9151,6 @@
"Downloaded {files} files to {folder}": "已下载 {files} 个文件到 {folder}",
"Download to {folder} finished with errors": "下载到 {folder} 完成,但有错误",
"Cannot download to {folder}": "无法下载到 {folder}",
"Copy the selected files and folders of a remote project to a folder on this computer": "把远程项目中选中的文件和文件夹复制到本机的文件夹"
"Copy the selected files and folders of a remote project to a folder on this computer": "把远程项目中选中的文件和文件夹复制到本机的文件夹",
"{modifier}+Click to only see \"{name}\"": "{modifier}+点击仅显示“{name}”"
}
+14 -6
View File
@@ -15,7 +15,7 @@ import clsx from "clsx";
import { create } from "zustand";
import { getAction, isActionEnabled, executeActionFrom, actionToggled } from "@/platform/actions";
import { useContextKeys } from "@/platform/context";
import { shortcutLabel } from "@/platform/keymap";
import { hasPrimaryModifier, shortcutLabel } from "@/platform/keymap";
import { Icon, type IconName } from "./icons";
import { Popup, type PopupAnchor } from "./Popup";
import type { Placement } from "@floating-ui/react-dom";
@@ -48,6 +48,10 @@ export type MenuItem =
checked?: boolean;
danger?: boolean;
run?: () => void;
/** Run instead of `run` on ⌘-click (macOS) / Ctrl-click, e.g. "only this one" in a multi-choice filter. */
runWithModifier?: () => void;
/** Tooltip of the whole row (the label's own tooltip shows a truncated label). */
hint?: string;
/** The pointer or the keyboard made it the active item (not on opening the menu). */
onActive?: () => void;
submenu?: MenuItem[];
@@ -65,6 +69,8 @@ interface Resolved {
checked?: boolean;
danger?: boolean;
run?: () => void;
runWithModifier?: () => void;
hint?: string;
onActive?: () => void;
submenu?: MenuItem[];
}
@@ -205,7 +211,7 @@ export function MenuList({
}
};
const activate = (i: number) => {
const activate = (i: number, modifiers?: Pick<KeyboardEvent, "metaKey" | "ctrlKey">) => {
cancelHover();
const item = resolved[i];
if (!selectable(item)) return;
@@ -215,7 +221,8 @@ export function MenuList({
return;
}
onDone();
item!.run?.();
if (item!.runWithModifier && modifiers && hasPrimaryModifier(modifiers)) item!.runWithModifier();
else item!.run?.();
};
const cancelHover = () => {
@@ -320,7 +327,7 @@ export function MenuList({
break;
case "Enter":
case " ":
activate(active);
activate(active, e);
break;
default:
if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {
@@ -396,7 +403,8 @@ export function MenuList({
onMouseEnter={(e) => hover(i, { x: e.clientX, y: e.clientY })}
onPointerLeave={() => leave(i)}
onMouseLeave={() => leave(i)}
onClick={() => activate(i)}
onClick={(e) => activate(i, e)}
title={r.hint}
>
{numbers && (
<span className={styles.mnemonic} data-menu-number={numbersOf[i]} aria-hidden={true}>
@@ -408,7 +416,7 @@ export function MenuList({
{r.checked ? <Icon name="check" size={13} /> : r.icon ? <Icon name={r.icon} size={14} /> : null}
</span>
)}
<span className={styles.label} title={r.label}>
<span className={styles.label} title={r.hint ? undefined : r.label}>
{r.label}
</span>
{r.shortcut && (
+27
View File
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen } from "@testing-library/react";
import { getContext, setContext } from "@/platform/context";
import { registerAction } from "@/platform/actions";
import { usePlatform } from "@/platform/platformInfo";
import { Popup } from "./Popup";
import { ContextMenuHost, Menu, MenuList, hideContextMenu, showContextMenu, useContextMenuStore } from "./Menu";
import menuStyles from "./Menu.module.css";
@@ -265,6 +266,32 @@ describe("Menu action enablement", () => {
}
});
it("runs an item's modifier action on ⌘-click (macOS) or Ctrl-click, and shows its hint", () => {
const os = usePlatform.getState().os;
try {
for (const [platform, mod] of [
["macos", { metaKey: true }],
["linux", { ctrlKey: true }],
] as const) {
usePlatform.setState({ os: platform });
const run = vi.fn();
const only = vi.fn();
const items = [{ label: "frontend", run, runWithModifier: only, hint: "Only frontend" }];
const { unmount } = render(<MenuList items={items} onDone={() => {}} />);
const row = screen.getByRole("menuitem", { name: /frontend/ });
expect(row).toHaveAttribute("title", "Only frontend");
fireEvent.click(row);
expect(run).toHaveBeenCalledTimes(1);
fireEvent.click(row, mod);
expect(only).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledTimes(1);
unmount();
}
} finally {
usePlatform.setState({ os });
}
});
it("highlights the row under the pointer without moving focus", () => {
render(
<MenuList