Skip to content

Commit 493f72b

Browse files
Biki-dashoxyqBIKI
authored
Feat:-Added open in editor to appear by default (#26949)
Currently the Open in editor just is a placeholder input where the developer would need to type the whole Vscode file path being shown as a placeholder, we can make this process a little easier by just already setting the URL . https://github.com/facebook/react/assets/72331432/96f43230-6c49-45f7-907c-c99a0d3d8bf7 Earlier it used to be a placeholder describing the URL <img width="1284" alt="Screenshot 2023-06-14 at 7 55 38 PM" src="https://github.com/facebook/react/assets/72331432/4e8234ad-e1cd-4b55-8ef8-46dea82a9c7c"> cc @hoxyq --------- Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com> Co-authored-by: BIKI <biki@BIKIs-MacBook-Pro.local>
1 parent fdb368d commit 493f72b

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

packages/react-devtools-shared/src/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export const SESSION_STORAGE_LAST_SELECTION_KEY =
3939
export const LOCAL_STORAGE_OPEN_IN_EDITOR_URL =
4040
'React::DevTools::openInEditorUrl';
4141

42+
export const LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET =
43+
'React::DevTools::openInEditorUrlPreset';
44+
4245
export const LOCAL_STORAGE_PARSE_HOOK_NAMES_KEY =
4346
'React::DevTools::parseHookNames';
4447

packages/react-devtools-shared/src/devtools/views/Components/InspectedElement.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ export default function InspectedElementWrapper(_: Props): React.Node {
219219
}
220220

221221
const url = new URL(editorURL);
222-
url.href = url.href.replace('{path}', source.fileName);
223-
url.href = url.href.replace('{line}', String(source.lineNumber));
222+
url.href = url.href
223+
.replace('{path}', source.fileName)
224+
.replace('{line}', String(source.lineNumber))
225+
.replace('%7Bpath%7D', source.fileName)
226+
.replace('%7Bline%7D', String(source.lineNumber));
224227
window.open(url);
225228
}, [inspectedElement, editorURL]);
226229

packages/react-devtools-shared/src/devtools/views/Settings/ComponentsSettings.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
useRef,
1717
useState,
1818
} 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';
2023
import {useLocalStorage, useSubscription} from '../hooks';
2124
import {StoreContext} from '../context';
2225
import Button from '../Button';
@@ -51,6 +54,8 @@ import type {
5154
RegExpComponentFilter,
5255
} from 'react-devtools-shared/src/types';
5356

57+
const vscodeFilepath = 'vscode://file/{path}:{line}';
58+
5459
export default function ComponentsSettings(_: {}): React.Node {
5560
const store = useContext(StoreContext);
5661
const {parseHookNames, setParseHookNames} = useContext(SettingsContext);
@@ -83,6 +88,10 @@ export default function ComponentsSettings(_: {}): React.Node {
8388
[setParseHookNames],
8489
);
8590

91+
const [openInEditorURLPreset, setOpenInEditorURLPreset] = useLocalStorage<
92+
'vscode' | 'custom',
93+
>(LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET, 'custom');
94+
8695
const [openInEditorURL, setOpenInEditorURL] = useLocalStorage<string>(
8796
LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
8897
getDefaultOpenInEditorURL(),
@@ -280,15 +289,32 @@ export default function ComponentsSettings(_: {}): React.Node {
280289

281290
<label className={styles.OpenInURLSetting}>
282291
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+
)}
292318
</label>
293319

294320
<div className={styles.Header}>Hide components where...</div>

packages/react-devtools-shared/src/devtools/views/Settings/SettingsShared.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
border: 1px solid var(--color-border);
8989
border-radius: 0.125rem;
9090
padding: 0.125rem;
91+
margin-left: .5rem;
9192
}
9293

9394
.InvalidRegExp,

0 commit comments

Comments
 (0)