From fa460d697c926a4ff7a8747a82983fb66642022a Mon Sep 17 00:00:00 2001 From: Philip Peterson <1326208+philip-peterson@users.noreply.github.com> Date: Sat, 7 Jun 2025 21:15:54 -0700 Subject: [PATCH] Search command should re-focus search box if already open (#164) --- lib/actions/sessions.ts | 4 ++-- lib/components/searchBox.tsx | 9 +++++++++ lib/components/term.tsx | 1 + lib/reducers/sessions.ts | 2 +- typings/constants/sessions.d.ts | 2 +- typings/hyper.d.ts | 7 ++++--- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/actions/sessions.ts b/lib/actions/sessions.ts index 4cb53f9d..d36563ff 100644 --- a/lib/actions/sessions.ts +++ b/lib/actions/sessions.ts @@ -141,7 +141,7 @@ export function openSearch(uid?: string) { dispatch({ type: SESSION_SEARCH, uid: targetUid, - value: true + value: new Date() }); }; } @@ -153,7 +153,7 @@ export function closeSearch(uid?: string, keyEvent?: any) { dispatch({ type: SESSION_SEARCH, uid: targetUid, - value: false + value: null }); } else { if (keyEvent) { diff --git a/lib/components/searchBox.tsx b/lib/components/searchBox.tsx index 55a72f16..a8d2f50e 100644 --- a/lib/components/searchBox.tsx +++ b/lib/components/searchBox.tsx @@ -87,6 +87,7 @@ const SearchButton = ({ const SearchBox = forwardRef((props, ref) => { const { caseSensitive, + dateFocused, wholeWord, regex, results, @@ -122,6 +123,14 @@ const SearchBox = forwardRef((props, ref) => { inputRef.current?.focus(); }, [inputRef.current]); + useEffect(() => { + if (!dateFocused) { + return; + } + inputRef.current?.focus(); + inputRef.current?.select(); + }, [dateFocused]); + const searchButtonColors: SearchButtonColors = { backgroundColor: borderColor, selectionColor, diff --git a/lib/components/term.tsx b/lib/components/term.tsx index 923f398c..b59fe80c 100644 --- a/lib/components/term.tsx +++ b/lib/components/term.tsx @@ -518,6 +518,7 @@ export default class Term extends React.PureComponent< {this.props.customChildren} {this.props.search ? ( ) { cols: null, rows: null, cleared: false, - search: false, + search: null, shell: '', pid: null, profile: '' diff --git a/typings/constants/sessions.d.ts b/typings/constants/sessions.d.ts index db52a757..10d64303 100644 --- a/typings/constants/sessions.d.ts +++ b/typings/constants/sessions.d.ts @@ -74,7 +74,7 @@ export interface SessionSetCwdAction { export interface SessionSearchAction { type: typeof SESSION_SEARCH; uid: string; - value: boolean; + value: Date | null; } export type SessionActions = diff --git a/typings/hyper.d.ts b/typings/hyper.d.ts index 55f7b484..dc2d442b 100644 --- a/typings/hyper.d.ts +++ b/typings/hyper.d.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair /* eslint-disable import/order */ -import type {Immutable} from 'seamless-immutable'; +import type {Immutable, ImmutableDate} from 'seamless-immutable'; import type Client from '../lib/utils/rpc'; declare global { @@ -118,7 +118,7 @@ export type session = { pid: number | null; resizeAt?: number; rows: number | null; - search: boolean; + search: ImmutableDate | null; shell: string | null; title: string; uid: string; @@ -326,6 +326,7 @@ import type {TermGroupConnectedProps} from '../lib/components/term-group'; export type TermGroupProps = TermGroupConnectedProps & TermGroupOwnProps; export type SearchBoxProps = { + dateFocused: ImmutableDate | null; caseSensitive: boolean; wholeWord: boolean; regex: boolean; @@ -386,7 +387,7 @@ export type TermProps = { rows: number | null; screenReaderMode: boolean; scrollback: number; - search: boolean; + search: ImmutableDate | null; searchAddon: SearchAddon | null; selectionColor: string; term: Terminal | null;