Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/desktop/src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function App(): JSX.Element {
const setUpdateInfo = useAppStore((s) => s.setUpdateInfo);
const saveOrPrompt = useAppStore((s) => s.saveOrPrompt);
const focusUrl = useAppStore((s) => s.focusUrl);
const focusSearch = useAppStore((s) => s.focusSearch);
const toggleHiddenRequest = useAppStore((s) => s.toggleHiddenRequest);
const tabs = useAppStore((s) => s.tabs);
const isRepo = useAppStore((s) => s.gitStatus?.isRepo === true);
Expand Down Expand Up @@ -88,6 +89,17 @@ export function App(): JSX.Element {
handler: () => activeTabId && duplicateTab(activeTabId),
},
{ combo: 'mod+l', description: 'Focus URL bar', handler: () => focusUrl() },
{
combo: 'mod+f',
description: 'Find in response',
handler: () => {
const state = useAppStore.getState();
const tab = state.tabs.find((t) => t.id === state.activeTabId);
if (tab?.execution.status === 'success') {
focusSearch();
}
},
},
{
combo: 'mod+enter',
description: 'Send / cancel request',
Expand Down Expand Up @@ -137,6 +149,7 @@ export function App(): JSX.Element {
activeTabId,
saveOrPrompt,
focusUrl,
focusSearch,
toggleHiddenRequest,
tabs,
isRepo,
Expand Down
18 changes: 18 additions & 0 deletions apps/desktop/src/renderer/src/components/ResponseViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export function ResponseViewer(): JSX.Element {
});
const [tab, setTab] = useState<Tab>('body');

const focusSearchTick = useAppStore((s) => s.focusSearchTick);
useEffect(() => {
if (focusSearchTick === 0) return;
setTab('body');
}, [focusSearchTick]);

if (!execution) {
return (
<EmptyState icon="↵" title="No tab" description="Open or create a request first." />
Expand Down Expand Up @@ -255,8 +261,16 @@ function BodyPanel({ response }: { response: ExecutedResponse }): JSX.Element {
}, [matches.length]);

const searchable_supported = mode === 'raw' || mode === 'pretty';
const searchInputRef = useRef<HTMLInputElement | null>(null);
const activeMatchRef = useRef<HTMLElement | null>(null);

const focusSearchTick = useAppStore((s) => s.focusSearchTick);
useEffect(() => {
if (focusSearchTick === 0) return;
searchInputRef.current?.focus();
searchInputRef.current?.select();
}, [focusSearchTick]);

useEffect(() => {
if (activeMatchRef.current) {
activeMatchRef.current.scrollIntoView({
Expand All @@ -280,6 +294,7 @@ function BodyPanel({ response }: { response: ExecutedResponse }): JSX.Element {

{searchable_supported && (
<SearchBox
inputRef={searchInputRef}
value={search}
onChange={setSearch}
matchCount={matches.length}
Expand Down Expand Up @@ -326,13 +341,15 @@ function BodyPanel({ response }: { response: ExecutedResponse }): JSX.Element {
}

function SearchBox({
inputRef,
value,
onChange,
matchCount,
activeIndex,
onPrev,
onNext,
}: {
inputRef?: React.Ref<HTMLInputElement>;
value: string;
onChange: (value: string) => void;
matchCount: number;
Expand All @@ -343,6 +360,7 @@ function SearchBox({
return (
<div className="ml-3 flex items-center gap-1 rounded-md border border-line bg-bg-canvas pl-2 pr-1 focus-within:border-accent focus-within:shadow-focus">
<input
ref={inputRef}
type="text"
value={value}
placeholder="Find in body"
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/src/renderer/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ interface AppState {
focusUrlTick: number;
focusUrl: () => void;

// Bumped by ⌘F; ResponseViewer watches and focuses+selects the search input.
focusSearchTick: number;
focusSearch: () => void;

// Ticks bumped by the command palette to open dialogs owned by RequestBuilder.
importCurlTick: number;
openImportCurl: () => void;
Expand Down Expand Up @@ -537,6 +541,7 @@ export const useAppStore = create<AppState>((set, get) => {
setSidebarView: (view) => set({ sidebarView: view }),
saveDialogOpen: false,
focusUrlTick: 0,
focusSearchTick: 0,
importCurlTick: 0,
loadTestTick: 0,
revealInSidebarTick: 0,
Expand Down Expand Up @@ -582,6 +587,7 @@ export const useAppStore = create<AppState>((set, get) => {
},

focusUrl: () => set({ focusUrlTick: get().focusUrlTick + 1 }),
focusSearch: () => set({ focusSearchTick: get().focusSearchTick + 1 }),
openImportCurl: () => set({ importCurlTick: get().importCurlTick + 1 }),
openLoadTest: () => set({ loadTestTick: get().loadTestTick + 1 }),

Expand Down
Loading