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) // rendering (slower, but supports transparent backgrounds)
webGLRenderer: true, 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 // if `true` (without backticks and without quotes), Hyper will ignore ligatures provided by some fonts
disableLigatures: false, disableLigatures: false,

View file

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

View file

@ -148,13 +148,27 @@ export default class Term extends React.PureComponent<TermProps> {
} }
Term.reportRenderer(props.uid, useWebGL ? 'WebGL' : 'Canvas'); 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.attachCustomKeyEventHandler(this.keyboardHandler);
this.term.loadAddon(this.fitAddon); this.term.loadAddon(this.fitAddon);
this.term.loadAddon(this.searchAddon); this.term.loadAddon(this.searchAddon);
this.term.loadAddon( this.term.loadAddon(
new WebLinksAddon((event, uri) => { new WebLinksAddon(
shell.openExternal(uri); (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); this.term.open(this.termRef);
if (useWebGL) { if (useWebGL) {

View file

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

1
lib/config.d.ts vendored
View file

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

View file

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

3
lib/hyper.d.ts vendored
View file

@ -105,6 +105,7 @@ export type uiState = {
updateReleaseUrl: string | null; updateReleaseUrl: string | null;
updateVersion: string | null; updateVersion: string | null;
webGLRenderer: boolean; webGLRenderer: boolean;
webLinksActivationKey: string;
}; };
export type session = { export type session = {
@ -308,6 +309,7 @@ export type TermGroupOwnProps = {
| 'toggleSearch' | 'toggleSearch'
| 'uiFontFamily' | 'uiFontFamily'
| 'webGLRenderer' | 'webGLRenderer'
| 'webLinksActivationKey'
>; >;
import {TermGroupConnectedProps} from './components/term-group'; import {TermGroupConnectedProps} from './components/term-group';
@ -368,6 +370,7 @@ export type TermProps = {
uiFontFamily: string; uiFontFamily: string;
url: string | null; url: string | null;
webGLRenderer: boolean; webGLRenderer: boolean;
webLinksActivationKey: string;
} & extensionProps & {ref_?: any}; } & extensionProps & {ref_?: any};
export type Assignable<T, U> = {[k in keyof U]: k extends keyof T ? T[k] : U[k]} & Partial<T>; 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: '', showWindowControls: '',
quickEdit: false, quickEdit: false,
webGLRenderer: true, webGLRenderer: true,
webLinksActivationKey: '',
macOptionSelectionMode: 'vertical', macOptionSelectionMode: 'vertical',
disableLigatures: false disableLigatures: false
}); });
@ -256,6 +257,10 @@ const reducer = (state = initial, action: HyperActions) => {
ret.webGLRenderer = config.webGLRenderer; ret.webGLRenderer = config.webGLRenderer;
} }
if (config.webLinksActivationKey !== undefined) {
ret.webLinksActivationKey = config.webLinksActivationKey;
}
if (config.macOptionSelectionMode) { if (config.macOptionSelectionMode) {
ret.macOptionSelectionMode = config.macOptionSelectionMode; ret.macOptionSelectionMode = config.macOptionSelectionMode;
} }