Make keyboard shortcuts consistent (#20326)

* Make keyboard shortcuts consistent

* Cleanup

* Refactor prevent default to not require separate input

* Fix

* Implement escape for reviews

* Implement escape for explore

* Send content ref to get page changes for free
This commit is contained in:
Nicolas Mowen 2025-10-02 07:21:37 -06:00 committed by GitHub
parent 85ace6a6be
commit 2030809a6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 231 additions and 122 deletions

View File

@ -70,7 +70,10 @@ export default function ExportCard({
(editName.update?.length ?? 0) > 0 (editName.update?.length ?? 0) > 0
) { ) {
submitRename(); submitRename();
return true;
} }
return false;
}, },
); );

View File

@ -109,6 +109,7 @@ export default function ReviewCard({
useKeyboardListener(["Shift"], (_, modifiers) => { useKeyboardListener(["Shift"], (_, modifiers) => {
bypassDialogRef.current = modifiers.shift; bypassDialogRef.current = modifiers.shift;
return false;
}); });
const handleDelete = useCallback(() => { const handleDelete = useCallback(() => {

View File

@ -75,6 +75,7 @@ export default function ReviewActionGroup({
useKeyboardListener(["Shift"], (_, modifiers) => { useKeyboardListener(["Shift"], (_, modifiers) => {
setBypassDialog(modifiers.shift); setBypassDialog(modifiers.shift);
return false;
}); });
const handleDelete = useCallback(() => { const handleDelete = useCallback(() => {

View File

@ -62,6 +62,7 @@ export default function SearchActionGroup({
useKeyboardListener(["Shift"], (_, modifiers) => { useKeyboardListener(["Shift"], (_, modifiers) => {
setBypassDialog(modifiers.shift); setBypassDialog(modifiers.shift);
return false;
}); });
const handleDelete = useCallback(() => { const handleDelete = useCallback(() => {

View File

@ -83,7 +83,7 @@ export default function PtzControlPanel({
], ],
(key, modifiers) => { (key, modifiers) => {
if (modifiers.repeat || !key) { if (modifiers.repeat || !key) {
return; return true;
} }
if (["1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(key)) { if (["1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(key)) {
@ -95,34 +95,36 @@ export default function PtzControlPanel({
) { ) {
sendPtz(`preset_${ptz.presets[presetNumber - 1]}`); sendPtz(`preset_${ptz.presets[presetNumber - 1]}`);
} }
return; return true;
} }
if (!modifiers.down) { if (!modifiers.down) {
sendPtz("STOP"); sendPtz("STOP");
return; return true;
} }
switch (key) { switch (key) {
case "ArrowLeft": case "ArrowLeft":
sendPtz("MOVE_LEFT"); sendPtz("MOVE_LEFT");
break; return true;
case "ArrowRight": case "ArrowRight":
sendPtz("MOVE_RIGHT"); sendPtz("MOVE_RIGHT");
break; return true;
case "ArrowUp": case "ArrowUp":
sendPtz("MOVE_UP"); sendPtz("MOVE_UP");
break; return true;
case "ArrowDown": case "ArrowDown":
sendPtz("MOVE_DOWN"); sendPtz("MOVE_DOWN");
break; return true;
case "+": case "+":
sendPtz(modifiers.shift ? "FOCUS_IN" : "ZOOM_IN"); sendPtz(modifiers.shift ? "FOCUS_IN" : "ZOOM_IN");
break; return true;
case "-": case "-":
sendPtz(modifiers.shift ? "FOCUS_OUT" : "ZOOM_OUT"); sendPtz(modifiers.shift ? "FOCUS_OUT" : "ZOOM_OUT");
break; return true;
} }
return false;
}, },
); );

View File

@ -175,6 +175,8 @@ export default function ReviewDetailDialog({
if (key == "Esc" && modifiers.down && !modifiers.repeat) { if (key == "Esc" && modifiers.down && !modifiers.repeat) {
setIsOpen(false); setIsOpen(false);
} }
return true;
}); });
const Overlay = isDesktop ? Sheet : MobilePage; const Overlay = isDesktop ? Sheet : MobilePage;

View File

@ -60,7 +60,7 @@ export function GenericVideoPlayer({
["ArrowDown", "ArrowLeft", "ArrowRight", "ArrowUp", " ", "f", "m"], ["ArrowDown", "ArrowLeft", "ArrowRight", "ArrowUp", " ", "f", "m"],
(key, modifiers) => { (key, modifiers) => {
if (!modifiers.down || modifiers.repeat) { if (!modifiers.down || modifiers.repeat) {
return; return true;
} }
switch (key) { switch (key) {
@ -92,6 +92,8 @@ export function GenericVideoPlayer({
} }
break; break;
} }
return true;
}, },
); );

View File

@ -144,7 +144,7 @@ export default function VideoControls({
const onKeyboardShortcut = useCallback( const onKeyboardShortcut = useCallback(
(key: string | null, modifiers: KeyModifiers) => { (key: string | null, modifiers: KeyModifiers) => {
if (!modifiers.down) { if (!modifiers.down) {
return; return true;
} }
switch (key) { switch (key) {
@ -174,6 +174,8 @@ export default function VideoControls({
onPlayPause(!isPlaying); onPlayPause(!isPlaying);
break; break;
} }
return true;
}, },
// only update when preview only changes // only update when preview only changes
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect } from "react"; import { MutableRefObject, useCallback, useEffect, useMemo } from "react";
export type KeyModifiers = { export type KeyModifiers = {
down: boolean; down: boolean;
@ -9,9 +9,17 @@ export type KeyModifiers = {
export default function useKeyboardListener( export default function useKeyboardListener(
keys: string[], keys: string[],
listener: (key: string | null, modifiers: KeyModifiers) => void, listener?: (key: string | null, modifiers: KeyModifiers) => boolean,
preventDefault: boolean = true, contentRef?: MutableRefObject<HTMLDivElement | null>,
) { ) {
const pageKeys = useMemo(
() =>
contentRef != undefined
? ["ArrowDown", "ArrowUp", "PageDown", "PageUp"]
: [],
[contentRef],
);
const keyDownListener = useCallback( const keyDownListener = useCallback(
(e: KeyboardEvent) => { (e: KeyboardEvent) => {
// @ts-expect-error we know this field exists // @ts-expect-error we know this field exists
@ -26,14 +34,44 @@ export default function useKeyboardListener(
shift: e.shiftKey, shift: e.shiftKey,
}; };
if (keys.includes(e.key)) { if (contentRef && pageKeys.includes(e.key)) {
switch (e.key) {
case "ArrowDown":
contentRef.current?.scrollBy({
top: 100,
behavior: "smooth",
});
break;
case "ArrowUp":
contentRef.current?.scrollBy({
top: -100,
behavior: "smooth",
});
break;
case "PageDown":
contentRef.current?.scrollBy({
top: contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
case "PageUp":
contentRef.current?.scrollBy({
top: -contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
}
} else if (keys.includes(e.key) && listener) {
const preventDefault = listener(e.key, modifiers);
if (preventDefault) e.preventDefault(); if (preventDefault) e.preventDefault();
listener(e.key, modifiers); } else if (
} else if (e.key === "Shift" || e.key === "Control" || e.key === "Meta") { listener &&
(e.key === "Shift" || e.key === "Control" || e.key === "Meta")
) {
listener(null, modifiers); listener(null, modifiers);
} }
}, },
[keys, listener, preventDefault], [keys, pageKeys, listener, contentRef],
); );
const keyUpListener = useCallback( const keyUpListener = useCallback(
@ -49,10 +87,13 @@ export default function useKeyboardListener(
shift: false, shift: false,
}; };
if (keys.includes(e.key)) { if (listener && keys.includes(e.key)) {
e.preventDefault(); const preventDefault = listener(e.key, modifiers);
listener(e.key, modifiers); if (preventDefault) e.preventDefault();
} else if (e.key === "Shift" || e.key === "Control" || e.key === "Meta") { } else if (
listener &&
(e.key === "Shift" || e.key === "Control" || e.key === "Meta")
) {
listener(null, modifiers); listener(null, modifiers);
} }
}, },

View File

@ -13,12 +13,13 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog"; import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Toaster } from "@/components/ui/sonner"; import { Toaster } from "@/components/ui/sonner";
import useKeyboardListener from "@/hooks/use-keyboard-listener";
import { useSearchEffect } from "@/hooks/use-overlay-state"; import { useSearchEffect } from "@/hooks/use-overlay-state";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { DeleteClipType, Export } from "@/types/export"; import { DeleteClipType, Export } from "@/types/export";
import axios from "axios"; import axios from "axios";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { isMobile } from "react-device-detect"; import { isMobile } from "react-device-detect";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -109,6 +110,11 @@ function Exports() {
[mutate, t], [mutate, t],
); );
// Keyboard Listener
const contentRef = useRef<HTMLDivElement | null>(null);
useKeyboardListener([], undefined, contentRef);
return ( return (
<div className="flex size-full flex-col gap-2 overflow-hidden px-1 pt-2 md:p-2"> <div className="flex size-full flex-col gap-2 overflow-hidden px-1 pt-2 md:p-2">
<Toaster closeButton={true} /> <Toaster closeButton={true} />
@ -194,7 +200,10 @@ function Exports() {
<div className="w-full overflow-hidden"> <div className="w-full overflow-hidden">
{exports && filteredExports && filteredExports.length > 0 ? ( {exports && filteredExports && filteredExports.length > 0 ? (
<div className="scrollbar-container grid size-full gap-2 overflow-y-auto sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"> <div
ref={contentRef}
className="scrollbar-container grid size-full gap-2 overflow-y-auto sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
>
{Object.values(exports).map((item) => ( {Object.values(exports).map((item) => (
<ExportCard <ExportCard
key={item.name} key={item.name}

View File

@ -46,7 +46,14 @@ import { FaceLibraryData, RecognizedFaceData } from "@/types/face";
import { FaceRecognitionConfig, FrigateConfig } from "@/types/frigateConfig"; import { FaceRecognitionConfig, FrigateConfig } from "@/types/frigateConfig";
import { TooltipPortal } from "@radix-ui/react-tooltip"; import { TooltipPortal } from "@radix-ui/react-tooltip";
import axios from "axios"; import axios from "axios";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import {
MutableRefObject,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { isDesktop, isMobile } from "react-device-detect"; import { isDesktop, isMobile } from "react-device-detect";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { import {
@ -110,8 +117,6 @@ export default function FaceLibrary() {
const [addFace, setAddFace] = useState(false); const [addFace, setAddFace] = useState(false);
// input focus for keyboard shortcuts // input focus for keyboard shortcuts
const [inputFocused, setInputFocused] = useState(false);
const onUploadImage = useCallback( const onUploadImage = useCallback(
(file: File) => { (file: File) => {
const formData = new FormData(); const formData = new FormData();
@ -263,16 +268,17 @@ export default function FaceLibrary() {
// keyboard // keyboard
const contentRef = useRef<HTMLDivElement | null>(null);
useKeyboardListener( useKeyboardListener(
["a", "Escape"], ["a", "Escape"],
(key, modifiers) => { (key, modifiers) => {
if (modifiers.repeat || !modifiers.down) { if (!modifiers.down) {
return; return true;
} }
switch (key) { switch (key) {
case "a": case "a":
if (modifiers.ctrl) { if (modifiers.ctrl && !modifiers.repeat) {
if (selectedFaces.length) { if (selectedFaces.length) {
setSelectedFaces([]); setSelectedFaces([]);
} else { } else {
@ -280,14 +286,18 @@ export default function FaceLibrary() {
...(pageToggle === "train" ? trainImages : faceImages), ...(pageToggle === "train" ? trainImages : faceImages),
]); ]);
} }
return true;
} }
break; break;
case "Escape": case "Escape":
setSelectedFaces([]); setSelectedFaces([]);
break; return true;
} }
return false;
}, },
!inputFocused, contentRef,
); );
useEffect(() => { useEffect(() => {
@ -408,15 +418,16 @@ export default function FaceLibrary() {
(pageToggle == "train" ? ( (pageToggle == "train" ? (
<TrainingGrid <TrainingGrid
config={config} config={config}
contentRef={contentRef}
attemptImages={trainImages} attemptImages={trainImages}
faceNames={faces} faceNames={faces}
selectedFaces={selectedFaces} selectedFaces={selectedFaces}
onClickFaces={onClickFaces} onClickFaces={onClickFaces}
onRefresh={refreshFaces} onRefresh={refreshFaces}
setInputFocused={setInputFocused}
/> />
) : ( ) : (
<FaceGrid <FaceGrid
contentRef={contentRef}
faceImages={faceImages} faceImages={faceImages}
pageToggle={pageToggle} pageToggle={pageToggle}
selectedFaces={selectedFaces} selectedFaces={selectedFaces}
@ -609,21 +620,21 @@ function LibrarySelector({
type TrainingGridProps = { type TrainingGridProps = {
config: FrigateConfig; config: FrigateConfig;
contentRef: MutableRefObject<HTMLDivElement | null>;
attemptImages: string[]; attemptImages: string[];
faceNames: string[]; faceNames: string[];
selectedFaces: string[]; selectedFaces: string[];
onClickFaces: (images: string[], ctrl: boolean) => void; onClickFaces: (images: string[], ctrl: boolean) => void;
onRefresh: () => void; onRefresh: () => void;
setInputFocused: React.Dispatch<React.SetStateAction<boolean>>;
}; };
function TrainingGrid({ function TrainingGrid({
config, config,
contentRef,
attemptImages, attemptImages,
faceNames, faceNames,
selectedFaces, selectedFaces,
onClickFaces, onClickFaces,
onRefresh, onRefresh,
setInputFocused,
}: TrainingGridProps) { }: TrainingGridProps) {
const { t } = useTranslation(["views/faceLibrary"]); const { t } = useTranslation(["views/faceLibrary"]);
@ -698,10 +709,13 @@ function TrainingGrid({
setSimilarity={undefined} setSimilarity={undefined}
setSearchPage={setDialogTab} setSearchPage={setDialogTab}
setSearch={(search) => setSelectedEvent(search as unknown as Event)} setSearch={(search) => setSelectedEvent(search as unknown as Event)}
setInputFocused={setInputFocused} setInputFocused={() => {}}
/> />
<div className="scrollbar-container flex flex-wrap gap-2 overflow-y-scroll p-1"> <div
ref={contentRef}
className="scrollbar-container flex flex-wrap gap-2 overflow-y-scroll p-1"
>
{Object.entries(faceGroups).map(([key, group]) => { {Object.entries(faceGroups).map(([key, group]) => {
const event = events?.find((ev) => ev.id == key); const event = events?.find((ev) => ev.id == key);
return ( return (
@ -1039,6 +1053,7 @@ function FaceAttempt({
} }
type FaceGridProps = { type FaceGridProps = {
contentRef: MutableRefObject<HTMLDivElement | null>;
faceImages: string[]; faceImages: string[];
pageToggle: string; pageToggle: string;
selectedFaces: string[]; selectedFaces: string[];
@ -1046,6 +1061,7 @@ type FaceGridProps = {
onDelete: (name: string, ids: string[]) => void; onDelete: (name: string, ids: string[]) => void;
}; };
function FaceGrid({ function FaceGrid({
contentRef,
faceImages, faceImages,
pageToggle, pageToggle,
selectedFaces, selectedFaces,
@ -1070,6 +1086,7 @@ function FaceGrid({
return ( return (
<div <div
ref={contentRef}
className={cn( className={cn(
"scrollbar-container gap-2 overflow-y-scroll p-1", "scrollbar-container gap-2 overflow-y-scroll p-1",
isDesktop ? "flex flex-wrap" : "grid grid-cols-2 md:grid-cols-4", isDesktop ? "flex flex-wrap" : "grid grid-cols-2 md:grid-cols-4",

View File

@ -56,14 +56,16 @@ function Live() {
useKeyboardListener(["f"], (key, modifiers) => { useKeyboardListener(["f"], (key, modifiers) => {
if (!modifiers.down) { if (!modifiers.down) {
return; return true;
} }
switch (key) { switch (key) {
case "f": case "f":
toggleFullscreen(); toggleFullscreen();
break; return true;
} }
return false;
}); });
// document title // document title

View File

@ -337,7 +337,7 @@ function Logs() {
["PageDown", "PageUp", "ArrowDown", "ArrowUp"], ["PageDown", "PageUp", "ArrowDown", "ArrowUp"],
(key, modifiers) => { (key, modifiers) => {
if (!key || !modifiers.down || !lazyLogWrapperRef.current) { if (!key || !modifiers.down || !lazyLogWrapperRef.current) {
return; return true;
} }
const container = const container =
@ -346,7 +346,7 @@ function Logs() {
const logLineHeight = container?.querySelector(".log-line")?.clientHeight; const logLineHeight = container?.querySelector(".log-line")?.clientHeight;
if (!logLineHeight) { if (!logLineHeight) {
return; return true;
} }
const scrollAmount = key.includes("Page") const scrollAmount = key.includes("Page")
@ -354,6 +354,7 @@ function Logs() {
: logLineHeight; : logLineHeight;
const direction = key.includes("Down") ? 1 : -1; const direction = key.includes("Down") ? 1 : -1;
container?.scrollBy({ top: scrollAmount * direction }); container?.scrollBy({ top: scrollAmount * direction });
return true;
}, },
); );

View File

@ -37,7 +37,14 @@ import { cn } from "@/lib/utils";
import { CustomClassificationModelConfig } from "@/types/frigateConfig"; import { CustomClassificationModelConfig } from "@/types/frigateConfig";
import { TooltipPortal } from "@radix-ui/react-tooltip"; import { TooltipPortal } from "@radix-ui/react-tooltip";
import axios from "axios"; import axios from "axios";
import { useCallback, useEffect, useMemo, useState } from "react"; import {
MutableRefObject,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { isDesktop, isMobile } from "react-device-detect"; import { isDesktop, isMobile } from "react-device-detect";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { LuPencil, LuTrash2 } from "react-icons/lu"; import { LuPencil, LuTrash2 } from "react-icons/lu";
@ -226,30 +233,38 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
// keyboard // keyboard
useKeyboardListener(["a", "Escape"], (key, modifiers) => { const contentRef = useRef<HTMLDivElement | null>(null);
if (modifiers.repeat || !modifiers.down) { useKeyboardListener(
return; ["a", "Escape"],
} (key, modifiers) => {
if (!modifiers.down) {
return true;
}
switch (key) { switch (key) {
case "a": case "a":
if (modifiers.ctrl) { if (modifiers.ctrl && !modifiers.repeat) {
if (selectedImages.length) { if (selectedImages.length) {
setSelectedImages([]); setSelectedImages([]);
} else { } else {
setSelectedImages([ setSelectedImages([
...(pageToggle === "train" ...(pageToggle === "train"
? trainImages || [] ? trainImages || []
: dataset?.[pageToggle] || []), : dataset?.[pageToggle] || []),
]); ]);
}
return true;
} }
} break;
break; case "Escape":
case "Escape": setSelectedImages([]);
setSelectedImages([]); return true;
break; }
}
}); return false;
},
contentRef,
);
useEffect(() => { useEffect(() => {
setSelectedImages([]); setSelectedImages([]);
@ -370,6 +385,7 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
{pageToggle == "train" ? ( {pageToggle == "train" ? (
<TrainGrid <TrainGrid
model={model} model={model}
contentRef={contentRef}
classes={Object.keys(dataset || {})} classes={Object.keys(dataset || {})}
trainImages={trainImages || []} trainImages={trainImages || []}
trainFilter={trainFilter} trainFilter={trainFilter}
@ -380,6 +396,7 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
/> />
) : ( ) : (
<DatasetGrid <DatasetGrid
contentRef={contentRef}
modelName={model.name} modelName={model.name}
categoryName={pageToggle} categoryName={pageToggle}
images={dataset?.[pageToggle] || []} images={dataset?.[pageToggle] || []}
@ -579,6 +596,7 @@ function LibrarySelector({
} }
type DatasetGridProps = { type DatasetGridProps = {
contentRef: MutableRefObject<HTMLDivElement | null>;
modelName: string; modelName: string;
categoryName: string; categoryName: string;
images: string[]; images: string[];
@ -587,6 +605,7 @@ type DatasetGridProps = {
onDelete: (ids: string[]) => void; onDelete: (ids: string[]) => void;
}; };
function DatasetGrid({ function DatasetGrid({
contentRef,
modelName, modelName,
categoryName, categoryName,
images, images,
@ -602,7 +621,10 @@ function DatasetGrid({
); );
return ( return (
<div className="flex flex-wrap gap-2 overflow-y-auto p-2"> <div
ref={contentRef}
className="scrollbar-container flex flex-wrap gap-2 overflow-y-auto p-2"
>
{classData.map((image) => ( {classData.map((image) => (
<div <div
className={cn( className={cn(
@ -658,6 +680,7 @@ function DatasetGrid({
type TrainGridProps = { type TrainGridProps = {
model: CustomClassificationModelConfig; model: CustomClassificationModelConfig;
contentRef: MutableRefObject<HTMLDivElement | null>;
classes: string[]; classes: string[];
trainImages: string[]; trainImages: string[];
trainFilter?: TrainFilter; trainFilter?: TrainFilter;
@ -668,6 +691,7 @@ type TrainGridProps = {
}; };
function TrainGrid({ function TrainGrid({
model, model,
contentRef,
classes, classes,
trainImages, trainImages,
trainFilter, trainFilter,
@ -726,8 +750,9 @@ function TrainGrid({
return ( return (
<div <div
ref={contentRef}
className={cn( className={cn(
"flex flex-wrap gap-2 overflow-y-auto p-2", "scrollbar-container flex flex-wrap gap-2 overflow-y-auto p-2",
isMobile && "justify-center", isMobile && "justify-center",
)} )}
> >

View File

@ -650,42 +650,41 @@ function DetectionReview({
// keyboard // keyboard
useKeyboardListener(["a", "r", "PageDown", "PageUp"], (key, modifiers) => { useKeyboardListener(
if (modifiers.repeat || !modifiers.down) { ["a", "r", "Escape"],
return; (key, modifiers) => {
} if (!modifiers.down) {
return true;
}
switch (key) { switch (key) {
case "a": case "a":
if (modifiers.ctrl) { if (modifiers.ctrl && !modifiers.repeat) {
onSelectAllReviews(); onSelectAllReviews();
} return true;
break; }
case "r": break;
if (selectedReviews.length > 0) { case "r":
currentItems?.forEach((item) => { if (selectedReviews.length > 0 && !modifiers.repeat) {
if (selectedReviews.includes(item.id)) { currentItems?.forEach((item) => {
item.has_been_reviewed = true; if (selectedReviews.includes(item.id)) {
markItemAsReviewed(item); item.has_been_reviewed = true;
} markItemAsReviewed(item);
}); }
});
setSelectedReviews([]);
return true;
}
break;
case "Escape":
setSelectedReviews([]); setSelectedReviews([]);
} return true;
break; }
case "PageDown":
contentRef.current?.scrollBy({ return false;
top: contentRef.current.clientHeight / 2, },
behavior: "smooth", contentRef,
}); );
break;
case "PageUp":
contentRef.current?.scrollBy({
top: -contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
}
});
return ( return (
<> <>

View File

@ -309,21 +309,25 @@ export default function LiveCameraView({
useKeyboardListener(["m"], (key, modifiers) => { useKeyboardListener(["m"], (key, modifiers) => {
if (!modifiers.down) { if (!modifiers.down) {
return; return true;
} }
switch (key) { switch (key) {
case "m": case "m":
if (supportsAudioOutput) { if (supportsAudioOutput) {
setAudio(!audio); setAudio(!audio);
return true;
} }
break; break;
case "t": case "t":
if (supports2WayTalk) { if (supports2WayTalk) {
setMic(!mic); setMic(!mic);
return true;
} }
break; break;
} }
return false;
}); });
// layout state // layout state

View File

@ -308,16 +308,24 @@ export default function SearchView({
const onKeyboardShortcut = useCallback( const onKeyboardShortcut = useCallback(
(key: string | null, modifiers: KeyModifiers) => { (key: string | null, modifiers: KeyModifiers) => {
if (!modifiers.down || !uniqueResults || inputFocused) { if (inputFocused) {
return; return false;
}
if (!modifiers.down || !uniqueResults) {
return true;
} }
switch (key) { switch (key) {
case "a": case "a":
if (modifiers.ctrl) { if (modifiers.ctrl && !modifiers.repeat) {
onSelectAllObjects(); onSelectAllObjects();
return true;
} }
break; break;
case "Escape":
setSelectedObjects([]);
return true;
case "ArrowLeft": case "ArrowLeft":
if (uniqueResults.length > 0) { if (uniqueResults.length > 0) {
const currentIndex = searchDetail const currentIndex = searchDetail
@ -334,8 +342,7 @@ export default function SearchView({
setSearchDetail(uniqueResults[newIndex]); setSearchDetail(uniqueResults[newIndex]);
} }
break; return true;
case "ArrowRight": case "ArrowRight":
if (uniqueResults.length > 0) { if (uniqueResults.length > 0) {
const currentIndex = searchDetail const currentIndex = searchDetail
@ -351,28 +358,18 @@ export default function SearchView({
setSearchDetail(uniqueResults[newIndex]); setSearchDetail(uniqueResults[newIndex]);
} }
break; return true;
case "PageDown":
contentRef.current?.scrollBy({
top: contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
case "PageUp":
contentRef.current?.scrollBy({
top: -contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
} }
return false;
}, },
[uniqueResults, inputFocused, onSelectAllObjects, searchDetail], [uniqueResults, inputFocused, onSelectAllObjects, searchDetail],
); );
useKeyboardListener( useKeyboardListener(
["a", "ArrowLeft", "ArrowRight", "PageDown", "PageUp"], ["a", "Escape", "ArrowLeft", "ArrowRight"],
onKeyboardShortcut, onKeyboardShortcut,
!inputFocused, contentRef,
); );
// scroll into view // scroll into view

View File

@ -4,7 +4,7 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc"; import react from "@vitejs/plugin-react-swc";
import monacoEditorPlugin from "vite-plugin-monaco-editor"; import monacoEditorPlugin from "vite-plugin-monaco-editor";
const proxyHost = process.env.PROXY_HOST || "localhost:5000"; const proxyHost = process.env.PROXY_HOST || "192.168.50.106:5002";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({