Skip to content

Commit

Permalink
fix: account for DSF when using wheelDeltaX and wheelDeltaY values (#…
Browse files Browse the repository at this point in the history
…200776)

* fix: account for DSF when using wheelDeltaX and wheelDeltaY values

* chore: address review feedback

* fix: address review feedback
  • Loading branch information
deepak1556 authored Jan 12, 2024
1 parent 18b6920 commit 4f338c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/vs/base/browser/mouseEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,16 @@ export class StandardWheelEvent {
// Old (deprecated) wheel events
const e1 = <IWebKitMouseWheelEvent><any>e;
const e2 = <IGeckoMouseWheelEvent><any>e;
const devicePixelRatio = e.view?.devicePixelRatio || 1;

// vertical delta scroll
if (typeof e1.wheelDeltaY !== 'undefined') {
this.deltaY = e1.wheelDeltaY / 120;
if (browser.isChrome) {
// Refs https://github.com/microsoft/vscode/issues/146403#issuecomment-1854538928
this.deltaY = e1.wheelDeltaY / (120 * devicePixelRatio);
} else {
this.deltaY = e1.wheelDeltaY / 120;
}
} else if (typeof e2.VERTICAL_AXIS !== 'undefined' && e2.axis === e2.VERTICAL_AXIS) {
this.deltaY = -e2.detail / 3;
} else if (e.type === 'wheel') {
Expand All @@ -167,6 +173,9 @@ export class StandardWheelEvent {
if (typeof e1.wheelDeltaX !== 'undefined') {
if (browser.isSafari && platform.isWindows) {
this.deltaX = - (e1.wheelDeltaX / 120);
} else if (browser.isChrome) {
// Refs https://github.com/microsoft/vscode/issues/146403#issuecomment-1854538928
this.deltaX = e1.wheelDeltaX / (120 * devicePixelRatio);
} else {
this.deltaX = e1.wheelDeltaX / 120;
}
Expand All @@ -191,7 +200,12 @@ export class StandardWheelEvent {

// Assume a vertical scroll if nothing else worked
if (this.deltaY === 0 && this.deltaX === 0 && e.wheelDelta) {
this.deltaY = e.wheelDelta / 120;
if (browser.isChrome) {
// Refs https://github.com/microsoft/vscode/issues/146403#issuecomment-1854538928
this.deltaY = e.wheelDelta / (120 * devicePixelRatio);
} else {
this.deltaY = e.wheelDelta / 120;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { IDisposable } from 'vs/base/common/lifecycle';
import type * as webviewMessages from 'vs/workbench/contrib/notebook/browser/view/renderers/webviewMessages';
import type { NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import type * as rendererApi from 'vscode-notebook-renderer';
import * as browser from 'vs/base/browser/browser';

// !! IMPORTANT !! ----------------------------------------------------------------------------------
// import { RenderOutputType } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
Expand Down Expand Up @@ -482,9 +483,10 @@ async function webviewPreloads(ctx: PreloadContext) {
deltaX: event.deltaX,
deltaY: event.deltaY,
deltaZ: event.deltaZ,
wheelDelta: event.wheelDelta,
wheelDeltaX: event.wheelDeltaX,
wheelDeltaY: event.wheelDeltaY,
// Refs https://github.com/microsoft/vscode/issues/146403#issuecomment-1854538928
wheelDelta: event.wheelDelta && browser.isChrome ? (event.wheelDelta / $window.devicePixelRatio) : event.wheelDelta,
wheelDeltaX: event.wheelDeltaX && browser.isChrome ? (event.wheelDeltaX / $window.devicePixelRatio) : event.wheelDeltaX,
wheelDeltaY: event.wheelDeltaY && browser.isChrome ? (event.wheelDeltaY / $window.devicePixelRatio) : event.wheelDeltaY,
detail: event.detail,
shiftKey: event.shiftKey,
type: event.type
Expand Down

0 comments on commit 4f338c8

Please sign in to comment.