Skip to content

Fixed tab switching too fast when wheeling/scrolling - #112034

Merged
Benjamin Pasero (bpasero) merged 3 commits into
microsoft:masterfrom
Andre-Fonteles:tab-switch-too-fast-2
Dec 8, 2020
Merged

Benjamin Pasero (bpasero) merged 3 commits into
microsoft:masterfrom
Andre-Fonteles:tab-switch-too-fast-2

Conversation

@Andre-Fonteles

Copy link
Copy Markdown
Contributor

This PR fixes #96409 - Trackpad: Tab switch on mouse scroll: horizontal scrolling sensitivity too high.

PS: I created this new PR to avoid unrelated commits from the old one (#111901).

@bpasero Benjamin Pasero (bpasero) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested it with touchpad and mouse and seems to be working great 👍 . I left some feedback and suggested code changes.


private path: IPath = isWindows ? win32 : posix;

private lastMouseWheelEventTime: number = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
private lastMouseWheelEventTime: number = 0;
private lastMouseWheelEventTime = 0;

// Figure out scrolling direction
const nextEditor = this.group.getEditorByIndex(this.group.getIndexOfEditor(activeEditor) + (e.deltaX < 0 || e.deltaY < 0 /* scrolling up */ ? -1 : 1));
// Ignore event if the last one happened too recently.
// The restriction is relaxed according to the abs value of deltaX and deltaY

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The restriction is relaxed according to the abs value of deltaX and deltaY
// The restriction is relaxed according to the absolute value of `deltaX` and `deltaY`
// to support discrete (mouse wheel) and contiguous scrolling (touchpad) equally well

const nextEditor = this.group.getEditorByIndex(this.group.getIndexOfEditor(activeEditor) + (e.deltaX < 0 || e.deltaY < 0 /* scrolling up */ ? -1 : 1));
// Ignore event if the last one happened too recently.
// The restriction is relaxed according to the abs value of deltaX and deltaY
const time_threshold = 150;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest to extract this to a static constant below here

Comment on lines +353 to +358
if (e.deltaX + e.deltaY < - distance_threshold) {
tabSwitchDirection = -1;
}
if (e.deltaX + e.deltaY > distance_threshold) {
tabSwitchDirection = 1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (e.deltaX + e.deltaY < - distance_threshold) {
tabSwitchDirection = -1;
}
if (e.deltaX + e.deltaY > distance_threshold) {
tabSwitchDirection = 1;
}
if (e.deltaX + e.deltaY < - distance_threshold) {
tabSwitchDirection = -1;
} else if (e.deltaX + e.deltaY > distance_threshold) {
tabSwitchDirection = 1;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. For some reason I initially thought both conditions could be true, but that's obviously not the case.

this.lastMouseWheelEventTime = Date.now();

// Figure out scrolling direction (ignore direction if the scrolling is too subtile)
const distance_threshold = 1.5;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I personally prefer camel case names, i.e. distanceThreshold

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Me too. I've been using python too much recently... :-)

if (e.deltaX + e.deltaY > distance_threshold) {
tabSwitchDirection = 1;
}
const nextEditor = this.group.getEditorByIndex(this.group.getIndexOfEditor(activeEditor) + tabSwitchDirection);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could/should we return early from this method if we don't have a tabSwitchDirection? In other words, do we need the code to execute even if the same editor is going to be opened? I would prefer to ignore the work of opening an editor unless it really changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, we should return already if tabSwitchDirection is zero. I thought the if that checks if nextEditor is set was taking care of this, but it is not.

@Andre-Fonteles

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, Benjamin Pasero (@bpasero). I adopted all your suggestions.

@bpasero
Benjamin Pasero (bpasero) merged commit 768bcf4 into microsoft:master Dec 8, 2020
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trackpad: Tab switch on mouse scroll: horizontal scrolling sensitivity too high

3 participants