-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(whiteboard): scroll bug on the edge (#1561)
* fix(whiteboard): scroll bug on the edge * refactor(whiteboard): improve scroll mode behaviors * refactor scroll * upgrade window-manager, fix replay error
- Loading branch information
Showing
9 changed files
with
125 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import type { AnimationMode, WindowManager } from "@netless/window-manager"; | ||
import type { FastboardApp } from "@netless/fastboard-react"; | ||
import type { AnimationMode } from "@netless/window-manager"; | ||
|
||
// Let mouse wheel act as scrolling the whiteboard | ||
export function mousewheelToScroll(root: HTMLElement, manager: WindowManager): () => void { | ||
export function mousewheelToScroll(root: HTMLElement, fastboard: FastboardApp): () => void { | ||
const $whiteboard = root.querySelector(".netless-window-manager-main-view") as HTMLDivElement; | ||
if (!$whiteboard) { | ||
throw new Error("Not found .netless-window-manager-main-view"); | ||
} | ||
const listener = (ev: Event): void => { | ||
ev.preventDefault(); | ||
ev.stopPropagation(); | ||
const dy = (ev as WheelEvent).deltaY || 0; | ||
manager.moveCamera({ | ||
centerY: manager.camera.centerY + dy * manager.camera.scale, | ||
animationMode: "immediately" as AnimationMode.Immediately, | ||
}); | ||
if (fastboard.writable.value) { | ||
fastboard.manager.moveCamera({ | ||
centerY: clamp( | ||
fastboard.manager.camera.centerY + dy * fastboard.manager.camera.scale, | ||
-950, | ||
950, | ||
), | ||
animationMode: "immediately" as AnimationMode.Immediately, | ||
}); | ||
} | ||
}; | ||
root.addEventListener("wheel", listener, true); | ||
return () => root.removeEventListener("wheel", listener, true); | ||
$whiteboard.addEventListener("wheel", listener, true); | ||
return () => $whiteboard.removeEventListener("wheel", listener, true); | ||
} | ||
|
||
function clamp(x: number, min: number, max: number): number { | ||
return x < min ? min : x > max ? max : x; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.