mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-17 20:50:29 +03:00
Make hotkeys work again (#1819)
This commit is contained in:
parent
c52c4f7d32
commit
c4abe39375
40 changed files with 182 additions and 39 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import './Search.scss';
|
||||
|
||||
|
|
@ -25,6 +25,8 @@ import { roomToUnreadAtom } from '../../state/room/roomToUnread';
|
|||
import { roomToParentsAtom } from '../../state/room/roomToParents';
|
||||
import { allRoomsAtom } from '../../state/room-list/roomList';
|
||||
import { mDirectAtom } from '../../state/mDirectList';
|
||||
import { useKeyDown } from '../../hooks/useKeyDown';
|
||||
import { openSearch } from '../../../client/action/navigation';
|
||||
|
||||
function useVisiblityToggle(setResult) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
|
@ -49,6 +51,27 @@ function useVisiblityToggle(setResult) {
|
|||
}
|
||||
}, [isOpen]);
|
||||
|
||||
useKeyDown(
|
||||
window,
|
||||
useCallback((event) => {
|
||||
// Ctrl/Cmd +
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
// open search modal
|
||||
if (event.key === 'k') {
|
||||
event.preventDefault();
|
||||
// means some menu or modal window is open
|
||||
if (
|
||||
document.body.lastChild.className !== 'ReactModalPortal' ||
|
||||
navigation.isRawModalVisible
|
||||
) {
|
||||
return;
|
||||
}
|
||||
openSearch();
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
);
|
||||
|
||||
const requestClose = () => setIsOpen(false);
|
||||
|
||||
return [isOpen, requestClose];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue