Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/browser/Linkifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class Linkifier extends Disposable implements ILinkifier2 {
public get currentLink(): ILinkWithState | undefined { return this._currentLink; }
protected _currentLink: ILinkWithState | undefined;
private _mouseDownLink: ILinkWithState | undefined;
private _lastMouseDownPos: IBufferCellPosition | undefined;
private _lastMouseEvent: MouseEvent | undefined;
private _linkCacheDisposables: IDisposable[] = [];
private _lastBufferCell: IBufferCellPosition | undefined;
Expand Down Expand Up @@ -213,11 +214,21 @@ export class Linkifier extends Disposable implements ILinkifier2 {
return linkProvided;
}

private _handleMouseDown(): void {
private _handleMouseDown(event: MouseEvent): void {
if (!this._element) {
return;
}
const position = this._positionFromMouseEvent(event, this._element);

this._mouseDownLink = this._currentLink;

this._lastMouseDownPos = position;
}

private _handleMouseUp(event: MouseEvent): void {
const mouseDownLink = this._mouseDownLink;
this._mouseDownLink = undefined;

if (!this._currentLink) {
return;
}
Expand All @@ -227,7 +238,15 @@ export class Linkifier extends Disposable implements ILinkifier2 {
return;
}

if (this._mouseDownLink && linkEquals(this._mouseDownLink.link, this._currentLink.link) && this._linkAtPosition(this._currentLink.link, position)) {
// compare last mouse down position: if we strayed too much, don't open the link
// that's because very likely user intended to select the text instead of opening the link
let selectionDetected = true;
if (this._lastMouseDownPos) {
const deltaMov = Math.abs(this._lastMouseDownPos.x - position.x) + Math.abs(this._lastMouseDownPos.y - position.y);
selectionDetected = deltaMov >= 2;
}

if (!selectionDetected && mouseDownLink && linkEquals(mouseDownLink.link, this._currentLink.link) && this._linkAtPosition(this._currentLink.link, position)) {
this._currentLink.link.activate(event, this._currentLink.link.text);
}
}
Expand Down