Search command should re-focus search box if already open (#164)
Some checks failed
CodeQL / Analyze (push) Has been cancelled

This commit is contained in:
Philip Peterson 2025-06-07 21:15:54 -07:00 committed by GitHub
parent d65dfba445
commit fa460d697c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 7 deletions

View file

@ -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) {

View file

@ -87,6 +87,7 @@ const SearchButton = ({
const SearchBox = forwardRef<HTMLDivElement, SearchBoxProps>((props, ref) => {
const {
caseSensitive,
dateFocused,
wholeWord,
regex,
results,
@ -122,6 +123,14 @@ const SearchBox = forwardRef<HTMLDivElement, SearchBoxProps>((props, ref) => {
inputRef.current?.focus();
}, [inputRef.current]);
useEffect(() => {
if (!dateFocused) {
return;
}
inputRef.current?.focus();
inputRef.current?.select();
}, [dateFocused]);
const searchButtonColors: SearchButtonColors = {
backgroundColor: borderColor,
selectionColor,

View file

@ -518,6 +518,7 @@ export default class Term extends React.PureComponent<
{this.props.customChildren}
{this.props.search ? (
<SearchBox
dateFocused={this.props.search}
next={this.searchNext}
prev={this.searchPrevious}
close={this.closeSearchBox}

View file

@ -27,7 +27,7 @@ function Session(obj: Immutable.DeepPartial<session>) {
cols: null,
rows: null,
cleared: false,
search: false,
search: null,
shell: '',
pid: null,
profile: ''

View file

@ -74,7 +74,7 @@ export interface SessionSetCwdAction {
export interface SessionSearchAction {
type: typeof SESSION_SEARCH;
uid: string;
value: boolean;
value: Date | null;
}
export type SessionActions =

7
typings/hyper.d.ts vendored
View file

@ -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;