16
useRef,
17
useState,
18
} from 'react';
19
-import {LOCAL_STORAGE_OPEN_IN_EDITOR_URL} from '../../../constants';
19
+import {
20
+ LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
21
+ LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET,
22
+} from '../../../constants';
23
import {useLocalStorage, useSubscription} from '../hooks';
24
import {StoreContext} from '../context';
25
import Button from '../Button';
54
RegExpComponentFilter,
55
} from 'react-devtools-shared/src/types';
56
57
+const vscodeFilepath = 'vscode://file/{path}:{line}';
58
+
59
export default function ComponentsSettings(_: {}): React.Node {
60
const store = useContext(StoreContext);
61
const {parseHookNames, setParseHookNames} = useContext(SettingsContext);
88
[setParseHookNames],
89
);
90
91
+ const [openInEditorURLPreset, setOpenInEditorURLPreset] = useLocalStorage<
92
+ 'vscode' | 'custom',
93
+ >(LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET, 'custom');
94
+
95
const [openInEditorURL, setOpenInEditorURL] = useLocalStorage<string>(
96
LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
97
getDefaultOpenInEditorURL(),
289
290
<label className={styles.OpenInURLSetting}>
291
Open in Editor URL:{' '}
283
- <input
284
- className={styles.Input}
285
- type="text"
286
- placeholder={process.env.EDITOR_URL ?? 'vscode://file/{path}:{line}'}
287
- value={openInEditorURL}
288
- onChange={event => {
289
- setOpenInEditorURL(event.target.value);
290
- }}
291
- />
292
+ <select
293
+ className={styles.Select}
294
+ value={openInEditorURLPreset}
295
+ onChange={({currentTarget}) => {
296
+ const selectedValue = currentTarget.value;
297
+ setOpenInEditorURLPreset(selectedValue);
298
+ if (selectedValue === 'vscode') {
299
+ setOpenInEditorURL(vscodeFilepath);
300
+ } else if (selectedValue === 'custom') {
301
+ setOpenInEditorURL('');
302
+ }
303
+ }}>
304
+ <option value="vscode">VS Code</option>
305
+ <option value="custom">Custom</option>
306
+ </select>
307
+ {openInEditorURLPreset === 'custom' && (
308
+ <input
309
+ className={styles.Input}
310
+ type="text"
311
+ placeholder={process.env.EDITOR_URL ? process.env.EDITOR_URL : ''}
312
+ value={openInEditorURL}
313
+ onChange={event => {
314
+ setOpenInEditorURL(event.target.value);
315
+ }}
316
+ />
317
+ )}
318
</label>
319
320
<div className={styles.Header}>Hide components where...</div>