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

Commit 17c2ae1

Browse files
authored
Merge pull request #2177 from TriliumNext/tab-row-scroll
fix(tab-row): ensure similar behavior between horizontal/vertical scrolling
2 parents 497a851 + 17885f6 commit 17c2ae1

1 file changed

Lines changed: 15 additions & 35 deletions

File tree

apps/client/src/widgets/tab_row.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -385,38 +385,17 @@ export default class TabRowWidget extends BasicWidget {
385385
};
386386

387387
setupScrollEvents() {
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();
388+
this.$tabScrollingContainer.on('wheel', (event) => {
389+
const wheelEvent = event.originalEvent as WheelEvent;
390+
if (utils.isCtrlKey(event) || event.altKey || event.shiftKey) {
391+
return;
419392
}
393+
event.preventDefault();
394+
395+
const delta = Math.sign(wheelEvent.deltaX + wheelEvent.deltaY) *
396+
Math.min(Math.abs(wheelEvent.deltaX + wheelEvent.deltaY), TAB_CONTAINER_MIN_WIDTH * 2);
397+
398+
this.scrollTabContainer(delta, "instant");
420399
});
421400

422401
this.$scrollButtonLeft[0].addEventListener('click', () => this.scrollTabContainer(-200));
@@ -485,8 +464,9 @@ export default class TabRowWidget extends BasicWidget {
485464
// this.$newTab may include margin, and using NEW_TAB_WIDTH could cause tabsContainerWidth to be slightly larger,
486465
// resulting in misaligned scrollbars/buttons. Therefore, use outerwidth.
487466
this.updateOuterWidth();
488-
let tabsContainerWidth = Math.floor(this.$widget.width() ?? 0);
489-
tabsContainerWidth -= this.newTabOuterWidth + MIN_FILLER_WIDTH;
467+
let tabsContainerWidth = Math.floor(
468+
(this.$widget.width() ?? 0) - this.newTabOuterWidth - MIN_FILLER_WIDTH
469+
);
490470
// Check whether the scroll buttons need to be displayed.
491471
if ((TAB_CONTAINER_MIN_WIDTH + MARGIN_WIDTH) * numberOfTabs > tabsContainerWidth) {
492472
tabsContainerWidth -= this.scrollButtonsOuterWidth;
@@ -506,11 +486,11 @@ export default class TabRowWidget extends BasicWidget {
506486
let extraWidthRemaining = totalExtraWidthDueToFlooring;
507487

508488
for (let i = 0; i < numberOfTabs; i += 1) {
509-
const extraWidth = flooredClampedTargetWidth < TAB_CONTAINER_MAX_WIDTH && extraWidthRemaining > 0 ? 1 : 0;
489+
const extraWidth = flooredClampedTargetWidth < TAB_CONTAINER_MAX_WIDTH && extraWidthRemaining >= 1 ? 1 : 0;
510490

511491
widths.push(flooredClampedTargetWidth + extraWidth);
512492

513-
if (extraWidthRemaining > 0) {
493+
if (extraWidthRemaining >= 1) {
514494
extraWidthRemaining -= 1;
515495
}
516496
}

0 commit comments

Comments
 (0)