mirror of
https://github.com/block/buzz.git
synced 2026-11-03 07:51:22 +00:00
## What changed - unify Cmd+K and channel Cmd+F around a removable channel or conversation scope - add conservative fuzzy matching for people and channels while preserving exact-match ordering - make scoped message search complete for one-character queries and expose up to 40 scrollable results - keep the pre-scope channel or DM action in the normal results flow so it scrolls away with the list ## Validation - desktop TypeScript typecheck - desktop text-size and file-size guards - focused fuzzy-search unit tests (24 passed) - focused search Playwright coverage (7 passed), including channel and DM copy, one-character results/no-results, 40-result scrolling, and the non-sticky scope action - desktop E2E build - visual review of channel, scoped, expanded-results, and DM states --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Carl <3c4caeafb646d23867f1c4832e68211d77e2561946171625f75c3ce1a3f2670f@buzz.block.builderlab.xyz>
89 lines
2.0 KiB
TypeScript
89 lines
2.0 KiB
TypeScript
import * as React from "react";
|
|
|
|
import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
|
|
|
|
type AppShellKeyboardShortcutsOptions = {
|
|
canSearchCurrentChannel: boolean;
|
|
disabled: boolean;
|
|
onBrowseChannels: () => void;
|
|
onCreateChannel: () => void;
|
|
onGoHome: () => unknown;
|
|
onNewMessage: () => unknown;
|
|
onSearchCurrentChannel: () => void;
|
|
onSearchEverything: () => void;
|
|
};
|
|
|
|
export function useAppShellKeyboardShortcuts({
|
|
canSearchCurrentChannel,
|
|
disabled,
|
|
onBrowseChannels,
|
|
onCreateChannel,
|
|
onGoHome,
|
|
onNewMessage,
|
|
onSearchCurrentChannel,
|
|
onSearchEverything,
|
|
}: AppShellKeyboardShortcutsOptions) {
|
|
React.useLayoutEffect(() => {
|
|
if (disabled) return;
|
|
|
|
function handleKeyDown(event: KeyboardEvent) {
|
|
if (
|
|
!hasPrimaryShortcutModifier(event) ||
|
|
event.altKey ||
|
|
event.repeat ||
|
|
event.defaultPrevented
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const key = event.key.toLowerCase();
|
|
if (key === "f" && !event.shiftKey && canSearchCurrentChannel) {
|
|
event.preventDefault();
|
|
onSearchCurrentChannel();
|
|
return;
|
|
}
|
|
|
|
if (key === "k" && !event.shiftKey) {
|
|
event.preventDefault();
|
|
onSearchEverything();
|
|
return;
|
|
}
|
|
|
|
if (key === "k" && event.shiftKey) {
|
|
event.preventDefault();
|
|
void onNewMessage();
|
|
return;
|
|
}
|
|
|
|
if (key === "n" && event.shiftKey) {
|
|
event.preventDefault();
|
|
onCreateChannel();
|
|
return;
|
|
}
|
|
|
|
if (key === "o" && event.shiftKey) {
|
|
event.preventDefault();
|
|
onBrowseChannels();
|
|
return;
|
|
}
|
|
|
|
if (key === "a" && event.shiftKey) {
|
|
event.preventDefault();
|
|
void onGoHome();
|
|
}
|
|
}
|
|
|
|
window.addEventListener("keydown", handleKeyDown);
|
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
}, [
|
|
canSearchCurrentChannel,
|
|
disabled,
|
|
onBrowseChannels,
|
|
onCreateChannel,
|
|
onGoHome,
|
|
onNewMessage,
|
|
onSearchCurrentChannel,
|
|
onSearchEverything,
|
|
]);
|
|
}
|