mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-24 22:01:33 +01:00
add addl buttons
This commit is contained in:
parent
27f8a3c4f1
commit
4533c813ce
@ -16,6 +16,7 @@ type SearchProps = SearchAtoms & {
|
|||||||
onSearch?: (search: string) => void;
|
onSearch?: (search: string) => void;
|
||||||
onNext?: () => void;
|
onNext?: () => void;
|
||||||
onPrev?: () => void;
|
onPrev?: () => void;
|
||||||
|
additionalButtons?: IconButtonDecl[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const SearchComponent = ({
|
const SearchComponent = ({
|
||||||
@ -29,6 +30,7 @@ const SearchComponent = ({
|
|||||||
onSearch,
|
onSearch,
|
||||||
onNext,
|
onNext,
|
||||||
onPrev,
|
onPrev,
|
||||||
|
additionalButtons,
|
||||||
}: SearchProps) => {
|
}: SearchProps) => {
|
||||||
const [isOpen, setIsOpen] = useAtom<boolean>(isOpenAtom);
|
const [isOpen, setIsOpen] = useAtom<boolean>(isOpenAtom);
|
||||||
const [search, setSearch] = useAtom<string>(searchAtom);
|
const [search, setSearch] = useAtom<string>(searchAtom);
|
||||||
@ -74,7 +76,7 @@ const SearchComponent = ({
|
|||||||
);
|
);
|
||||||
middleware.push(offset(offsetCallback));
|
middleware.push(offset(offsetCallback));
|
||||||
|
|
||||||
const { refs, floatingStyles, context } = useFloating({
|
const { refs, floatingStyles } = useFloating({
|
||||||
placement: "top-end",
|
placement: "top-end",
|
||||||
open: isOpen,
|
open: isOpen,
|
||||||
onOpenChange: handleOpenChange,
|
onOpenChange: handleOpenChange,
|
||||||
@ -148,6 +150,13 @@ const SearchComponent = ({
|
|||||||
>
|
>
|
||||||
{index + 1}/{numResults}
|
{index + 1}/{numResults}
|
||||||
</div>
|
</div>
|
||||||
|
{additionalButtons?.length && (
|
||||||
|
<div className="right-buttons">
|
||||||
|
{additionalButtons.map((decl, i) => (
|
||||||
|
<IconButton key={i} decl={decl} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="right-buttons">
|
<div className="right-buttons">
|
||||||
<IconButton decl={prevDecl} />
|
<IconButton decl={prevDecl} />
|
||||||
<IconButton decl={nextDecl} />
|
<IconButton decl={nextDecl} />
|
||||||
|
@ -792,10 +792,53 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
const fullConfig = globalStore.get(atoms.fullConfigAtom);
|
const fullConfig = globalStore.get(atoms.fullConfigAtom);
|
||||||
const connFontFamily = fullConfig.connections?.[blockData?.meta?.connection]?.["term:fontfamily"];
|
const connFontFamily = fullConfig.connections?.[blockData?.meta?.connection]?.["term:fontfamily"];
|
||||||
|
|
||||||
|
// search
|
||||||
const searchProps = useSearch(viewRef, model);
|
const searchProps = useSearch(viewRef, model);
|
||||||
|
const { additionalButtons, stateAtoms } = React.useMemo(() => {
|
||||||
|
const regexAtom = jotai.atom(false);
|
||||||
|
const wholeWordAtom = jotai.atom(false);
|
||||||
|
const caseSensitiveAtom = jotai.atom(false);
|
||||||
|
const additionalButtons: IconButtonDecl[] = [
|
||||||
|
{
|
||||||
|
elemtype: "iconbutton",
|
||||||
|
icon: "font-case",
|
||||||
|
title: "Case Sensitive",
|
||||||
|
click: () => {
|
||||||
|
globalStore.set(caseSensitiveAtom, !globalStore.get(caseSensitiveAtom));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
elemtype: "iconbutton",
|
||||||
|
icon: "w",
|
||||||
|
title: "Whole Word",
|
||||||
|
click: () => {
|
||||||
|
globalStore.set(wholeWordAtom, !globalStore.get(wholeWordAtom));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
elemtype: "iconbutton",
|
||||||
|
icon: "asterisk",
|
||||||
|
title: "Regex Search",
|
||||||
|
click: () => {
|
||||||
|
globalStore.set(regexAtom, !globalStore.get(regexAtom));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
additionalButtons,
|
||||||
|
stateAtoms: { caseSensitiveAtom, wholeWordAtom, regexAtom },
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
searchProps.additionalButtons = additionalButtons;
|
||||||
|
const caseSensitive = jotai.useAtomValue<boolean>(stateAtoms.caseSensitiveAtom);
|
||||||
|
const wholeWord = jotai.useAtomValue<boolean>(stateAtoms.wholeWordAtom);
|
||||||
|
const regex = jotai.useAtomValue<boolean>(stateAtoms.regexAtom);
|
||||||
const searchVal = jotai.useAtomValue<string>(searchProps.searchAtom);
|
const searchVal = jotai.useAtomValue<string>(searchProps.searchAtom);
|
||||||
const searchOpts: ISearchOptions = {
|
const searchOpts: ISearchOptions = {
|
||||||
incremental: true,
|
incremental: true,
|
||||||
|
regex,
|
||||||
|
wholeWord,
|
||||||
|
caseSensitive,
|
||||||
decorations: {
|
decorations: {
|
||||||
matchOverviewRuler: "#e0e0e0",
|
matchOverviewRuler: "#e0e0e0",
|
||||||
activeMatchColorOverviewRuler: "#e0e0e0",
|
activeMatchColorOverviewRuler: "#e0e0e0",
|
||||||
@ -816,6 +859,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
|
|||||||
searchProps.onNext = React.useCallback(() => {
|
searchProps.onNext = React.useCallback(() => {
|
||||||
model.termRef.current?.searchAddon.findNext(searchVal, searchOpts);
|
model.termRef.current?.searchAddon.findNext(searchVal, searchOpts);
|
||||||
}, [searchVal]);
|
}, [searchVal]);
|
||||||
|
// end search
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const fullConfig = globalStore.get(atoms.fullConfigAtom);
|
const fullConfig = globalStore.get(atoms.fullConfigAtom);
|
||||||
|
Loading…
Reference in New Issue
Block a user