-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat(web): find text in the terminal with Cmd/Ctrl+F #11927
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
PwntasticKev
wants to merge
7
commits into
pingdotgg:main
Choose a base branch
from
PwntasticKev:feat/terminal-find
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
7 commits
Select commit
Hold shift + click to select a range
1800c1b
feat(web): find text in the terminal with Cmd/Ctrl+F
PwntasticKev 7eb8cf1
refactor(web): reuse existing search helpers in terminal find
PwntasticKev 3026d25
feat(web): condense terminal find bar and let it snap between corners
PwntasticKev ccccbd6
feat(web): open terminal find inline with the terminal action buttons
PwntasticKev e6ea2e1
fix(web): tighten terminal find spacing and stop the row shifting
PwntasticKev b72d9c7
feat(web): show the terminal find count inside the input
PwntasticKev 1dd858e
Merge remote-tracking branch 'origin/main' into feat/terminal-find
PwntasticKev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import type { ComponentType, MouseEventHandler, ReactNode } from "react"; | ||
| import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover"; | ||
|
|
||
| interface TerminalActionButtonProps { | ||
| readonly icon?: ComponentType<{ className?: string }>; | ||
| readonly label: string; | ||
| readonly className?: string; | ||
| readonly onClick: () => void; | ||
| readonly onMouseDown?: MouseEventHandler<HTMLButtonElement>; | ||
| readonly children?: ReactNode; | ||
| } | ||
|
|
||
| export const TerminalActionButton = ({ | ||
| icon: Icon, | ||
| label, | ||
| className = "p-1 text-foreground/90 transition-colors hover:bg-accent", | ||
| onClick, | ||
| onMouseDown, | ||
| children, | ||
| }: TerminalActionButtonProps) => ( | ||
| <Popover> | ||
| <PopoverTrigger | ||
| openOnHover | ||
| render={ | ||
| <button | ||
| type="button" | ||
| className={className} | ||
| onClick={onClick} | ||
| onMouseDown={onMouseDown} | ||
| aria-label={label} | ||
| /> | ||
| } | ||
| > | ||
| {Icon ? <Icon className="size-3.25" /> : children} | ||
| </PopoverTrigger> | ||
| <PopoverPopup | ||
| tooltipStyle | ||
| side="bottom" | ||
| sideOffset={6} | ||
| align="center" | ||
| className="pointer-events-none select-none" | ||
| > | ||
| {label} | ||
| </PopoverPopup> | ||
| </Popover> | ||
| ); | ||
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,150 @@ | ||
| import { ChevronDown, ChevronUp, Search, X } from "lucide-react"; | ||
| import { | ||
| type KeyboardEvent as ReactKeyboardEvent, | ||
| type MouseEvent as ReactMouseEvent, | ||
| useEffect, | ||
| useRef, | ||
| } from "react"; | ||
| import { SearchOptionButton } from "~/components/search/SearchOptionButton"; | ||
| import { TerminalActionButton } from "~/components/TerminalActionButton"; | ||
| import { cn } from "~/lib/utils"; | ||
|
|
||
| export interface TerminalSearchBarProps { | ||
| readonly open: boolean; | ||
| readonly docked: boolean; | ||
| readonly query: string; | ||
| readonly caseSensitive: boolean; | ||
| readonly matchCount: number; | ||
| readonly activeIndex: number; | ||
| readonly truncated: boolean; | ||
| readonly focusRequestId: number; | ||
| readonly isFindShortcut: (event: KeyboardEvent) => boolean; | ||
| readonly findShortcutLabel?: string; | ||
| readonly onOpen: () => void; | ||
| readonly onQueryChange: (query: string) => void; | ||
| readonly onCaseSensitiveChange: (value: boolean) => void; | ||
| readonly onNext: () => void; | ||
| readonly onPrevious: () => void; | ||
| readonly onClose: () => void; | ||
| } | ||
|
|
||
| export function TerminalSearchBar(props: TerminalSearchBarProps) { | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
| const lastFocusRequestIdRef = useRef<number | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!props.open || lastFocusRequestIdRef.current === props.focusRequestId) return; | ||
| lastFocusRequestIdRef.current = props.focusRequestId; | ||
| inputRef.current?.focus({ preventScroll: true }); | ||
| inputRef.current?.select(); | ||
| }, [props.focusRequestId, props.open]); | ||
|
|
||
| const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => { | ||
| const nativeEvent = event.nativeEvent; | ||
| if (nativeEvent.key === "Escape") { | ||
| props.onClose(); | ||
| } else if (props.isFindShortcut(nativeEvent)) { | ||
| inputRef.current?.focus({ preventScroll: true }); | ||
| inputRef.current?.select(); | ||
| } else if (nativeEvent.key === "Enter" && event.target === inputRef.current) { | ||
| (nativeEvent.shiftKey ? props.onPrevious : props.onNext)(); | ||
| } else { | ||
| return; | ||
| } | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| }; | ||
|
|
||
| const keepInputFocus = (event: ReactMouseEvent<HTMLButtonElement>) => event.preventDefault(); | ||
| const count = | ||
| props.query.length === 0 | ||
| ? "" | ||
| : props.matchCount === 0 | ||
| ? "0/0" | ||
| : `${props.activeIndex + 1}/${props.matchCount}${props.truncated ? "+" : ""}`; | ||
| const actionClassName = "p-1 text-foreground/90 transition-colors hover:bg-accent"; | ||
| const navigationClassName = cn( | ||
| actionClassName, | ||
| props.matchCount === 0 && "pointer-events-none opacity-45", | ||
| ); | ||
| const row = ( | ||
| <> | ||
| <span className="relative flex w-36 items-center"> | ||
| <input | ||
| ref={inputRef} | ||
| type="text" | ||
| value={props.query} | ||
| onChange={(event) => props.onQueryChange(event.target.value)} | ||
| className="h-5 w-full bg-transparent pr-11 pl-1.5 text-xs leading-5 text-foreground outline-none placeholder:text-muted-foreground" | ||
| placeholder="Find" | ||
| aria-label="Find in terminal" | ||
| /> | ||
| <span className="pointer-events-none absolute inset-y-0 right-1.5 flex items-center text-[10px] text-muted-foreground/70 italic tabular-nums"> | ||
| {count} | ||
| </span> | ||
| </span> | ||
| <div className="h-4 w-px bg-border/80" /> | ||
| <div className="flex" onMouseDown={(event) => event.preventDefault()}> | ||
| <SearchOptionButton | ||
| active={props.caseSensitive} | ||
| label="Match case" | ||
| className="size-auto h-5 w-6 rounded-none text-[11px] sm:size-auto sm:h-5 sm:w-6 sm:text-[11px] min-w-0" | ||
| onClick={() => props.onCaseSensitiveChange(!props.caseSensitive)} | ||
| > | ||
| Aa | ||
| </SearchOptionButton> | ||
| </div> | ||
| <div className="h-4 w-px bg-border/80" /> | ||
| <TerminalActionButton | ||
| icon={ChevronUp} | ||
| label="Previous match" | ||
| className={navigationClassName} | ||
| onClick={props.onPrevious} | ||
| onMouseDown={keepInputFocus} | ||
| /> | ||
| <TerminalActionButton | ||
| icon={ChevronDown} | ||
| label="Next match" | ||
| className={navigationClassName} | ||
| onClick={props.onNext} | ||
| onMouseDown={keepInputFocus} | ||
| /> | ||
| <TerminalActionButton | ||
| icon={X} | ||
| label="Close find" | ||
| className={actionClassName} | ||
| onClick={props.onClose} | ||
| onMouseDown={keepInputFocus} | ||
| /> | ||
| </> | ||
| ); | ||
|
|
||
| if (!props.docked) { | ||
| if (!props.open) return null; | ||
| return ( | ||
| <div | ||
| onKeyDown={handleKeyDown} | ||
| className="absolute right-2 top-2 z-20 inline-flex origin-right items-center overflow-hidden rounded-md border border-border/80 bg-background shadow-xs transition-[opacity,scale] duration-150 ease-out starting:scale-95 starting:opacity-0 motion-reduce:transition-none" | ||
| > | ||
| {row} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const label = `Find in terminal${props.findShortcutLabel ? ` (${props.findShortcutLabel})` : ""}`; | ||
| return ( | ||
| <> | ||
| {!props.open && <TerminalActionButton icon={Search} label={label} onClick={props.onOpen} />} | ||
| <div | ||
| inert={!props.open} | ||
| onKeyDown={handleKeyDown} | ||
| className={cn( | ||
| "overflow-hidden transition-[max-width] duration-200 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none", | ||
| props.open ? "max-w-80" : "max-w-0", | ||
| )} | ||
| > | ||
| <div className="flex w-max items-center">{row}</div> | ||
| </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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add native disabled-state support.
pointer-events-noneinTerminalSearchBarblocks only pointer input. A keyboard user can still focus and activate navigation whenmatchCountis zero. Assistive technology also reports the buttons as enabled.Add a
disabledprop. Forward it to the native button. Set it on both navigation buttons.Proposed fix
interface TerminalActionButtonProps { + readonly disabled?: boolean; readonly icon?: ComponentType<{ className?: string }>;export const TerminalActionButton = ({ + disabled, icon: Icon,<button type="button" + disabled={disabled}In
TerminalSearchBar.tsx:<TerminalActionButton + disabled={props.matchCount === 0} icon={ChevronUp}<TerminalActionButton + disabled={props.matchCount === 0} icon={ChevronDown}🤖 Prompt for AI Agents