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

@ -154,6 +154,10 @@ module.exports = {
// rendering (slower, but supports transparent backgrounds)
webGLRenderer: true,
// keypress required for weblink activation: [ctrl|alt|meta|shift]
// todo: does not pick up config changes automatically, need to restart terminal :/
webLinksActivationKey: '',
// if `true` (without backticks and without quotes), Hyper will ignore ligatures provided by some fonts
disableLigatures: false,

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

1
lib/config.d.ts vendored
View file

@ -59,6 +59,7 @@ export type configOptions = {
updateChannel: 'stable' | 'canary';
useConpty: boolean;
webGLRenderer: boolean;
webLinksActivationKey: 'ctrl' | 'alt' | 'meta' | 'shift';
windowSize: [number, number];
};

View file

@ -43,6 +43,7 @@ const mapStateToProps = (state: HyperState) => {
modifierKeys: state.ui.modifierKeys,
quickEdit: state.ui.quickEdit,
webGLRenderer: state.ui.webGLRenderer,
webLinksActivationKey: state.ui.webLinksActivationKey,
macOptionSelectionMode: state.ui.macOptionSelectionMode,
disableLigatures: state.ui.disableLigatures
};

3
lib/hyper.d.ts vendored
View file

@ -105,6 +105,7 @@ export type uiState = {
updateReleaseUrl: string | null;
updateVersion: string | null;
webGLRenderer: boolean;
webLinksActivationKey: string;
};
export type session = {
@ -308,6 +309,7 @@ export type TermGroupOwnProps = {
| 'toggleSearch'
| 'uiFontFamily'
| 'webGLRenderer'
| 'webLinksActivationKey'
>;
import {TermGroupConnectedProps} from './components/term-group';
@ -368,6 +370,7 @@ export type TermProps = {
uiFontFamily: string;
url: string | null;
webGLRenderer: boolean;
webLinksActivationKey: string;
} & extensionProps & {ref_?: any};
export type Assignable<T, U> = {[k in keyof U]: k extends keyof T ? T[k] : U[k]} & Partial<T>;

View file

@ -108,6 +108,7 @@ const initial: ImmutableType<uiState> = Immutable({
showWindowControls: '',
quickEdit: false,
webGLRenderer: true,
webLinksActivationKey: '',
macOptionSelectionMode: 'vertical',
disableLigatures: false
});
@ -256,6 +257,10 @@ const reducer = (state = initial, action: HyperActions) => {
ret.webGLRenderer = config.webGLRenderer;
}
if (config.webLinksActivationKey !== undefined) {
ret.webLinksActivationKey = config.webLinksActivationKey;
}
if (config.macOptionSelectionMode) {
ret.macOptionSelectionMode = config.macOptionSelectionMode;
}