Merge pull request #1264 from Tyriar/1021_support_modifiers

Allow support of modifiers with links
This commit is contained in:
Daniel Imms
2018-02-06 02:32:00 -08:00
committed by GitHub
5 changed files with 37 additions and 12 deletions
+7
View File
@@ -150,6 +150,7 @@ export class Linkifier extends EventEmitter implements ILinkifier {
validationCallback: options.validationCallback, validationCallback: options.validationCallback,
hoverTooltipCallback: options.tooltipCallback, hoverTooltipCallback: options.tooltipCallback,
hoverLeaveCallback: options.leaveCallback, hoverLeaveCallback: options.leaveCallback,
willLinkActivate: options.willLinkActivate,
priority: options.priority || 0 priority: options.priority || 0
}; };
this._addLinkMatcherToList(matcher); this._addLinkMatcherToList(matcher);
@@ -290,6 +291,12 @@ export class Linkifier extends EventEmitter implements ILinkifier {
if (matcher.hoverLeaveCallback) { if (matcher.hoverLeaveCallback) {
matcher.hoverLeaveCallback(); matcher.hoverLeaveCallback();
} }
},
e => {
if (matcher.willLinkActivate) {
return matcher.willLinkActivate(e, uri);
}
return true;
} }
)); ));
} }
+8
View File
@@ -161,6 +161,7 @@ export interface ILinkMatcher {
matchIndex?: number; matchIndex?: number;
validationCallback?: LinkMatcherValidationCallback; validationCallback?: LinkMatcherValidationCallback;
priority?: number; priority?: number;
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
} }
export interface ICharset { export interface ICharset {
@@ -323,6 +324,13 @@ export interface ILinkMatcherOptions {
* default value is 0. * default value is 0.
*/ */
priority?: number; priority?: number;
/**
* A callback that fires when the mousedown and click events occur that
* determines whether a link will be activated upon click. This enables
* only activating a link when a certain modifier is held down, if not the
* mouse event will continue propagation (eg. double click to select word).
*/
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
} }
export interface IBrowser { export interface IBrowser {
+8 -7
View File
@@ -151,10 +151,10 @@ export class MouseZoneManager implements IMouseZoneManager {
// components from handling the mouse event. // components from handling the mouse event.
const zone = this._findZoneEventAt(e); const zone = this._findZoneEventAt(e);
if (zone) { if (zone) {
// TODO: When link modifier support is added, the event should only be if (zone.willLinkActivate(e)) {
// cancelled when the modifier is held (see #1021) e.preventDefault();
e.preventDefault(); e.stopImmediatePropagation();
e.stopImmediatePropagation(); }
} }
} }
@@ -189,9 +189,10 @@ export class MouseZone implements IMouseZone {
public x2: number, public x2: number,
public y: number, public y: number,
public clickCallback: (e: MouseEvent) => any, public clickCallback: (e: MouseEvent) => any,
public hoverCallback?: (e: MouseEvent) => any, public hoverCallback: (e: MouseEvent) => any,
public tooltipCallback?: (e: MouseEvent) => any, public tooltipCallback: (e: MouseEvent) => any,
public leaveCallback?: () => void public leaveCallback: () => void,
public willLinkActivate: (e: MouseEvent) => boolean
) { ) {
} }
} }
+4 -3
View File
@@ -13,7 +13,8 @@ export interface IMouseZone {
x2: number; x2: number;
y: number; y: number;
clickCallback: (e: MouseEvent) => any; clickCallback: (e: MouseEvent) => any;
hoverCallback?: (e: MouseEvent) => any; hoverCallback: (e: MouseEvent) => any | undefined;
tooltipCallback?: (e: MouseEvent) => any; tooltipCallback: (e: MouseEvent) => any | undefined;
leaveCallback?: () => any; leaveCallback: () => any | undefined;
willLinkActivate: (e: MouseEvent) => boolean;
} }
+10 -2
View File
@@ -180,8 +180,8 @@ declare module 'xterm' {
matchIndex?: number; matchIndex?: number;
/** /**
* A callback that validates an individual link, returning true if valid and * A callback that validates whether to create an individual link, pass
* false if invalid. * whether the link is valid to the callback.
*/ */
validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void; validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;
@@ -202,6 +202,14 @@ declare module 'xterm' {
* default value is 0. * default value is 0.
*/ */
priority?: number; priority?: number;
/**
* A callback that fires when the mousedown and click events occur that
* determines whether a link will be activated upon click. This enables
* only activating a link when a certain modifier is held down, if not the
* mouse event will continue propagation (eg. double click to select word).
*/
willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
} }
export interface IEventEmitter { export interface IEventEmitter {