mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
Add hotkey controls to relevant pages
This commit is contained in:
parent
d7f24262fd
commit
4c98afb613
6 changed files with 155 additions and 37 deletions
|
|
@ -3,6 +3,8 @@ import { TextInputProps } from '@mantine/core';
|
|||
import { useFocusWithin, useHotkeys, useMergedRef } from '@mantine/hooks';
|
||||
import { RiSearchLine } from 'react-icons/ri';
|
||||
import { TextInput } from '/@/renderer/components/input';
|
||||
import { useSettingsStore } from '/@/renderer/store';
|
||||
import { shallow } from 'zustand/shallow';
|
||||
|
||||
interface SearchInputProps extends TextInputProps {
|
||||
initialWidth?: number;
|
||||
|
|
@ -18,18 +20,12 @@ export const SearchInput = ({
|
|||
}: SearchInputProps) => {
|
||||
const { ref, focused } = useFocusWithin();
|
||||
const mergedRef = useMergedRef<HTMLInputElement>(ref);
|
||||
const binding = useSettingsStore((state) => state.hotkeys.bindings.localSearch, shallow);
|
||||
|
||||
const isOpened = focused || ref.current?.value;
|
||||
const showIcon = !isOpened || (openedWidth || 100) > 100;
|
||||
|
||||
useHotkeys([
|
||||
[
|
||||
'ctrl+F',
|
||||
() => {
|
||||
ref.current.select();
|
||||
},
|
||||
],
|
||||
]);
|
||||
useHotkeys([[binding.hotkey, () => ref.current.select()]]);
|
||||
|
||||
const handleEscape = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.code === 'Escape') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue