Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Touch and Mouse scroll #151

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/app/workspace/screen/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ScreenTabs extends React.Component<{ session: Session }, { showingScreens:
lastActiveScreenId: string = null;
dragEndTimeout = null;
scrollIntoViewTimeout = null;
deltaYHistory = [];

constructor(props: any) {
super(props);
Expand Down Expand Up @@ -79,24 +80,36 @@ class ScreenTabs extends React.Component<{ session: Session }, { showingScreens:
GlobalCommandRunner.switchScreen(screenId);
}

// @boundMethod
// handleWheel(event: WheelEvent) {
// if (!this.tabsRef.current) return;
@boundMethod
handleWheel(event: WheelEvent) {
if (!this.tabsRef.current) return;

// Add the current deltaY to the history
this.deltaYHistory.push(Math.abs(event.deltaY));
if (this.deltaYHistory.length > 5) {
this.deltaYHistory.shift(); // Keep only the last 5 entries
}

// // Prevent the default vertical scrolling
// event.preventDefault();
// Check if any of the last 5 deltaY values are greater than a threshold
let isMouseWheel = this.deltaYHistory.some((deltaY) => deltaY > 0);

// // Scroll horizontally instead
// this.tabsRef.current.scrollLeft += event.deltaY;
// }
if (isMouseWheel) {
// It's likely a mouse wheel event, so handle it for horizontal scrolling
this.tabsRef.current.scrollLeft += event.deltaY;

// Prevent default vertical scroll
event.preventDefault();
}
// For touchpad events, do nothing and let the browser handle it
}

componentDidMount(): void {
this.componentDidUpdate();

// // Add the wheel event listener to the tabsRef
// if (this.tabsRef.current) {
// this.tabsRef.current.addEventListener("wheel", this.handleWheel, { passive: false });
// }
// Add the wheel event listener to the tabsRef
if (this.tabsRef.current) {
this.tabsRef.current.addEventListener("wheel", this.handleWheel, { passive: false });
}
}

componentWillUnmount() {
Expand Down