1
1
import { Dialog , Transition } from '@headlessui/react'
2
2
import { Fragment , useEffect , useRef } from 'react'
3
- import { useHotkeys } from 'react-hotkeys-hook'
4
3
import { useLocation , useNavigate , useSearchParams } from 'react-router-dom'
5
4
6
5
import { CustomIcon } from '@src/components/CustomIcon'
@@ -10,23 +9,26 @@ import { KeybindingsSectionsList } from '@src/components/Settings/KeybindingsSec
10
9
import { SettingsSearchBar } from '@src/components/Settings/SettingsSearchBar'
11
10
import { SettingsSectionsList } from '@src/components/Settings/SettingsSectionsList'
12
11
import { SettingsTabs } from '@src/components/Settings/SettingsTabs'
13
- import { useDotDotSlash } from '@src/hooks/useDotDotSlash'
14
12
import { PATHS } from '@src/lib/paths'
15
13
import type { SettingsLevel } from '@src/lib/settings/settingsTypes'
16
14
17
15
export const Settings = ( ) => {
18
16
const navigate = useNavigate ( )
19
17
const [ searchParams , setSearchParams ] = useSearchParams ( )
20
- const close = ( ) => navigate ( location . pathname . replace ( PATHS . SETTINGS , '' ) )
18
+ const close = ( ) => {
19
+ // This makes sure input texts are saved before closing the dialog (eg. default project name).
20
+ if ( document . activeElement instanceof HTMLInputElement ) {
21
+ document . activeElement . blur ( )
22
+ }
23
+ navigate ( location . pathname . replace ( PATHS . SETTINGS , '' ) )
24
+ }
21
25
const location = useLocation ( )
22
26
const isFileSettings = location . pathname . includes ( PATHS . FILE )
23
27
const searchParamTab =
24
28
( searchParams . get ( 'tab' ) as SettingsLevel | 'keybindings' ) ??
25
29
( isFileSettings ? 'project' : 'user' )
26
30
27
31
const scrollRef = useRef < HTMLDivElement > ( null )
28
- const dotDotSlash = useDotDotSlash ( )
29
- useHotkeys ( 'esc' , ( ) => navigate ( dotDotSlash ( ) ) )
30
32
31
33
// Scroll to the hash on load if it exists
32
34
useEffect ( ( ) => {
0 commit comments