feat: add sidebar type-to-search

This commit is contained in:
Spencer.Chang authored and GitHub committed 2026-06-18 13:13:45 +08:00
1 parent ca427715af
commit fae454f96a
3 files changed
+83 -2

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
export interface SidebarTypeSearchKeyEvent {
key: string;
ctrlKey?: boolean;
metaKey?: boolean;
altKey?: boolean;
isComposing?: boolean;
}
export function isEditableSidebarTypeSearchTarget(target: EventTarget | null): boolean {
if (!(target instanceof HTMLElement)) return false;
return !!target.closest("input, textarea, select, [contenteditable='true'], .cm-editor");
}
export function sidebarTypeSearchNextQuery(currentQuery: string, event: SidebarTypeSearchKeyEvent): string | null {
if (event.ctrlKey || event.metaKey || event.altKey || event.isComposing) return null;
if (event.key === "Backspace") {
if (!currentQuery) return null;
return currentQuery.slice(0, -1);
}
if (event.key.length !== 1) return null;
if (event.key === " " && !currentQuery.trim()) return null;
return `${currentQuery}${event.key}`;
}