add web-link activation modifier

This commit is contained in:
Vassiliy Shvetsov 2020-05-06 12:04:14 -07:00 committed by Benjamin Staneck
parent 7d571cfdc2
commit ffd4eb46e3
8 changed files with 33 additions and 3 deletions

View file

@ -102,6 +102,7 @@ class TermGroup_ extends React.PureComponent<TermGroupProps> {
selectionColor: this.props.selectionColor,
quickEdit: this.props.quickEdit,
webGLRenderer: this.props.webGLRenderer,
webLinksActivationKey: this.props.webLinksActivationKey,
macOptionSelectionMode: this.props.macOptionSelectionMode,
disableLigatures: this.props.disableLigatures,
uid

View file

@ -148,13 +148,27 @@ export default class Term extends React.PureComponent<TermProps> {
}
Term.reportRenderer(props.uid, useWebGL ? 'WebGL' : 'Canvas');
const shallActivateWebLink = (event: Record<string, any> | undefined) => {
return event && (!props.webLinksActivationKey || event[`${props.webLinksActivationKey}Key`]);
};
this.term.attachCustomKeyEventHandler(this.keyboardHandler);
this.term.loadAddon(this.fitAddon);
this.term.loadAddon(this.searchAddon);
this.term.loadAddon(
new WebLinksAddon((event, uri) => {
shell.openExternal(uri);
})
new WebLinksAddon(
(event: MouseEvent | undefined, uri: string) => {
if (shallActivateWebLink(event)) shell.openExternal(uri);
},
{
// prevent default electron link handling to allow selection, e.g. via double-click
willLinkActivate: (event: MouseEvent | undefined) => {
event?.preventDefault();
return shallActivateWebLink(event);
},
priority: Date.now()
}
)
);
this.term.open(this.termRef);
if (useWebGL) {

View file

@ -113,6 +113,7 @@ export default class Terms extends React.Component<TermsProps> {
onContextMenu: this.props.onContextMenu,
quickEdit: this.props.quickEdit,
webGLRenderer: this.props.webGLRenderer,
webLinksActivationKey: this.props.webLinksActivationKey,
macOptionSelectionMode: this.props.macOptionSelectionMode,
disableLigatures: this.props.disableLigatures,
parentProps: this.props