diff --git a/e2e/logBranchRenameFollow.spec.ts b/e2e/logBranchRenameFollow.spec.ts index f60232491..61c83e3d6 100644 --- a/e2e/logBranchRenameFollow.spec.ts +++ b/e2e/logBranchRenameFollow.spec.ts @@ -74,6 +74,7 @@ async function openLogOnSd(page: Page) { operation: null, }); h.vcs_status = () => []; + h.fs_entry_kind = ({ path }) => (/\.(ts|md)$/.test(String(path)) ? "file" : "dir"); h.vcs_branches = () => branches; h.vcs_stashes = () => []; h.vcs_tags = () => []; @@ -99,6 +100,9 @@ async function openLogOnSd(page: Page) { const storeModule = "/src/features/vcs/store.ts"; const { useVcs, refreshNow, loadBranches } = await import(/* @vite-ignore */ storeModule); useVcs.setState({ available: true, root, repo: root, roots: [root], branchesLoaded: false, stashesLoaded: false }); + const contextModule = "/src/platform/context.ts"; + const { setContext } = await import(/* @vite-ignore */ contextModule); + setContext("vcsAvailable", true); await refreshNow(); await loadBranches(); const actionsModule = "/src/platform/actions.ts"; @@ -108,6 +112,33 @@ async function openLogOnSd(page: Page) { await expect(page.getByRole("listbox", { name: "Commits" }).getByRole("option").first()).toBeVisible(); } +test("Ctrl+L toggles focus between Git Log filters and commits, including File History", async ({ + workbench: page, +}) => { + await openLogOnSd(page); + const toolbar = page.getByRole("toolbar", { name: "Log filters", exact: true }); + const filter = toolbar.getByRole("textbox", { name: "Filter by message" }); + const commits = page.getByRole("listbox", { name: "Commits" }); + + await commits.focus(); + await page.keyboard.press("Control+L"); + await expect(filter).toBeFocused(); + await page.keyboard.press("Control+L"); + await expect(commits).toBeFocused(); + + await page.getByRole("treeitem", { name: "README.md", exact: true }).click({ button: "right" }); + await page.getByRole("menuitem", { name: "Git", exact: true }).hover(); + await page.getByRole("menuitem", { name: "Show History", exact: true }).click(); + const historyTab = page.getByRole("tablist", { name: "Git" }).getByRole("tab", { name: /History: README.md/ }); + await expect(historyTab).toHaveAttribute("aria-selected", "true"); + await expect(filter).toBeVisible(); + await commits.focus(); + await page.keyboard.press("Control+L"); + await expect(filter).toBeFocused(); + await page.keyboard.press("Control+L"); + await expect(commits).toBeFocused(); +}); + test("the log branch filter follows a branch rename from the log's own toolbar", async ({ workbench: page }) => { await openLogOnSd(page); const toolbar = page.getByRole("toolbar", { name: "Log filters", exact: true }); diff --git a/src/features/vcs/__tests__/focusTextFilter.test.ts b/src/features/vcs/__tests__/focusTextFilter.test.ts new file mode 100644 index 000000000..49e35d8da --- /dev/null +++ b/src/features/vcs/__tests__/focusTextFilter.test.ts @@ -0,0 +1,73 @@ +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { executeAction, getAction, isActionKeyEnabled } from "@/platform/actions"; +import { getContext, setContext } from "@/platform/context"; +import { IDEA_ACTIONS } from "@/platform/ideaActions"; +import { intellijMacos } from "@/platform/keymaps/intellij-macos"; +import { intellijWindows } from "@/platform/keymaps/intellij-windows"; +import { registerHistoryActions } from "../historyActions"; + +let unregister: (() => void) | undefined; +const originalContext = getContext(); + +beforeEach(() => { + setContext("vcsAvailable", true); + setContext("activeToolWindow", "git"); + document.body.innerHTML = ` +
+
+ + +
+
+ `; + unregister = registerHistoryActions(); +}); + +afterEach(() => { + unregister?.(); + unregister = undefined; + setContext("vcsAvailable", originalContext.vcsAvailable); + setContext("activeToolWindow", originalContext.activeToolWindow); + document.body.replaceChildren(); +}); + +describe("Focus Text Filter", () => { + it("maps IDEA's action and binds Ctrl+L only inside Git Log or File History", () => { + const action = getAction("vcs.log.focusTextFilter")!; + expect(action).toMatchObject({ title: "Focus Text Filter", category: "Git Log", keyWhen: expect.any(String) }); + expect(IDEA_ACTIONS["Vcs.Log.FocusTextFilter"]).toBe("vcs.log.focusTextFilter"); + expect(intellijWindows[action.id]).toEqual(["Ctrl+L"]); + expect(intellijMacos[action.id]).toEqual(["Ctrl+L"]); + expect(isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "git" })).toBe(true); + expect(isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "editor", vcsLogFocus: true })).toBe( + true, + ); + expect(isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "editor", editorTextFocus: true })).toBe( + false, + ); + // A popup over the log (Find, a filter menu) keeps its own Ctrl+L. + expect(isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "git", popupOpen: true })).toBe(false); + }); + + it("focuses the active log's message filter from outside its toolbar", async () => { + const commits = document.querySelector("[data-vcs-log-commits][data-active]")!; + commits.focus(); + await executeAction("vcs.log.focusTextFilter"); + expect(document.activeElement).toBe( + document.querySelector("[data-vcs-log-filters][data-active] [aria-label='Filter by message']"), + ); + }); + + it("returns to the active commit list when focus is inside the filters toolbar", async () => { + const button = document.querySelector("[data-vcs-log-filters][data-active] button")!; + button.focus(); + await executeAction("vcs.log.focusTextFilter"); + expect(document.activeElement).toBe(document.querySelector("[data-vcs-log-commits][data-active]")); + }); + + it("does nothing when no log view is active", async () => { + document.body.replaceChildren(); + await executeAction("vcs.log.focusTextFilter"); + expect(document.activeElement).toBe(document.body); + }); +}); diff --git a/src/features/vcs/historyActions.tsx b/src/features/vcs/historyActions.tsx index fb4a346cc..99363748d 100644 --- a/src/features/vcs/historyActions.tsx +++ b/src/features/vcs/historyActions.tsx @@ -91,6 +91,15 @@ const IN_COMMIT = "vcsAvailable && activeToolWindow == commit"; /** Shortcuts that act on the selected commit: only while the commit list has focus. */ const IN_COMMITS = "vcsLogCommitsFocus"; +function focusLogTextFilter() { + const filters = document.querySelector("[data-vcs-log-filters][data-active]"); + const commits = document.querySelector("[data-vcs-log-commits][data-active]"); + const target = filters?.contains(document.activeElement) + ? commits + : filters?.querySelector("[aria-label='Filter by message']"); + target?.focus({ preventScroll: true }); +} + /** The commit an action refers to: its argument (commit or id), else the Git Log selection. */ export function commitArg(arg: unknown): Commit | null { const { commits, selected } = useGitLog.getState(); @@ -396,6 +405,15 @@ export function registerHistoryActions(): () => void { }, }, + { + id: "vcs.log.focusTextFilter", + title: "Focus Text Filter", + category: "Git Log", + when: "vcsAvailable || projectOpen || vcsLogFocus", + keyWhen: `${IN_GIT_LOG} && !popupOpen`, + run: focusLogTextFilter, + }, + // --- Git Log commit context menu --- { id: "vcs.log.copyRevision", diff --git a/src/features/vcs/log/CommitList.tsx b/src/features/vcs/log/CommitList.tsx index 19643af35..27572468c 100644 --- a/src/features/vcs/log/CommitList.tsx +++ b/src/features/vcs/log/CommitList.tsx @@ -554,6 +554,8 @@ export function CommitList({ fileHistory = false }: { fileHistory?: boolean }) { role="listbox" aria-label={tx("Commits")} aria-multiselectable + data-vcs-log-commits + data-active={active ? "" : undefined} aria-activedescendant={selectedIndex >= 0 ? `commit-${scope ?? "log"}-${selectedIndex}` : undefined} tabIndex={0} onFocusCapture={() => { diff --git a/src/features/vcs/log/FilterBar.tsx b/src/features/vcs/log/FilterBar.tsx index 2d39df652..5e8d99c99 100644 --- a/src/features/vcs/log/FilterBar.tsx +++ b/src/features/vcs/log/FilterBar.tsx @@ -370,7 +370,13 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) { ]; return ( -
+
{!fileHistory && !comparison && !showBranches && ( diff --git a/src/platform/ideaActions.ts b/src/platform/ideaActions.ts index 6f0bb7a73..9784b5d3a 100644 --- a/src/platform/ideaActions.ts +++ b/src/platform/ideaActions.ts @@ -185,4 +185,5 @@ export const IDEA_ACTIONS: Readonly> = { ShowUmlDiagram: "db.showDiagram", ShowUmlDiagramPopup: "db.showDiagramPopup", "Vcs.CopyCommitSubjectAction": "vcs.log.copyCommitSubject", + "Vcs.Log.FocusTextFilter": "vcs.log.focusTextFilter", }; diff --git a/src/platform/keymaps/eclipse.test.ts b/src/platform/keymaps/eclipse.test.ts index dc12cbb90..a88596390 100644 --- a/src/platform/keymaps/eclipse.test.ts +++ b/src/platform/keymaps/eclipse.test.ts @@ -32,7 +32,7 @@ const owners = (km: Record, key: string) => // parent collisions are not introduced by this preset; new pairs must be reviewed here. const shared = [ ["navigate.gotoClass", "terminal.new"], - ["navigate.gotoLine", "agents.focusInput"], + ["navigate.gotoLine", "agents.focusInput", "vcs.log.focusTextFilter"], ["navigate.recentLocations", "project.open", "debug.jumpToSource", "diff.jumpToSource", "find.popup.openResult"], [ "navigate.declaration", diff --git a/src/platform/keymaps/ideaParity.test.ts b/src/platform/keymaps/ideaParity.test.ts index f0f885306..5c9338f0c 100644 --- a/src/platform/keymaps/ideaParity.test.ts +++ b/src/platform/keymaps/ideaParity.test.ts @@ -116,6 +116,7 @@ describe("IDEA keymap parity", () => { ["find.recentUsages", [], []], // Vcs.Log.GoToRef: Find in the Git Log table. ["vcs.log.goToRef", ["Meta+F"], ["Ctrl+F"]], + ["vcs.log.focusTextFilter", ["Ctrl+L"], ["Ctrl+L"]], // Back / Forward also carry the mouse side buttons (``). ["editor.codeBlockStartWithSelection", ["Meta+Alt+Shift+["], ["Ctrl+Shift+["]], ["editor.codeBlockEndWithSelection", ["Meta+Alt+Shift+]"], ["Ctrl+Shift+]"]], @@ -182,6 +183,9 @@ describe("IDEA keymap parity", () => { order(km, "navigate.nextOccurrence", "navigate.nextHighlightedUsage"); order(km, "code.moveElementLeft", "toolwindow.resizeLeft"); order(km, "find.inFile", "vcs.log.goToRef"); + order(km, "find.next", "vcs.log.focusTextFilter"); + order(km, "vcs.log.focusTextFilter", "agents.focusInput"); + order(km, "editor.scrollToCenter", "vcs.log.focusTextFilter"); // Inline (text editor only) wins over New Branch. order(km, "vcs.newBranch", "refactor.inline"); order(km, "vcs.addToVcs", "diff.applyRightSide"); diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.ts index d16ed8cf7..128295637 100644 --- a/src/platform/keymaps/intellij-macos.ts +++ b/src/platform/keymaps/intellij-macos.ts @@ -481,6 +481,8 @@ export const intellijMacos: Record = { "db.editCell": [], "db.showToolWindow": [], "agents.newTask": ["Meta+Shift+I"], + // Git Log / File History, outside popups. + "vcs.log.focusTextFilter": ["Ctrl+L"], "agents.focusInput": ["Meta+L"], "agents.cycleEffort": ["Alt+T"], "agents.showToolWindow": [], diff --git a/src/platform/keymaps/intellij-windows.ts b/src/platform/keymaps/intellij-windows.ts index 2bd22458e..fb3ee8732 100644 --- a/src/platform/keymaps/intellij-windows.ts +++ b/src/platform/keymaps/intellij-windows.ts @@ -479,6 +479,8 @@ export const intellijWindows: Record = { "db.editCell": [], "db.showToolWindow": [], "agents.newTask": ["Ctrl+Alt+Shift+I"], + // Git Log / File History (outside popups): before the Agents input, which yields to a panel claiming Ctrl+L. + "vcs.log.focusTextFilter": ["Ctrl+L"], "agents.focusInput": ["Ctrl+L"], "agents.cycleEffort": ["Alt+T"], "agents.showToolWindow": [], diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 440f431f1..e6ea0ae6a 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -4780,5 +4780,6 @@ "Cross-session learning for this task": "Cross-session learning for this task", "Session auto-memory mode": "Session auto-memory mode", "No memory files found.": "No memory files found.", - "No matching memories.": "No matching memories." + "No matching memories.": "No matching memories.", + "Focus Text Filter": "Focus Text Filter" } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 487ce5bf8..0353dde02 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -11424,5 +11424,6 @@ "Cross-session learning for this task": "此任务的跨会话学习策略", "Session auto-memory mode": "会话自动记忆模式", "No memory files found.": "未找到记忆文件。", - "No matching memories.": "没有匹配的记忆。" + "No matching memories.": "没有匹配的记忆。", + "Focus Text Filter": "聚焦文本过滤器" }