From 21c4b08a5d54de6ecb4703fb401a3840eceb436e Mon Sep 17 00:00:00 2001 From: ntbang0901 <121003585+ntbang0901@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:06:19 +0530 Subject: [PATCH] fix(vcs): give the commit keys back when the focused commit list is removed (#7774) Closing a file history tab with the keyboard while its commit list had focus left vcsLogCommitsFocus on, because React reports no blur for a focused element it removes; Left and Right in the editor then moved to the child or parent commit instead of the caret. The commit list now clears that context when it is removed, as it already did for vcsLogRevisionFocus. Co-authored-by: ntbang0901 <121003585+ntbang0901@users.noreply.github.com> --- src/features/vcs/__tests__/logUiFeatures.test.tsx | 10 ++++++++++ src/features/vcs/log/CommitList.tsx | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/features/vcs/__tests__/logUiFeatures.test.tsx b/src/features/vcs/__tests__/logUiFeatures.test.tsx index 8b8a2f3701..1e76cd912d 100644 --- a/src/features/vcs/__tests__/logUiFeatures.test.tsx +++ b/src/features/vcs/__tests__/logUiFeatures.test.tsx @@ -1,4 +1,5 @@ import type { Commit } from "@/bindings"; +import { getContext } from "@/platform/context"; import { ContextMenuHost, hideContextMenu } from "@/ui"; import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; @@ -157,6 +158,15 @@ describe("log controls", () => { expect(useLogOptions.getState().collapseLinear).toBe(true); }); + it("gives the commit keys back when the focused list is removed", async () => { + const { unmount } = render(); + const list = await screen.findByRole("listbox", { name: "Commits" }); + act(() => list.focus()); + expect(getContext().vcsLogCommitsFocus).toBe(true); + unmount(); + expect(getContext().vcsLogCommitsFocus).toBe(false); + }); + it("keeps the selected middle commit visible under collapse and supports speed search", async () => { useLogOptions.setState({ collapseLinear: true }); useGitLog.setState({ selected: "/repo\0middle", selection: ["/repo\0middle"] }); diff --git a/src/features/vcs/log/CommitList.tsx b/src/features/vcs/log/CommitList.tsx index 27572468c7..9c6747915b 100644 --- a/src/features/vcs/log/CommitList.tsx +++ b/src/features/vcs/log/CommitList.tsx @@ -96,7 +96,14 @@ export function CommitList({ fileHistory = false }: { fileHistory?: boolean }) { const speedGeneration = useRef(0); const speedTimer = useRef | undefined>(undefined); useEffect(() => () => clearTimeout(speedTimer.current), []); - useEffect(() => () => setContext("vcsLogRevisionFocus", false), []); + // React reports no blur for a focused list it removes. + useEffect( + () => () => { + setContext("vcsLogRevisionFocus", false); + setContext("vcsLogCommitsFocus", false); + }, + [], + ); const columns = useMemo(() => { const builtins: LogColumn[] = [ ...(opts.showAuthor ? [{ id: "author", title: "Author", width: 130, render: (c: Commit) => c.author }] : []),