mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
Improve desktop search scoping (#5306)
## 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>
This commit is contained in:
88
desktop/src/app/useAppShellKeyboardShortcuts.ts
Normal file
88
desktop/src/app/useAppShellKeyboardShortcuts.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
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,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user