Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export const GLOBAL_HEADER_MENU_ID = '__GLOBAL_HEADER_MENU__';

export const GLOBAL_SIDER_MENU_ID = '__GLOBAL_SIDER_MENU__';

/** Wheel speed ratio for horizontal scrolling on the global tab bar. <1 slower, >1 faster */
export const GLOBAL_TAB_WHEEL_SPEED_RATIO = 0.3;

export const themeSchemaRecord: Record<UnionKey.ThemeScheme, App.I18n.I18nKey> = {
light: 'theme.appearance.themeSchema.light',
dark: 'theme.appearance.themeSchema.dark',
Expand Down
14 changes: 13 additions & 1 deletion src/layouts/modules/global-tab/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useAppStore } from '@/store/modules/app';
import { useThemeStore } from '@/store/modules/theme';
import { useTabStore } from '@/store/modules/tab';
import { isPC } from '@/utils/agent';
import { GLOBAL_TAB_WHEEL_SPEED_RATIO } from '@/constants/app';
import BetterScroll from '@/components/custom/better-scroll.vue';
import ContextMenu from './context-menu.vue';

Expand Down Expand Up @@ -71,6 +72,17 @@ function scrollByClientX(clientX: number) {
}
}

// Convert vertical wheel delta into horizontal tab scroll
function handleWheel(e: WheelEvent) {
const bs = bsScroll.value?.instance;
if (!bs) return;
// Do not intercept when there is no horizontal scroll space, keep native vertical scrolling
if (bs.maxScrollX === 0) return;
e.preventDefault();
// deltaY > 0 (scroll down) -> tabs slide left; deltaY < 0 (scroll up) -> tabs slide right
bs.scrollBy(-e.deltaY * GLOBAL_TAB_WHEEL_SPEED_RATIO, 0, 0);
}

function getContextMenuDisabledKeys(tabId: string) {
const disabledKeys: App.Global.DropdownKey[] = [];

Expand Down Expand Up @@ -186,7 +198,7 @@ init();

<template>
<DarkModeContainer class="size-full flex-y-center px-16px shadow-tab">
<div ref="bsWrapper" class="h-full flex-1-hidden">
<div ref="bsWrapper" class="h-full flex-1-hidden" @wheel="handleWheel">
<BetterScroll ref="bsScroll" :options="{ scrollX: true, scrollY: false, click: !isPCFlag }" @click="removeFocus">
<div
ref="tabRef"
Expand Down