-
Notifications
You must be signed in to change notification settings - Fork 924
[codex] Fix changes sidebar modifier click behavior #4644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
apps/desktop/src/renderer/lib/clickPolicy/policies/changesSidebarFilePolicy.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import type { LinkTierMap } from "../types"; | ||
| import { | ||
| resolveChangesSidebarFileIntent, | ||
| tierForChangesSidebarFileIntent, | ||
| } from "./changesSidebarFilePolicy"; | ||
|
|
||
| const map: LinkTierMap = { | ||
| plain: "pane", | ||
| shift: "newTab", | ||
| meta: "pane", | ||
| metaShift: "external", | ||
| }; | ||
|
|
||
| describe("changes sidebar file policy", () => { | ||
| it("keeps plain click on the diff", () => { | ||
| expect( | ||
| resolveChangesSidebarFileIntent(map, { | ||
| metaKey: false, | ||
| ctrlKey: false, | ||
| shiftKey: false, | ||
| }), | ||
| ).toBe("diff"); | ||
| }); | ||
|
|
||
| it("maps shift-click through the settings map", () => { | ||
| expect( | ||
| resolveChangesSidebarFileIntent(map, { | ||
| metaKey: false, | ||
| ctrlKey: false, | ||
| shiftKey: true, | ||
| }), | ||
| ).toBe("diffNewTab"); | ||
| }); | ||
|
|
||
| it("maps cmd/ctrl-click to the file when the settings action is pane", () => { | ||
| expect( | ||
| resolveChangesSidebarFileIntent(map, { | ||
| metaKey: true, | ||
| ctrlKey: false, | ||
| shiftKey: false, | ||
| }), | ||
| ).toBe("file"); | ||
| expect( | ||
| resolveChangesSidebarFileIntent(map, { | ||
| metaKey: false, | ||
| ctrlKey: true, | ||
| shiftKey: false, | ||
| }), | ||
| ).toBe("file"); | ||
| }); | ||
|
|
||
| it("maps cmd/ctrl-shift-click to the external editor", () => { | ||
| expect( | ||
| resolveChangesSidebarFileIntent(map, { | ||
| metaKey: true, | ||
| ctrlKey: false, | ||
| shiftKey: true, | ||
| }), | ||
| ).toBe("external"); | ||
| expect( | ||
| resolveChangesSidebarFileIntent(map, { | ||
| metaKey: false, | ||
| ctrlKey: true, | ||
| shiftKey: true, | ||
| }), | ||
| ).toBe("external"); | ||
| }); | ||
|
|
||
| it("returns null for unbound tiers", () => { | ||
| expect( | ||
| resolveChangesSidebarFileIntent( | ||
| { ...map, meta: null }, | ||
| { | ||
| metaKey: true, | ||
| ctrlKey: false, | ||
| shiftKey: false, | ||
| }, | ||
| ), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("finds shortcuts for menu items from the same map", () => { | ||
| expect(tierForChangesSidebarFileIntent(map, "diffNewTab")).toBe("shift"); | ||
| expect(tierForChangesSidebarFileIntent(map, "file")).toBe("meta"); | ||
| expect(tierForChangesSidebarFileIntent(map, "external")).toBe("metaShift"); | ||
| }); | ||
| }); |
59 changes: 59 additions & 0 deletions
59
apps/desktop/src/renderer/lib/clickPolicy/policies/changesSidebarFilePolicy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { modifierLabel } from "../modifierLabel"; | ||
| import { tierFor } from "../tiers"; | ||
| import type { | ||
| LinkAction, | ||
| LinkTier, | ||
| LinkTierMap, | ||
| ModifierEvent, | ||
| } from "../types"; | ||
|
|
||
| export type ChangesSidebarFileIntent = | ||
| | "diff" | ||
| | "diffNewTab" | ||
| | "file" | ||
| | "external"; | ||
|
|
||
| const MODIFIER_TIERS: LinkTier[] = ["shift", "meta", "metaShift"]; | ||
|
|
||
| function intentFor( | ||
| tier: LinkTier, | ||
| action: LinkAction | null, | ||
| ): ChangesSidebarFileIntent | null { | ||
| if (action === null) return null; | ||
| if (action === "external") return "external"; | ||
| if (action === "newTab") return "diffNewTab"; | ||
| return tier === "plain" ? "diff" : "file"; | ||
| } | ||
|
|
||
| function shortIntentLabel(intent: ChangesSidebarFileIntent): string { | ||
| if (intent === "diff") return "diff"; | ||
| if (intent === "diffNewTab") return "diff in new tab"; | ||
| if (intent === "file") return "open file"; | ||
| return "editor"; | ||
| } | ||
|
|
||
| export function resolveChangesSidebarFileIntent( | ||
| map: LinkTierMap, | ||
| event: ModifierEvent, | ||
| ): ChangesSidebarFileIntent | null { | ||
| const tier = tierFor(event, "4-tier"); | ||
| return intentFor(tier, map[tier]); | ||
| } | ||
|
|
||
| export function tierForChangesSidebarFileIntent( | ||
| map: LinkTierMap, | ||
| intent: ChangesSidebarFileIntent, | ||
| ): LinkTier | null { | ||
| for (const tier of MODIFIER_TIERS) { | ||
| if (intentFor(tier, map[tier]) === intent) return tier; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export function buildChangesSidebarFileHint(map: LinkTierMap): string { | ||
| return MODIFIER_TIERS.flatMap((tier) => { | ||
| const intent = intentFor(tier, map[tier]); | ||
| if (intent === null) return []; | ||
| return `${modifierLabel(tier)}: ${shortIntentLabel(intent)}`; | ||
| }).join(" · "); | ||
| } |
29 changes: 29 additions & 0 deletions
29
apps/desktop/src/renderer/lib/clickPolicy/policies/useChangesSidebarFilePolicy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { useCallback, useMemo } from "react"; | ||
| import { | ||
| buildChangesSidebarFileHint, | ||
| type ChangesSidebarFileIntent, | ||
| resolveChangesSidebarFileIntent, | ||
| tierForChangesSidebarFileIntent, | ||
| } from "./changesSidebarFilePolicy"; | ||
| import { useSidebarFilePolicy } from "./useSidebarFilePolicy"; | ||
|
|
||
| export function useChangesSidebarFilePolicy() { | ||
| const policy = useSidebarFilePolicy(); | ||
|
|
||
| const getIntent = useCallback( | ||
| (event: Parameters<typeof resolveChangesSidebarFileIntent>[1]) => | ||
| resolveChangesSidebarFileIntent(policy.map, event), | ||
| [policy.map], | ||
| ); | ||
| const tierForIntent = useCallback( | ||
| (intent: ChangesSidebarFileIntent) => | ||
| tierForChangesSidebarFileIntent(policy.map, intent), | ||
| [policy.map], | ||
| ); | ||
| const hint = useMemo( | ||
| () => buildChangesSidebarFileHint(policy.map), | ||
| [policy.map], | ||
| ); | ||
|
|
||
| return { ...policy, getIntent, tierForIntent, hint }; | ||
| } |
73 changes: 73 additions & 0 deletions
73
apps/desktop/src/renderer/lib/clickPolicy/usePierreChangesSidebarRowClickPolicy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { useCallback } from "react"; | ||
| import type { ChangesSidebarFileIntent } from "./policies/changesSidebarFilePolicy"; | ||
| import { folderIntentFor } from "./policies/folderPolicy"; | ||
| import type { ModifierEvent } from "./types"; | ||
|
|
||
| interface UsePierreChangesSidebarRowClickPolicyOptions { | ||
| getFileIntent: (event: ModifierEvent) => ChangesSidebarFileIntent | null; | ||
| onSelectDiff: (relativePath: string, openInNewTab?: boolean) => void; | ||
| onOpenFile: (relativePath: string, openInNewTab?: boolean) => void; | ||
| openInExternalEditor: (relativePath: string) => void; | ||
| } | ||
|
|
||
| interface UsePierreChangesSidebarRowClickPolicyResult { | ||
| onClickCapture: (e: React.MouseEvent<HTMLDivElement>) => void; | ||
| findFileRow: (e: React.MouseEvent) => HTMLElement | null; | ||
| } | ||
|
|
||
| export function usePierreChangesSidebarRowClickPolicy({ | ||
| getFileIntent, | ||
| onSelectDiff, | ||
| onOpenFile, | ||
| openInExternalEditor, | ||
| }: UsePierreChangesSidebarRowClickPolicyOptions): UsePierreChangesSidebarRowClickPolicyResult { | ||
| const findRow = useCallback((e: React.MouseEvent): HTMLElement | null => { | ||
| const path = e.nativeEvent.composedPath(); | ||
| for (const node of path) { | ||
| if (!(node instanceof HTMLElement)) continue; | ||
| if (node.getAttribute("data-item-path")) return node; | ||
| } | ||
| return null; | ||
| }, []); | ||
|
|
||
| const findFileRow = useCallback( | ||
| (e: React.MouseEvent): HTMLElement | null => { | ||
| const row = findRow(e); | ||
| const itemPath = row?.getAttribute("data-item-path"); | ||
| if (!row || !itemPath || itemPath.endsWith("/")) return null; | ||
| return row; | ||
| }, | ||
| [findRow], | ||
| ); | ||
|
|
||
| const onClickCapture = useCallback( | ||
| (e: React.MouseEvent<HTMLDivElement>) => { | ||
| const treePath = findRow(e)?.getAttribute("data-item-path"); | ||
| if (!treePath) return; | ||
| const trimmed = treePath.endsWith("/") ? treePath.slice(0, -1) : treePath; | ||
|
|
||
| if (treePath.endsWith("/")) { | ||
| const intent = folderIntentFor(e); | ||
| if (intent === null) return; | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| if (intent === "external") openInExternalEditor(trimmed); | ||
| return; | ||
| } | ||
|
|
||
| const intent = getFileIntent(e); | ||
| if (intent === null) return; | ||
|
|
||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
|
|
||
| if (intent === "external") openInExternalEditor(trimmed); | ||
| else if (intent === "file") onOpenFile(trimmed, false); | ||
| else if (intent === "diffNewTab") onSelectDiff(trimmed, true); | ||
| else if (intent === "diff") onSelectDiff(trimmed, false); | ||
| }, | ||
| [findRow, getFileIntent, onSelectDiff, onOpenFile, openInExternalEditor], | ||
| ); | ||
|
|
||
| return { onClickCapture, findFileRow }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For file rows,
e.preventDefault()ande.stopPropagation()are called unconditionally beforegetFileIntent(e)is evaluated. WhengetFileIntentreturnsnull(unbound tier), the click event is fully consumed but no action is taken. In contrast, the folder branch does the opposite — it returns early without consuming the event whenfolderIntentForreturns null, allowing the tree to handle expansion/collapse normally. A user who explicitly unbinds a modifier tier for files will get a silent no-op with no visual feedback, while the same situation on a folder correctly falls through to the tree.Prompt To Fix With AI