From 9e10814840067d97581402be8ae1b0f267548597 Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Mon, 12 Jun 2023 21:36:24 +0100 Subject: [PATCH] Patch 1 (#278) * Touch support for split view * Attempting to make TS happy * Making typescript happy round two https://stackoverflow.com/questions/54688147/react-typescript-event-type-for-both-interfaces-mouseevent-and-touchevent * make TS Happy * Update splitview.ts --------- Co-authored-by: Ray Foss --- .../dockview-core/src/splitview/splitview.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/dockview-core/src/splitview/splitview.ts b/packages/dockview-core/src/splitview/splitview.ts index fd68a4a29..a39c989e3 100644 --- a/packages/dockview-core/src/splitview/splitview.ts +++ b/packages/dockview-core/src/splitview/splitview.ts @@ -393,7 +393,8 @@ export class Splitview { const sash = document.createElement('div'); sash.className = 'sash'; - const onStart = (event: MouseEvent) => { + const onStart = (nativeEvent: MouseEvent | TouchEvent) => { + const event = nativeEvent instanceof TouchEvent ? nativeEvent.touches[0] : nativeEvent; for (const item of this.viewItems) { item.enabled = false; } @@ -488,11 +489,12 @@ export class Splitview { } // - const mousemove = (mousemoveEvent: MouseEvent) => { + const mousemove = (nativeMoveEvent: MouseEvent | TouchEvent) => { + const moveEvent = nativeMoveEvent instanceof TouchEvent ? nativeMoveEvent.touches[0] : nativeMoveEvent; const current = this._orientation === Orientation.HORIZONTAL - ? mousemoveEvent.clientX - : mousemoveEvent.clientY; + ? moveEvent.clientX + : moveEvent.clientY; const delta = current - start; this.resize( @@ -523,15 +525,24 @@ export class Splitview { document.removeEventListener('mousemove', mousemove); document.removeEventListener('mouseup', end); + document.removeEventListener("touchmove", mousemove); + document.removeEventListener("touchend", end); + document.removeEventListener("touchcancel", end); this._onDidSashEnd.fire(undefined); + return true // Consume, otherwise Monaco complains }; document.addEventListener('mousemove', mousemove); document.addEventListener('mouseup', end); + document.addEventListener("touchmove", mousemove); + document.addEventListener("touchend", end); + document.addEventListener("touchcancel", end); + return true // consume pull to refresh gesture }; sash.addEventListener('mousedown', onStart); + sash.addEventListener("touchstart", onStart); const sashItem: ISashItem = { container: sash,