From d3b3ff3d2b367f12a28e9c2e11884d86f8132d2e Mon Sep 17 00:00:00 2001 From: Danil B Date: Sun, 9 Oct 2022 22:28:40 +0300 Subject: [PATCH 1/3] add wheelReverseAxis flag --- src/plugins/Drag.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugins/Drag.ts b/src/plugins/Drag.ts index fb71fff2..efc501b5 100644 --- a/src/plugins/Drag.ts +++ b/src/plugins/Drag.ts @@ -95,6 +95,13 @@ export interface IDragOptions { * @default 20 */ lineHeight?: number; + + /** + * Swap x and y axes when scrolling. + * + * @default false + */ + wheelReverseAxis?: boolean; } const DEFAULT_DRAG_OPTIONS: Required = { @@ -110,6 +117,7 @@ const DEFAULT_DRAG_OPTIONS: Required = { keyToPress: null, ignoreKeyToPressOnTouch: false, lineHeight: 20, + wheelReverseAxis: false, }; /** @@ -421,13 +429,16 @@ export class Drag extends Plugin { const step = event.deltaMode ? this.options.lineHeight : 1; + const deltas = [event.deltaX, event.deltaY]; + const [deltaX, deltaY] = this.options.wheelReverseAxis ? deltas.reverse() : deltas; + if (this.xDirection) { - this.parent.x += event.deltaX * step * this.options.wheelScroll * this.reverse; + this.parent.x += deltaX * step * this.options.wheelScroll * this.reverse; } if (this.yDirection) { - this.parent.y += event.deltaY * step * this.options.wheelScroll * this.reverse; + this.parent.y += deltaY * step * this.options.wheelScroll * this.reverse; } if (this.options.clampWheel) { @@ -521,3 +532,4 @@ export class Drag extends Plugin } } } + From b476688a055db3ce2a55cb79c3234b68b7d4d4f0 Mon Sep 17 00:00:00 2001 From: Danil B Date: Sun, 9 Oct 2022 22:30:22 +0300 Subject: [PATCH 2/3] fix newlines --- src/plugins/Drag.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/Drag.ts b/src/plugins/Drag.ts index efc501b5..5a80c133 100644 --- a/src/plugins/Drag.ts +++ b/src/plugins/Drag.ts @@ -532,4 +532,3 @@ export class Drag extends Plugin } } } - From 419331d94999431c84c1bb1f78d43ee0fec0f10a Mon Sep 17 00:00:00 2001 From: Danil B <61459199+blnvdanil@users.noreply.github.com> Date: Mon, 10 Oct 2022 12:01:16 +0300 Subject: [PATCH 3/3] More descriptive name for flag --- src/plugins/Drag.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/Drag.ts b/src/plugins/Drag.ts index 5a80c133..9f48ca73 100644 --- a/src/plugins/Drag.ts +++ b/src/plugins/Drag.ts @@ -101,7 +101,7 @@ export interface IDragOptions { * * @default false */ - wheelReverseAxis?: boolean; + wheelSwapAxes?: boolean; } const DEFAULT_DRAG_OPTIONS: Required = { @@ -117,7 +117,7 @@ const DEFAULT_DRAG_OPTIONS: Required = { keyToPress: null, ignoreKeyToPressOnTouch: false, lineHeight: 20, - wheelReverseAxis: false, + wheelSwapAxes: false, }; /** @@ -430,7 +430,7 @@ export class Drag extends Plugin const step = event.deltaMode ? this.options.lineHeight : 1; const deltas = [event.deltaX, event.deltaY]; - const [deltaX, deltaY] = this.options.wheelReverseAxis ? deltas.reverse() : deltas; + const [deltaX, deltaY] = this.options.wheelSwapAxes ? deltas.reverse() : deltas; if (this.xDirection) {