Repository navigation
Fixed tab switching too fast when wheeling/scrolling - #112034
Benjamin Pasero (bpasero) merged 3 commits into
Conversation
Benjamin Pasero (bpasero)
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
| 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 |
There was a problem hiding this comment.
| // 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; |
There was a problem hiding this comment.
I suggest to extract this to a static constant below here
| if (e.deltaX + e.deltaY < - distance_threshold) { | ||
| tabSwitchDirection = -1; | ||
| } | ||
| if (e.deltaX + e.deltaY > distance_threshold) { | ||
| tabSwitchDirection = 1; | ||
| } |
There was a problem hiding this comment.
| 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; | |
| } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
I personally prefer camel case names, i.e. distanceThreshold
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Thanks for the feedback, Benjamin Pasero (@bpasero). I adopted all your suggestions. |
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).