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
18 changed files with 231 additions and 122 deletions
+17 -20
View File
@@ -308,16 +308,24 @@ export default function SearchView({
const onKeyboardShortcut = useCallback(
(key: string | null, modifiers: KeyModifiers) => {
if (!modifiers.down || !uniqueResults || inputFocused) {
return;
if (inputFocused) {
return false;
}
if (!modifiers.down || !uniqueResults) {
return true;
}
switch (key) {
case "a":
if (modifiers.ctrl) {
if (modifiers.ctrl && !modifiers.repeat) {
onSelectAllObjects();
return true;
}
break;
case "Escape":
setSelectedObjects([]);
return true;
case "ArrowLeft":
if (uniqueResults.length > 0) {
const currentIndex = searchDetail
@@ -334,8 +342,7 @@ export default function SearchView({
setSearchDetail(uniqueResults[newIndex]);
}
break;
return true;
case "ArrowRight":
if (uniqueResults.length > 0) {
const currentIndex = searchDetail
@@ -351,28 +358,18 @@ export default function SearchView({
setSearchDetail(uniqueResults[newIndex]);
}
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;
return true;
}
return false;
},
[uniqueResults, inputFocused, onSelectAllObjects, searchDetail],
);
useKeyboardListener(
["a", "ArrowLeft", "ArrowRight", "PageDown", "PageUp"],
["a", "Escape", "ArrowLeft", "ArrowRight"],
onKeyboardShortcut,
!inputFocused,
contentRef,
);
// scroll into view