Skip to content

Commit 50235bf

Browse files
authored
Merge pull request Gnathonic#201 from Gnathonic/feat/swap-wheel-behavior
feat: Add toggle to swap mouse wheel scroll/zoom behavior
2 parents 0bcd3e5 + 40516a9 commit 50235bf

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/lib/components/Settings/Reader/ReaderToggles.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
{ key: 'mobile', text: 'Mobile', value: $settings.mobile },
1919
{ key: 'showTimer', text: 'Show timer', value: $settings.showTimer },
2020
{ key: 'quickActions', text: 'Show quick actions', value: $settings.quickActions },
21+
{ key: 'swapWheelBehavior', text: 'Swap mouse wheel scroll/zoom', value: $settings.swapWheelBehavior },
2122
{ key: 'invertColors', text: 'Invert colors of the images', value: $settings.invertColors, shortcut: 'I' },
2223
{ key: 'nightMode', text: 'Night mode (strong red filter)', value: $settings.nightMode, shortcut: 'N' }
2324
] as { key: SettingsKey; text: string; value: any; shortcut?: string }[]);

src/lib/panzoom/util.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const sessionFullscreenState = writable<boolean | undefined>(undefined);
1414

1515
export function initPanzoom(node: HTMLElement) {
1616
container = node;
17+
1718
pz = panzoom(node, {
1819
bounds: false,
1920
maxZoom: 10,
@@ -29,7 +30,12 @@ export function initPanzoom(node: HTMLElement) {
2930
// This allows text selection within text boxes
3031
return isTextBox;
3132
},
32-
beforeWheel: (e) => !e.ctrlKey,
33+
// When swapWheelBehavior is true: zoom without modifier, scroll with Ctrl
34+
// When swapWheelBehavior is false (default): scroll without modifier, zoom with Ctrl
35+
beforeWheel: (e) => {
36+
const swapWheelBehavior = get(settings).swapWheelBehavior;
37+
return swapWheelBehavior ? e.ctrlKey : !e.ctrlKey;
38+
},
3339
onTouch: (e) => e.touches.length > 1,
3440
// Panzoom typing is wrong here
3541
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -49,14 +55,19 @@ export function initPanzoom(node: HTMLElement) {
4955
pz.on('pan', () => keepInBounds());
5056
pz.on('zoom', () => keepInBounds());
5157

52-
// Add custom wheel handler for panning when Ctrl is not pressed
58+
// Add custom wheel handler for panning/zooming based on swapWheelBehavior
5359
const wheelHandler = (e: WheelEvent) => {
54-
if (!e.ctrlKey && pz) {
55-
e.preventDefault();
56-
const { x, y } = pz.getTransform();
57-
// Pan vertically based on wheel deltaY
58-
pz.moveTo(x, y - e.deltaY);
59-
keepInBounds();
60+
if (pz) {
61+
const swapWheelBehavior = get(settings).swapWheelBehavior;
62+
const shouldPan = swapWheelBehavior ? e.ctrlKey : !e.ctrlKey;
63+
64+
if (shouldPan) {
65+
e.preventDefault();
66+
const { x, y } = pz.getTransform();
67+
// Pan vertically based on wheel deltaY
68+
pz.moveTo(x, y - e.deltaY);
69+
keepInBounds();
70+
}
6071
}
6172
};
6273

src/lib/settings/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type Settings = {
6969
invertColors: boolean;
7070
nightMode: boolean;
7171
inactivityTimeoutMinutes: number;
72+
swapWheelBehavior: boolean;
7273
volumeDefaults: VolumeDefaults;
7374
ankiConnectSettings: AnkiConnectSettings;
7475
lastUpdated?: string; // ISO 8601 timestamp for sync conflict resolution
@@ -102,6 +103,7 @@ const defaultSettings: Settings = {
102103
invertColors: false,
103104
nightMode: false,
104105
inactivityTimeoutMinutes: 5,
106+
swapWheelBehavior: false,
105107
volumeDefaults: {
106108
singlePageView: 'auto',
107109
rightToLeft: true,

0 commit comments

Comments
 (0)