mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-11-02 14:12:42 +08:00
fix(tab-row): Remove smooth scrolling
This commit is contained in:
parent
537ad1c1e5
commit
17885f6091
@ -385,41 +385,17 @@ export default class TabRowWidget extends BasicWidget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
setupScrollEvents() {
|
setupScrollEvents() {
|
||||||
let pendingScroll = 0;
|
this.$tabScrollingContainer.on('wheel', (event) => {
|
||||||
let isScrolling = false;
|
const wheelEvent = event.originalEvent as WheelEvent;
|
||||||
const stepScroll = () => {
|
|
||||||
if (Math.abs(pendingScroll) > 20) {
|
|
||||||
const step = Math.round(pendingScroll * 0.2);
|
|
||||||
pendingScroll -= step;
|
|
||||||
this.scrollTabContainer(step, "instant");
|
|
||||||
requestAnimationFrame(stepScroll);
|
|
||||||
} else {
|
|
||||||
this.scrollTabContainer(pendingScroll, "instant");
|
|
||||||
pendingScroll = 0;
|
|
||||||
isScrolling = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.$tabScrollingContainer[0].addEventListener('wheel', async (event) => {
|
|
||||||
if (utils.isCtrlKey(event) || event.altKey || event.shiftKey) {
|
if (utils.isCtrlKey(event) || event.altKey || event.shiftKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopImmediatePropagation();
|
|
||||||
|
|
||||||
// Set an upper limit to avoid scrolling too fast
|
const delta = Math.sign(wheelEvent.deltaX + wheelEvent.deltaY) *
|
||||||
// no lower limit is set because touchpad deltas are usually small
|
Math.min(Math.abs(wheelEvent.deltaX + wheelEvent.deltaY), TAB_CONTAINER_MIN_WIDTH * 2);
|
||||||
const delta = Math.sign(event.deltaX + event.deltaY) * Math.min(Math.abs(event.deltaX + event.deltaY), TAB_CONTAINER_MIN_WIDTH * 3);
|
|
||||||
|
|
||||||
// Check if the device has reduced motion enabled
|
this.scrollTabContainer(delta, "instant");
|
||||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
||||||
this.scrollTabContainer(delta, "instant");
|
|
||||||
} else {
|
|
||||||
pendingScroll += delta
|
|
||||||
if (!isScrolling) {
|
|
||||||
isScrolling = true;
|
|
||||||
stepScroll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$scrollButtonLeft[0].addEventListener('click', () => this.scrollTabContainer(-200));
|
this.$scrollButtonLeft[0].addEventListener('click', () => this.scrollTabContainer(-200));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user