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 <[email protected]>
Цей коміт міститься в:
ntbang0901 authored and GitHub committed 2026-12-03 18:36:19 +08:00
1 джерело f8e0ad57ff
коміт 21c4b08a5d
2 files changed
+18 -1

No files matched your search

+10
Переглянути файл
@@ -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(<LogView />);
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"] });
+8 -1
Переглянути файл
@@ -96,7 +96,14 @@ export function CommitList({ fileHistory = false }: { fileHistory?: boolean }) {
const speedGeneration = useRef(0);
const speedTimer = useRef<ReturnType<typeof setTimeout> | 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 }] : []),