Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit e4af99b

Browse files
authored
Merge pull request #2059 from TriliumNext/tab-row
feat(tab-row): Added smooth decay logic
2 parents 64234ae + 7010472 commit e4af99b

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

apps/client/src/widgets/tab_row.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,45 @@ export default class TabRowWidget extends BasicWidget {
378378
}
379379

380380
scrollTabContainer(direction: number, behavior: ScrollBehavior = "smooth") {
381-
const currentScrollLeft = this.$tabScrollingContainer[0]?.scrollLeft;
382-
this.$tabScrollingContainer[0].scrollTo({
383-
left: currentScrollLeft + direction,
381+
this.$tabScrollingContainer[0].scrollBy({
382+
left: direction,
384383
behavior
385384
});
386385
};
387386

388387
setupScrollEvents() {
389-
this.$tabScrollingContainer[0].addEventListener('wheel', (event) => {
390-
this.scrollTabContainer(event.deltaY * 1.5);
388+
let deltaX = 0;
389+
let isScrolling = false;
390+
const stepScroll = () => {
391+
if (Math.abs(deltaX) > 5) {
392+
const step = Math.round(deltaX * 0.2);
393+
deltaX -= step;
394+
this.scrollTabContainer(step, "instant");
395+
requestAnimationFrame(stepScroll);
396+
} else {
397+
this.scrollTabContainer(deltaX, "instant");
398+
deltaX = 0;
399+
isScrolling = false;
400+
}
401+
};
402+
this.$tabScrollingContainer[0].addEventListener('wheel', async (event) => {
403+
if (!event.shiftKey && event.deltaX === 0) {
404+
event.preventDefault();
405+
// Clamp deltaX between TAB_CONTAINER_MIN_WIDTH and TAB_CONTAINER_MIN_WIDTH * 3
406+
deltaX += Math.sign(event.deltaY) * Math.max(Math.min(Math.abs(event.deltaY), TAB_CONTAINER_MIN_WIDTH * 3), TAB_CONTAINER_MIN_WIDTH);
407+
if (!isScrolling) {
408+
isScrolling = true;
409+
stepScroll();
410+
}
411+
} else if (event.shiftKey) {
412+
event.preventDefault();
413+
if (event.deltaY > 0) {
414+
await appContext.tabManager.activateNextTabCommand();
415+
} else {
416+
await appContext.tabManager.activatePreviousTabCommand();
417+
}
418+
this.activeTabEl.scrollIntoView();
419+
}
391420
});
392421

393422
this.$scrollButtonLeft[0].addEventListener('click', () => this.scrollTabContainer(-200));

0 commit comments

Comments
 (0)