mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-30 05:42:44 -08:00
separate ctrlK and ctrlF and add search messages
Signed-off-by: Shea <[email protected]>
This commit is contained in:
4 files changed
+43
-2
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Add search message keybind and combine sidebar items.
|
||||
@@ -16,12 +16,21 @@ import { roomToParentsAtom } from '$state/room/roomToParents';
|
||||
import { mDirectAtom } from '$state/mDirectList';
|
||||
import { roomToUnreadAtom } from '$state/room/roomToUnread';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { getDirectRoomPath, getHomeRoomPath, getSpaceRoomPath } from '$pages/pathUtils';
|
||||
import {
|
||||
getDirectRoomPath,
|
||||
getHomeRoomPath,
|
||||
getHomeSearchPath,
|
||||
getSpaceRoomPath,
|
||||
getSpaceSearchPath,
|
||||
withSearchParam,
|
||||
} from '$pages/pathUtils';
|
||||
import type { SearchPathSearchParams } from '$pages/paths';
|
||||
import { HOME_ROOM_PATH, DIRECT_ROOM_PATH, SPACE_ROOM_PATH } from '$pages/paths';
|
||||
import { getCanonicalAliasOrRoomId } from '$utils/matrix';
|
||||
import { announce } from '$utils/announce';
|
||||
import { roomIdToReplyDraftAtomFamily } from '$state/room/roomInputDrafts';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { useSelectedSpace } from '$hooks/router/useSelectedSpace';
|
||||
|
||||
export function GlobalKeyboardShortcuts() {
|
||||
const navigate = useNavigate();
|
||||
@@ -40,7 +49,9 @@ export function GlobalKeyboardShortcuts() {
|
||||
const roomIdOrAlias = roomMatch?.params.roomIdOrAlias
|
||||
? decodeURIComponent(roomMatch.params.roomIdOrAlias)
|
||||
: undefined;
|
||||
const currentSpace = useSelectedSpace();
|
||||
let currentRoom: Room | null = null;
|
||||
|
||||
if (roomIdOrAlias) {
|
||||
if (roomIdOrAlias.startsWith('!')) {
|
||||
currentRoom = mx.getRoom(roomIdOrAlias);
|
||||
@@ -151,9 +162,29 @@ export function GlobalKeyboardShortcuts() {
|
||||
[currentRoom, replyDraft, setReplyDraft]
|
||||
);
|
||||
|
||||
/** Ctrl+F: Search for messages */
|
||||
const handleSearchMessageInRoom = useCallback(
|
||||
(evt: KeyboardEvent) => {
|
||||
if (!isKeyHotkey('mod+f', evt)) return;
|
||||
evt.preventDefault();
|
||||
|
||||
const searchParams: SearchPathSearchParams = {
|
||||
rooms: currentRoom?.roomId,
|
||||
};
|
||||
const path = currentSpace
|
||||
? getSpaceSearchPath(getCanonicalAliasOrRoomId(mx, currentSpace))
|
||||
: getHomeSearchPath();
|
||||
const roomName = mx.getRoom(currentRoom?.roomId)?.name;
|
||||
navigate(withSearchParam(path, searchParams));
|
||||
announce(`Start Searching messages ${roomName ? `in ${roomName}` : ''}`);
|
||||
},
|
||||
[mx, currentRoom, currentSpace, navigate]
|
||||
);
|
||||
|
||||
useKeyDown(window, handleNextUnreadKeyDown);
|
||||
useKeyDown(window, handleUnreadNavKeyDown);
|
||||
useKeyDown(window, handleReplyKeyDown);
|
||||
useKeyDown(window, handleSearchMessageInRoom);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -521,7 +521,7 @@ export function SearchModalRenderer() {
|
||||
window,
|
||||
useCallback(
|
||||
(event) => {
|
||||
if (isKeyHotkey('mod+k', event) || isKeyHotkey('mod+f', event)) {
|
||||
if (isKeyHotkey('mod+k', event)) {
|
||||
event.preventDefault();
|
||||
if (opened) {
|
||||
setOpen(false);
|
||||
|
||||
@@ -28,12 +28,17 @@ function formatKey(key: string): string {
|
||||
}
|
||||
|
||||
const SHORTCUT_CATEGORIES: ShortcutCategory[] = [
|
||||
{
|
||||
name: 'General',
|
||||
shortcuts: [{ keys: 'Ctrl+F / ⌘+F', description: 'Search for messages' }],
|
||||
},
|
||||
{
|
||||
name: 'Navigation',
|
||||
shortcuts: [
|
||||
{ keys: 'Alt+N', description: 'Jump to the highest-priority unread room' },
|
||||
{ keys: 'Alt+Shift+Down', description: 'Go to next unread room (cycle)' },
|
||||
{ keys: 'Alt+Shift+Up', description: 'Go to previous unread room (cycle)' },
|
||||
{ keys: 'Ctrl+K / ⌘+K', description: 'Search and go to Room' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user