feat: Improve settings navigation hotkey behavior

- Add location check to prevent navigating to settings when already on settings page
- Enable hotkey on content editable and form elements
- Use useLocation to track current route
This commit is contained in:
xiaotianxt 2025-02-27 15:03:40 +08:00 committed by 亢奋猫
parent b2ebbc1e30
commit 79c7c3dc1c

View File

@ -1,14 +1,19 @@
import { useHotkeys } from 'react-hotkeys-hook' import { useHotkeys } from 'react-hotkeys-hook'
import { useNavigate } from 'react-router-dom' import { useLocation, useNavigate } from 'react-router-dom'
const NavigationHandler: React.FC = () => { const NavigationHandler: React.FC = () => {
const location = useLocation()
const navigate = useNavigate() const navigate = useNavigate()
useHotkeys( useHotkeys(
'meta+, ! ctrl+,', 'meta+, ! ctrl+,',
function () { function () {
if (location.pathname.startsWith('/settings')) {
return
}
navigate('/settings/provider') navigate('/settings/provider')
}, },
{ splitKey: '!' } { splitKey: '!', enableOnContentEditable: true, enableOnFormTags: true }
) )
return null return null