-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(web): add Cmd+F find in thread #4599
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
Open
colonelpanic8
wants to merge
6
commits into
pingdotgg:main
Choose a base branch
from
colonelpanic8:t3code/find-in-thread
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f7ad96
feat(web): add Cmd+F find in thread
colonelpanic8 449a74a
fix(web): address find-in-thread review feedback
colonelpanic8 a9597b5
fix(web): address follow-up find review feedback
colonelpanic8 82d1ffa
fix(web): preserve find composition and context display
colonelpanic8 f625827
fix(web): respect hidden find contexts
colonelpanic8 ba5a3b3
fix(web): align thread find highlights with match identity
colonelpanic8 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
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,125 @@ | ||
| import { useEffect, useRef, type KeyboardEvent } from "react"; | ||
| import { ChevronDownIcon, ChevronUpIcon, XIcon } from "lucide-react"; | ||
| import { Button } from "../ui/button"; | ||
| import { formatThreadFindCount } from "./threadFind"; | ||
|
|
||
| interface FindInThreadBarProps { | ||
| query: string; | ||
| matchCount: number; | ||
| activeIndex: number; | ||
| /** Bumped by the caller to pull focus back into the field on a repeat Cmd+F. */ | ||
| focusRequestId: number; | ||
| onQueryChange: (query: string) => void; | ||
| onNext: () => void; | ||
| onPrevious: () => void; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export function FindInThreadBar({ | ||
| query, | ||
| matchCount, | ||
| activeIndex, | ||
| focusRequestId, | ||
| onQueryChange, | ||
| onNext, | ||
| onPrevious, | ||
| onClose, | ||
| }: FindInThreadBarProps) { | ||
| const inputRef = useRef<HTMLInputElement | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const input = inputRef.current; | ||
| if (!input) { | ||
| return; | ||
| } | ||
| input.focus(); | ||
| input.select(); | ||
| }, [focusRequestId]); | ||
|
|
||
| const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => { | ||
| if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) { | ||
| return; | ||
| } | ||
| if (event.key === "Escape") { | ||
| event.preventDefault(); | ||
|
macroscopeapp[bot] marked this conversation as resolved.
|
||
| event.stopPropagation(); | ||
| onClose(); | ||
| return; | ||
| } | ||
| if (event.key === "Enter") { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| if (event.shiftKey) { | ||
| onPrevious(); | ||
| } else { | ||
| onNext(); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const hasQuery = query.trim().length > 0; | ||
| const noResults = hasQuery && matchCount === 0; | ||
|
|
||
| return ( | ||
| <div | ||
| role="search" | ||
| aria-label="Find in thread" | ||
| className="pointer-events-auto flex items-center gap-1 rounded-full border border-border/60 bg-card px-2 py-1 shadow-md" | ||
| > | ||
| <input | ||
| ref={inputRef} | ||
| type="text" | ||
| value={query} | ||
| aria-label="Find in thread" | ||
| placeholder="Find in thread" | ||
| spellCheck={false} | ||
| autoComplete="off" | ||
| onChange={(event) => onQueryChange(event.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| className="h-6 w-44 bg-transparent px-1 text-sm text-foreground outline-none placeholder:text-muted-foreground/72" | ||
| /> | ||
| <span | ||
| aria-live="polite" | ||
| className={ | ||
| noResults | ||
| ? "min-w-10 shrink-0 text-center text-xs tabular-nums text-destructive" | ||
| : "min-w-10 shrink-0 text-center text-xs tabular-nums text-muted-foreground" | ||
| } | ||
| > | ||
| {hasQuery ? formatThreadFindCount(activeIndex, matchCount) : ""} | ||
| </span> | ||
| <Button | ||
| type="button" | ||
| size="xs" | ||
| variant="ghost" | ||
| aria-label="Previous match" | ||
| disabled={matchCount === 0} | ||
| onClick={onPrevious} | ||
| className="size-6 p-0" | ||
| > | ||
| <ChevronUpIcon className="size-3.5" /> | ||
| </Button> | ||
| <Button | ||
| type="button" | ||
| size="xs" | ||
| variant="ghost" | ||
| aria-label="Next match" | ||
| disabled={matchCount === 0} | ||
| onClick={onNext} | ||
| className="size-6 p-0" | ||
| > | ||
| <ChevronDownIcon className="size-3.5" /> | ||
| </Button> | ||
| <Button | ||
| type="button" | ||
| size="xs" | ||
| variant="ghost" | ||
| aria-label="Close find" | ||
| onClick={onClose} | ||
| className="size-6 p-0" | ||
| > | ||
| <XIcon className="size-3.5" /> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.