From 610cd2189795fd290cf38633fd79eb18ec0e0ece Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Sat, 7 Jun 2025 20:44:19 -0700 Subject: [PATCH] Search command should re-focus search box if already open --- lib/actions/sessions.ts | 4 ++-- lib/components/searchBox.tsx | 9 +++++++++ lib/components/term-group.tsx | 2 +- lib/components/term.tsx | 1 + lib/reducers/sessions.ts | 2 +- typings/constants/sessions.d.ts | 2 +- typings/hyper.d.ts | 5 +++-- 7 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-group.tsx b/lib/components/term-group.tsx index 5e6e66ec..441d1c0b 100644 --- a/lib/components/term-group.tsx +++ b/lib/components/term-group.tsx @@ -86,7 +86,7 @@ class TermGroup_ extends React.PureComponent { modifierKeys: this.props.modifierKeys, padding: this.props.padding, cleared: session.cleared, - search: session.search, + search: session.search?.asMutable() ?? null, cols: session.cols, rows: session.rows, copyOnSelect: this.props.copyOnSelect, 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..a35e9dfa 100644 --- a/typings/hyper.d.ts +++ b/typings/hyper.d.ts @@ -118,7 +118,7 @@ export type session = { pid: number | null; resizeAt?: number; rows: number | null; - search: boolean; + search: Date | 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: Date | null; caseSensitive: boolean; wholeWord: boolean; regex: boolean; @@ -386,7 +387,7 @@ export type TermProps = { rows: number | null; screenReaderMode: boolean; scrollback: number; - search: boolean; + search: Date | null; searchAddon: SearchAddon | null; selectionColor: string; term: Terminal | null;