Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SelectionManager] Use event.detail instead for counting the mousedown event #780

Merged
merged 2 commits into from
Jul 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 3 additions & 49 deletions src/SelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ export class SelectionManager extends EventEmitter {
*/
private _dragScrollAmount: number;

/**
* The last time the mousedown event fired, this is used to track double and
* triple clicks.
*/
private _lastMouseDownTime: number;

/**
* The last position the mouse was clicked [x, y].
*/
private _lastMousePosition: [number, number];

/**
* The number of clicks of the mousedown event. This is used to keep track of
* double and triple clicks.
*/
private _clickCount: number;

/**
* The current selection mode.
*/
Expand Down Expand Up @@ -135,7 +118,6 @@ export class SelectionManager extends EventEmitter {
this.enable();

this._model = new SelectionModel(_terminal);
this._lastMouseDownTime = 0;
this._activeSelectionMode = SelectionMode.NORMAL;
}

Expand Down Expand Up @@ -396,16 +378,14 @@ export class SelectionManager extends EventEmitter {
// Reset drag scroll state
this._dragScrollAmount = 0;

this._setMouseClickCount(event);

if (event.shiftKey) {
this._onShiftClick(event);
} else {
if (this._clickCount === 1) {
if (event.detail === 1) {
this._onSingleClick(event);
} else if (this._clickCount === 2) {
} else if (event.detail === 2) {
this._onDoubleClick(event);
} else if (this._clickCount === 3) {
} else if (event.detail === 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be >= to maintain current behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, more than three clicks should yield the same behaviour as three clicks.

this._onTripleClick(event);
}
}
Expand Down Expand Up @@ -491,32 +471,6 @@ export class SelectionManager extends EventEmitter {
}
}

/**
* Sets the number of clicks for the current mousedown event based on the time
* and position of the last mousedown event.
* @param event The mouse event.
*/
private _setMouseClickCount(event: MouseEvent): void {
let currentTime = (new Date()).getTime();
if (currentTime - this._lastMouseDownTime > CLEAR_MOUSE_DOWN_TIME || this._distanceFromLastMousePosition(event) > CLEAR_MOUSE_DISTANCE) {
this._clickCount = 0;
}
this._lastMouseDownTime = currentTime;
this._lastMousePosition = [event.pageX, event.pageY];
this._clickCount++;
}

/**
* Gets the maximum number of pixels in each direction the mouse has moved.
* @param event The mouse event.
*/
private _distanceFromLastMousePosition(event: MouseEvent): number {
const result = Math.max(
Math.abs(this._lastMousePosition[0] - event.pageX),
Math.abs(this._lastMousePosition[1] - event.pageY));
return result;
}

/**
* Handles the mousemove event when the mouse button is down, recording the
* end of the selection and refreshing the selection.
Expand Down