mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-23 18:13:53 +03:00
More customizable url when opening an external editor
This commit is contained in:
parent
5c4721acf0
commit
96aa706040
|
@ -47,37 +47,12 @@ export default ({ options, saveOption }: OptionsProps) => {
|
||||||
id="editor"
|
id="editor"
|
||||||
type="text"
|
type="text"
|
||||||
size={33}
|
size={33}
|
||||||
maxLength={30}
|
placeholder={'vscode://file/{path}:{line}:{column}'}
|
||||||
placeholder="vscode, atom, webstorm, sublime..."
|
value={options.editorURL}
|
||||||
value={options.editor}
|
|
||||||
disabled={options.useEditor !== EditorState.EXTERNAL}
|
disabled={options.useEditor !== EditorState.EXTERNAL}
|
||||||
onChange={(e) =>
|
onChange={(e) => saveOption('editorURL', e.target.value)}
|
||||||
saveOption('editor', e.target.value.replace(/\W/g, ''))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="option option_type_radio">
|
|
||||||
<label
|
|
||||||
className="option__label"
|
|
||||||
htmlFor="editor-external"
|
|
||||||
style={{ marginLeft: '20px' }}
|
|
||||||
>
|
|
||||||
Absolute path to the project directory to open:
|
|
||||||
</label>
|
|
||||||
<br />
|
|
||||||
<textarea
|
|
||||||
className="option__textarea"
|
|
||||||
placeholder="/home/user/my-awesome-app"
|
|
||||||
value={options.projectPath}
|
|
||||||
disabled={options.useEditor !== EditorState.EXTERNAL}
|
|
||||||
onChange={(e) =>
|
|
||||||
saveOption('projectPath', e.target.value.replace('\n', ''))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<div className="option__hint">
|
|
||||||
Run `pwd` in your project root directory to get it
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { FilterState, FilterStateValue } from '../../../app/api/filters';
|
||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
readonly useEditor: number;
|
readonly useEditor: number;
|
||||||
readonly editor: string;
|
readonly editorURL: string;
|
||||||
readonly projectPath: string;
|
|
||||||
readonly maxAge: number;
|
readonly maxAge: number;
|
||||||
readonly filter: FilterStateValue;
|
readonly filter: FilterStateValue;
|
||||||
readonly allowlist: string;
|
readonly allowlist: string;
|
||||||
|
@ -16,8 +15,7 @@ export interface Options {
|
||||||
|
|
||||||
interface OldOrNewOptions {
|
interface OldOrNewOptions {
|
||||||
readonly useEditor: number;
|
readonly useEditor: number;
|
||||||
readonly editor: string;
|
readonly editorURL: string;
|
||||||
readonly projectPath: string;
|
|
||||||
readonly maxAge: number;
|
readonly maxAge: number;
|
||||||
readonly filter:
|
readonly filter:
|
||||||
| FilterStateValue
|
| FilterStateValue
|
||||||
|
@ -77,8 +75,7 @@ const get = (callback: (options: Options) => void) => {
|
||||||
chrome.storage.sync.get(
|
chrome.storage.sync.get(
|
||||||
{
|
{
|
||||||
useEditor: 0,
|
useEditor: 0,
|
||||||
editor: '',
|
editorURL: '',
|
||||||
projectPath: '',
|
|
||||||
maxAge: 50,
|
maxAge: 50,
|
||||||
filter: FilterState.DO_NOT_FILTER,
|
filter: FilterState.DO_NOT_FILTER,
|
||||||
whitelist: '',
|
whitelist: '',
|
||||||
|
|
|
@ -55,8 +55,7 @@ function openInIframe(url: string) {
|
||||||
setTimeout(() => iframe.parentNode!.removeChild(iframe), 3000);
|
setTimeout(() => iframe.parentNode!.removeChild(iframe), 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openInEditor(editor: string, path: string, stackFrame: StackFrame) {
|
function openInEditor(editorURL: string, stackFrame: StackFrame) {
|
||||||
const projectPath = path.replace(/\/$/, '');
|
|
||||||
const file =
|
const file =
|
||||||
stackFrame._originalFileName ||
|
stackFrame._originalFileName ||
|
||||||
(stackFrame as unknown as { finalFileName: string }).finalFileName ||
|
(stackFrame as unknown as { finalFileName: string }).finalFileName ||
|
||||||
|
@ -69,30 +68,17 @@ function openInEditor(editor: string, path: string, stackFrame: StackFrame) {
|
||||||
const line = stackFrame._originalLineNumber || stackFrame.lineNumber || '0';
|
const line = stackFrame._originalLineNumber || stackFrame.lineNumber || '0';
|
||||||
const column =
|
const column =
|
||||||
stackFrame._originalColumnNumber || stackFrame.columnNumber || '0';
|
stackFrame._originalColumnNumber || stackFrame.columnNumber || '0';
|
||||||
let url;
|
|
||||||
|
|
||||||
switch (editor) {
|
const url = new URL(editorURL);
|
||||||
case 'vscode':
|
url.href = url.href.replace('{path}', filePath);
|
||||||
case 'code':
|
url.href = url.href.replace('{line}', String(line));
|
||||||
url = `vscode://file/${projectPath}${filePath}:${line}:${column}`;
|
url.href = url.href.replace('{column}', String(column));
|
||||||
break;
|
|
||||||
case 'atom':
|
|
||||||
url = `atom://core/open/file?filename=${projectPath}${filePath}&line=${line}&column=${column}`;
|
|
||||||
break;
|
|
||||||
case 'webstorm':
|
|
||||||
case 'phpstorm':
|
|
||||||
case 'idea':
|
|
||||||
url = `${editor}://open?file=${projectPath}${filePath}&line=${line}&column=${column}`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// sublime, emacs, macvim, textmate + custom like https://github.com/eclemens/atom-url-handler
|
|
||||||
url = `${editor}://open/?url=file://${projectPath}${filePath}&line=${line}&column=${column}`;
|
|
||||||
}
|
|
||||||
if (chrome.devtools && !isFF) {
|
if (chrome.devtools && !isFF) {
|
||||||
if (chrome.tabs) openAndCloseTab(url);
|
if (chrome.tabs) openAndCloseTab(url.href);
|
||||||
else window.open(url);
|
else window.open(url);
|
||||||
} else {
|
} else {
|
||||||
openInIframe(url);
|
openInIframe(url.href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,37 +91,29 @@ export default function openFile(
|
||||||
const storage = isFF
|
const storage = isFF
|
||||||
? chrome.storage.local
|
? chrome.storage.local
|
||||||
: chrome.storage.sync || chrome.storage.local;
|
: chrome.storage.sync || chrome.storage.local;
|
||||||
storage.get(
|
storage.get(['useEditor', 'editorURL'], function ({ useEditor, editorURL }) {
|
||||||
['useEditor', 'editor', 'projectPath'],
|
if (useEditor && typeof editorURL === 'string') {
|
||||||
function ({ useEditor, editor, projectPath }) {
|
openInEditor(editorURL, stackFrame);
|
||||||
|
} else {
|
||||||
if (
|
if (
|
||||||
useEditor &&
|
chrome.devtools &&
|
||||||
projectPath &&
|
chrome.devtools.panels &&
|
||||||
typeof editor === 'string' &&
|
!!chrome.devtools.panels.openResource
|
||||||
/^\w{1,30}$/.test(editor)
|
|
||||||
) {
|
) {
|
||||||
openInEditor(editor.toLowerCase(), projectPath as string, stackFrame);
|
openResource(fileName, lineNumber, stackFrame);
|
||||||
} else {
|
} else if (chrome.runtime && (chrome.runtime.openOptionsPage || isFF)) {
|
||||||
if (
|
if (chrome.devtools && isFF) {
|
||||||
chrome.devtools &&
|
chrome.devtools.inspectedWindow.eval(
|
||||||
chrome.devtools.panels &&
|
'confirm("Set the editor to open the file in?")',
|
||||||
!!chrome.devtools.panels.openResource
|
(result) => {
|
||||||
) {
|
if (!result) return;
|
||||||
openResource(fileName, lineNumber, stackFrame);
|
chrome.runtime.sendMessage({ type: 'OPEN_OPTIONS' });
|
||||||
} else if (chrome.runtime && (chrome.runtime.openOptionsPage || isFF)) {
|
}
|
||||||
if (chrome.devtools && isFF) {
|
);
|
||||||
chrome.devtools.inspectedWindow.eval(
|
} else if (confirm('Set the editor to open the file in?')) {
|
||||||
'confirm("Set the editor to open the file in?")',
|
chrome.runtime.openOptionsPage();
|
||||||
(result) => {
|
|
||||||
if (!result) return;
|
|
||||||
chrome.runtime.sendMessage({ type: 'OPEN_OPTIONS' });
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if (confirm('Set the editor to open the file in?')) {
|
|
||||||
chrome.runtime.openOptionsPage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user