Skip to content

Commit

Permalink
feat: enable opening external URLs in editor (#1524)
Browse files Browse the repository at this point in the history
codebytere authored Jan 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d5e49c4 commit 7f4101d
Showing 2 changed files with 76 additions and 20 deletions.
48 changes: 38 additions & 10 deletions src/renderer/components/editor.tsx
Original file line number Diff line number Diff line change
@@ -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(() => {
@@ -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} />;
}
48 changes: 38 additions & 10 deletions src/renderer/components/output.tsx
Original file line number Diff line number Diff line change
@@ -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(),
},
);
}
}

@@ -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;

0 comments on commit 7f4101d

Please sign in to comment.