Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 9661981d59 fix(vcs): focus the changes tree when the Commit tool window opens
Opening the Commit tool window from its stripe button or shortcut put the
focus in the commit message, because the message field was the window's
activation target. The tree now takes the activation focus; Commit…
(Cmd/Ctrl+K) asks for the message, which then gets it until it loses focus.
The Commit dialog keeps focusing the message.
2026-12-05 01:02:01 +08:00
4 змінених файлів з 28 додано та 3 видалено

No files matched your search

+9 -2
Переглянути файл
@@ -1550,15 +1550,19 @@ export function CommitMessageField({
runner,
chooseAmendTarget,
onOpenToolWindow,
focusOnRequest,
}: {
runner: CommitRunner;
chooseAmendTarget?: boolean;
onOpenToolWindow?: () => void;
/** Take the activation focus only when Commit… asked for the message (the Commit window focuses its tree). */
focusOnRequest?: boolean;
}) {
const git = useCommitTargetsGit();
const message = useCommit((s) => s.message);
const amend = useCommit((s) => s.amend);
const focusTick = useCommit((s) => s.focusTick);
const messageFocus = useCommit((s) => s.messageFocus);
const ref = useRef<HTMLTextAreaElement>(null);
const [historyOpen, setHistoryOpen] = useState(false);
const historyTick = useCommit((s) => s.historyTick);
@@ -1643,7 +1647,10 @@ export function CommitMessageField({
</div>
<textarea
ref={ref}
data-autofocus
data-autofocus={!focusOnRequest || messageFocus || undefined}
onBlur={() => {
if (useCommit.getState().messageFocus) useCommit.setState({ messageFocus: false });
}}
className={clsx(styles.message, !showMargin && styles.noMargin, emptyError && styles.messageError)}
aria-invalid={emptyError || undefined}
style={{
@@ -1789,7 +1796,7 @@ function CommitPanel({ included }: { included: number }) {
return (
<div className={styles.commit}>
<CommitMessageField runner={runner} chooseAmendTarget />
<CommitMessageField runner={runner} chooseAmendTarget focusOnRequest />
{(author || authorDate) && (
<div className={styles.commitAuthor}>
{author && (
+12
Переглянути файл
@@ -416,6 +416,18 @@ describe("Commit… from a Project view directory", () => {
expect(useCommit.getState().checks.get("/p/module/sub/b.ts")).toBe("all");
expect(useCommit.getState().checks.get("/p/module-old/a.ts")).toBe("none");
});
it("gives the Commit tool window's focus to the message only for Commit…", () => {
const show = vi.fn();
provideToolWindowService({ show } as unknown as ToolWindowService);
useProject.setState({ settings: { vcs: { commit: { nonModal: true } } } as Settings });
useCommit.setState({ messageFocus: false });
commitFromContext({});
expect(show).toHaveBeenCalledWith("commit", true);
expect(useCommit.getState().messageFocus).toBe(true);
});
});
describe("log tabs of their own", () => {
+3
Переглянути файл
@@ -80,6 +80,8 @@ interface CommitState extends CommitAuthorDetails {
unstagedSelection: string[];
/** Bumped to focus the message field. */
focusTick: number;
/** Commit… asked for the message: the Commit window gives it the focus on activation instead of the changes tree. */
messageFocus: boolean;
/** Bumped to open the commit message history popup. */
historyTick: number;
checkResult: (CommitCheckRun & { stale?: boolean }) | null;
@@ -126,6 +128,7 @@ export const useCommit = create<CommitState>(() => ({
selectionKeys: [],
unstagedSelection: [],
focusTick: 0,
messageFocus: false,
historyTick: 0,
checkResult: null,
operation: null,
+4 -1
Переглянути файл
@@ -36,7 +36,10 @@ export function showLocalChanges(tab: CommitTab = "changes", focus = true) {
/** Commit… (⌘K): focuses the commit message of the Commit window, or opens the Commit dialog. */
export function openCommit() {
if (!isModalCommit()) return showLocalChanges("changes");
if (!isModalCommit()) {
useCommit.setState((s) => ({ messageFocus: true, focusTick: s.focusTick + 1 }));
return showLocalChanges("changes");
}
void import("./CommitDialog").then((m) => m.showCommitDialog());
}