Skip to content

Commit

Permalink
fix: scroll threshold logic fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Palanikannan1437 committed Dec 23, 2024
1 parent c28d35a commit 065c5d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/editor/src/core/extensions/side-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const SideMenuExtension = (props: Props) => {
ai: aiEnabled,
dragDrop: dragDropEnabled,
},
scrollThreshold: { up: 250, down: 150 },
scrollThreshold: { up: 200, down: 150 },
}),
];
},
Expand Down
16 changes: 7 additions & 9 deletions packages/editor/src/core/plugins/drag-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ const generalSelectors = [
".editor-callout-component",
].join(", ");

const maxScrollSpeed = 10;
const acceleration = 0.2;
const scrollDivisor = 1;
const maxScrollSpeed = 20;
const acceleration = 0.5;

const scrollParentCache = new WeakMap();

Expand Down Expand Up @@ -169,9 +168,8 @@ export const DragHandlePlugin = (options: SideMenuPluginProps): SideMenuHandleOp
const scrollableParent = getScrollParent(dragHandleElement);
if (!scrollableParent) return;

const scrollThreshold = Math.min(100, scrollableParent.clientHeight * 0.15);
const scrollRegionUp = scrollThreshold;
const scrollRegionDown = window.innerHeight - scrollThreshold;
const scrollRegionUp = options.scrollThreshold.up;
const scrollRegionDown = window.innerHeight - options.scrollThreshold.down;

let targetScrollAmount = 0;

Expand All @@ -180,17 +178,17 @@ export const DragHandlePlugin = (options: SideMenuPluginProps): SideMenuHandleOp
} else if (isDraggedOutsideWindow === "bottom") {
targetScrollAmount = maxScrollSpeed * 5;
} else if (lastClientY < scrollRegionUp) {
const ratio = easeOutQuadAnimation((scrollRegionUp - lastClientY) / scrollThreshold);
const ratio = easeOutQuadAnimation((scrollRegionUp - lastClientY) / options.scrollThreshold.up);
targetScrollAmount = -maxScrollSpeed * ratio;
} else if (lastClientY > scrollRegionDown) {
const ratio = easeOutQuadAnimation((lastClientY - scrollRegionDown) / scrollThreshold);
const ratio = easeOutQuadAnimation((lastClientY - scrollRegionDown) / options.scrollThreshold.down);
targetScrollAmount = maxScrollSpeed * ratio;
}

currentScrollSpeed += (targetScrollAmount - currentScrollSpeed) * acceleration;

if (Math.abs(currentScrollSpeed) > 0.1) {
scrollableParent.scrollBy({ top: currentScrollSpeed / scrollDivisor });
scrollableParent.scrollBy({ top: currentScrollSpeed });
}

scrollAnimationFrame = requestAnimationFrame(scroll);
Expand Down

0 comments on commit 065c5d2

Please sign in to comment.