Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-context-aware-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: minor
---

`Ctrl + K` search menu is now context aware and lists the current space's rooms at the top.
15 changes: 14 additions & 1 deletion src/app/features/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { useKeyDown } from '$hooks/useKeyDown';
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
import { KeySymbol } from '$utils/key-symbol';
import { isMacOS } from '$utils/user-agent';
import { useSelectedSpace } from '$hooks/router/useSelectedSpace';

enum SearchRoomType {
Rooms = '#',
Expand Down Expand Up @@ -167,7 +168,19 @@ export function Search({ requestClose }: SearchProps) {
);

const [result, search, resetSearch] = useAsyncSearch(targetRooms, getTargetStr, SEARCH_OPTIONS);
const roomsToRender = result ? result.items : topActiveRooms;
const selectedSpaceId = useSelectedSpace();

const roomsToRender = useMemo(() => {
const items = result ? result.items : topActiveRooms;
if (!selectedSpaceId) return items;

return [...items].sort((a, b) => {
const aInSpace = getAllParents(roomToParents, a)?.has(selectedSpaceId) ? 1 : 0;
const bInSpace = getAllParents(roomToParents, b)?.has(selectedSpaceId) ? 1 : 0;
return bInSpace - aInSpace;
});
}, [result, topActiveRooms, selectedSpaceId, roomToParents]);

const listFocus = useListFocusIndex(roomsToRender.length, 0);

const queryHighlighRegex = result?.query
Expand Down
Loading