дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
feat(vcs): add option to filter Git Log on single click in Branches pane (#8040)
* feat(vcs): add option to filter Git Log on single click in Branches pane * fix(vcs): do not update branch filter on context-menu right click --------- Co-authored-by: LU XIANGRUI <[email protected]> Co-authored-by: l0ng-ai <[email protected]>
Цей коміт міститься в:
8 files changed
+58
-2
No files matched your search
@@ -15,6 +15,10 @@ const OPTIONS: { key: Flag; label: string }[] = [
|
||||
{ key: "refsOnLeft", label: "Show references on the left" },
|
||||
];
|
||||
|
||||
const BRANCHES: { key: Flag; label: string }[] = [
|
||||
{ key: "branchClickFilters", label: "Update branch filter on single click" },
|
||||
];
|
||||
|
||||
const COLUMNS: { key: Flag; label: string }[] = [
|
||||
{ key: "showAuthor", label: "Author" },
|
||||
{ key: "showHash", label: "Hash" },
|
||||
@@ -43,6 +47,7 @@ export function LogSettingsPage() {
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<OptionGroup title="View Options">{OPTIONS.map(flag)}</OptionGroup>
|
||||
<OptionGroup title="Branches pane">{BRANCHES.map(flag)}</OptionGroup>
|
||||
<OptionGroup title="Visible columns">{COLUMNS.map(flag)}</OptionGroup>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -46,6 +46,7 @@ import { ContextMenuHost, iconMarkup } from "@/ui";
|
||||
import syncStyles from "../BranchSync.module.css";
|
||||
import { BranchesPanel } from "../log/BranchesPanel";
|
||||
import { FilterBar } from "../log/FilterBar";
|
||||
import { setLogOptions } from "../logOptions";
|
||||
import { useBranchesPane } from "../logPaneActions";
|
||||
import { emptyFilters, useGitLog } from "../logStore";
|
||||
import { useVcs } from "../store";
|
||||
@@ -113,6 +114,35 @@ describe("Git Log branches pane", () => {
|
||||
expect(screen.getByText("feature").closest("[data-row]")).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
|
||||
it("one click filters the log when branchClickFilters is enabled, ignoring group rows", () => {
|
||||
setLogOptions({ branchClickFilters: true });
|
||||
try {
|
||||
render(<BranchesPanel />);
|
||||
fireEvent.mouseDown(screen.getByText("feature"));
|
||||
expect(useGitLog.getState().filters.branches).toEqual(["feature"]);
|
||||
fireEvent.mouseDown(screen.getByText("Local"));
|
||||
expect(useGitLog.getState().filters.branches).toEqual(["feature"]);
|
||||
fireEvent.mouseDown(screen.getByText("main"));
|
||||
expect(useGitLog.getState().filters.branches).toEqual(["main"]);
|
||||
} finally {
|
||||
setLogOptions({ branchClickFilters: false });
|
||||
}
|
||||
});
|
||||
|
||||
it("right click selects the branch without changing the log filter when branchClickFilters is enabled", () => {
|
||||
setLogOptions({ branchClickFilters: true });
|
||||
try {
|
||||
render(<BranchesPanel />);
|
||||
fireEvent.mouseDown(screen.getByText("feature"));
|
||||
expect(useGitLog.getState().filters.branches).toEqual(["feature"]);
|
||||
fireEvent.mouseDown(screen.getByText("main"), { button: 2 });
|
||||
expect(useGitLog.getState().filters.branches).toEqual(["feature"]);
|
||||
expect(screen.getByText("main").closest("[data-row]")).toHaveAttribute("aria-selected", "true");
|
||||
} finally {
|
||||
setLogOptions({ branchClickFilters: false });
|
||||
}
|
||||
});
|
||||
|
||||
it("collapses and expands every group from the toolbar", () => {
|
||||
render(<BranchesPanel />);
|
||||
expect(screen.getByText("feature")).toBeInTheDocument();
|
||||
|
||||
@@ -558,5 +558,7 @@ describe("Settings › Version Control › Log", () => {
|
||||
expect(useLogOptions.getState().tagNames).toBe(!DEFAULT_LOG_OPTIONS.tagNames);
|
||||
fireEvent.click(screen.getByLabelText("Hash"));
|
||||
expect(useLogOptions.getState().showHash).toBe(!DEFAULT_LOG_OPTIONS.showHash);
|
||||
fireEvent.click(screen.getByLabelText("Update branch filter on single click"));
|
||||
expect(useLogOptions.getState().branchClickFilters).toBe(!DEFAULT_LOG_OPTIONS.branchClickFilters);
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,7 @@ import { summarizeBranchSync, type BranchSyncSummary } from "../branchSyncState"
|
||||
import { FetchButton } from "../FetchButton";
|
||||
import styles from "../GitLog.module.css";
|
||||
import { LogIdContext } from "../logContext";
|
||||
import { useLogOptions } from "../logOptions";
|
||||
import { canUpdateBranch, useBranchesPane, type BranchTarget } from "../logPaneActions";
|
||||
import { reloadLog, scopedLogRepositories, setLogBranches, setLogFilters, useGitLog } from "../logStore";
|
||||
import { branchesByRepo } from "../multiRoot";
|
||||
@@ -87,6 +88,7 @@ function sharedHead(roots: readonly string[]): string | null {
|
||||
|
||||
export function BranchesPanel() {
|
||||
const scope = useContext(LogIdContext);
|
||||
const branchClickFilters = useLogOptions((s) => s.branchClickFilters);
|
||||
const shown = useGitLog((s) => s.shownLog);
|
||||
const active = !scope || scope === shown;
|
||||
const logGeneration = useGitLog((s) => s.generation);
|
||||
@@ -475,7 +477,16 @@ export function BranchesPanel() {
|
||||
}}
|
||||
getTooltip={(n) => mergedRefTooltip(n, (r) => repoName(branchRoots[r] ?? r))}
|
||||
selected={selected}
|
||||
onSelectionChange={(sel) => setSelected(sel)}
|
||||
onSelectionChange={(sel, _lead, reason) => {
|
||||
setSelected(sel);
|
||||
if (!branchClickFilters || reason === "contextMenu") return;
|
||||
const branchTargets = refs.filter((r) => sel.has(r.key)).map(({ ref, repo }) => ({ ref, repo }));
|
||||
if (!branchTargets.length) return;
|
||||
setLogFilters({
|
||||
branches: [...new Set(branchTargets.map(({ ref }) => ref))],
|
||||
branchTargets: branchTargets.some(({ repo }) => repo) ? branchTargets : undefined,
|
||||
});
|
||||
}}
|
||||
onActivate={(n) => {
|
||||
if (!n.ref) return;
|
||||
const activated = selected.has(n.key) ? targets : expand(n, scopedRepo);
|
||||
|
||||
@@ -34,6 +34,8 @@ export interface LogOptions {
|
||||
highlightCurrentBranch: boolean;
|
||||
/** The Branches pane on the left of the log. */
|
||||
showBranches: boolean;
|
||||
/** Single-clicking a branch in the Branches pane updates the log's branch filter. */
|
||||
branchClickFilters: boolean;
|
||||
/** Changed files grouped by directory (else a flat list). */
|
||||
groupByDirectory: boolean;
|
||||
/** Selecting a changed file updates the embedded preview or an open editor preview. */
|
||||
@@ -74,6 +76,7 @@ export const DEFAULT_LOG_OPTIONS: LogOptions = {
|
||||
highlightMerges: true,
|
||||
highlightCurrentBranch: true,
|
||||
showBranches: true,
|
||||
branchClickFilters: false,
|
||||
groupByDirectory: true,
|
||||
diffPreview: true,
|
||||
showLineStats: false,
|
||||
@@ -101,6 +104,7 @@ const APPLICATION_LOG_OPTION_KEYS = [
|
||||
"showHash",
|
||||
"showSignature",
|
||||
"showGitHubChecks",
|
||||
"branchClickFilters",
|
||||
"diffPreview",
|
||||
"changesFromParents",
|
||||
"diffLocation",
|
||||
|
||||
@@ -16,7 +16,7 @@ export function activateSettingsPages(): () => void {
|
||||
id: "vcs.log",
|
||||
title: "Log",
|
||||
order: 6,
|
||||
keywords: ["git log", "references", "tags", "columns", "commit time"],
|
||||
keywords: ["git log", "references", "tags", "columns", "commit time", "branches", "branch filter", "single click"],
|
||||
component: lazyComponent(() => import("./LogSettingsPage").then((m) => m.LogSettingsPage)),
|
||||
});
|
||||
return () => {
|
||||
|
||||
@@ -4288,6 +4288,8 @@
|
||||
"Cannot read the whole values": "Cannot read the whole values",
|
||||
"The result changed since this page was read. Run the query again.": "The result changed since this page was read. Run the query again.",
|
||||
"View Options": "View Options",
|
||||
"Branches pane": "Branches pane",
|
||||
"Update branch filter on single click": "Update branch filter on single click",
|
||||
"Visible columns": "Visible columns",
|
||||
"Install Ruff to optimize imports in Python files": "Install Ruff to optimize imports in Python files",
|
||||
"Optimize Imports (Ruff)": "Optimize Imports (Ruff)",
|
||||
|
||||
@@ -6847,6 +6847,8 @@
|
||||
"{removed} lines deleted": "删除了 {removed} 行",
|
||||
"Show commit time rather than author time": "显示提交时间而非作者时间",
|
||||
"Show references on the left": "在左侧显示引用",
|
||||
"Branches pane": "分支面板",
|
||||
"Update branch filter on single click": "单击时更新分支过滤",
|
||||
"Visible columns": "可见列",
|
||||
"Open Repository Version": "打开仓库版本",
|
||||
"Open the selected files as they exist after the change": "打开所选文件在该更改之后的版本",
|
||||
|
||||
Reference in new issue
Заблокувати користувача