Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable opening external URLs in editor #1524

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions src/renderer/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,22 @@ export class Editor extends React.Component<EditorProps> {
const { fontFamily, fontSize } = appState;

if (ref) {
this.editor = monaco.editor.create(ref, {
automaticLayout: true,
language: this.language,
theme: 'main',
fontFamily,
fontSize,
contextmenu: false,
model: null,
...monacoOptions,
});
this.editor = monaco.editor.create(
ref,
{
automaticLayout: true,
language: this.language,
theme: 'main',
fontFamily,
fontSize,
contextmenu: false,
model: null,
...monacoOptions,
},
{
openerService: this.openerService(),
},
);

// mark this editor as focused whenever it is
this.editor.onDidFocusEditorText(() => {
Expand All @@ -113,6 +119,28 @@ export class Editor extends React.Component<EditorProps> {
}
}

/**
* Implements external url handling for Monaco.
*
* @returns {MonacoType.editor.IOpenerService}
*/
private openerService() {
const { appState } = this.props;

return {
open: (url: string) => {
appState
.showConfirmDialog({
label: `Open ${url} in external browser?`,
ok: 'Open',
})
.then((open) => {
if (open) window.open(url);
});
},
};
}

public render() {
return <div className="editorContainer" ref={this.containerRef} />;
}
Expand Down
48 changes: 38 additions & 10 deletions src/renderer/components/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,22 @@ export const Output = observer(
const ref = this.outputRef.current;
if (ref) {
this.setupCustomOutputEditorLanguage(monaco);
this.editor = monaco.editor.create(ref, {
language: this.language,
theme: 'main',
readOnly: true,
contextmenu: false,
automaticLayout: true,
model: this.model,
...monacoOptions,
wordWrap: 'on',
});
this.editor = monaco.editor.create(
ref,
{
language: this.language,
theme: 'main',
readOnly: true,
contextmenu: false,
automaticLayout: true,
model: this.model,
...monacoOptions,
wordWrap: 'on',
},
{
openerService: this.openerService(),
},
);
}
}

Expand Down Expand Up @@ -193,6 +199,28 @@ export const Output = observer(
return lines;
}

/**
* Implements external url handling for Monaco.
*
* @returns {MonacoType.editor.IOpenerService}
*/
private openerService() {
const { appState } = this.props;

return {
open: (url: string) => {
appState
.showConfirmDialog({
label: `Open ${url} in external browser?`,
ok: 'Open',
})
.then((open) => {
if (open) window.open(url);
});
},
};
}

public render(): JSX.Element | null {
const { isConsoleShowing } = this.props.appState;

Expand Down