Add "increase/decrease auto scroll speed" hotkeys

This commit is contained in:
schroda
2024-12-29 22:24:59 +01:00
parent 3238103ca0
commit d90767c71c
5 changed files with 36 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import { IReaderSettings, ReaderHotkey } from '@/modules/reader/types/Reader.typ
import { useReaderOverlayContext } from '@/modules/reader/contexts/ReaderOverlayContext.tsx';
import { getNextRotationValue } from '@/modules/core/utils/ValueRotationButton.utils.ts';
import {
AUTO_SCROLL_SPEED,
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION,
READER_PAGE_SCALE_MODE_VALUES,
ReaderScrollAmount,
@@ -69,8 +70,15 @@ export const ReaderHotkeys = ({
const { enableScope, disableScope } = useHotkeysContext();
const { manga } = useReaderStateMangaContext();
const { isVisible, setIsVisible: setIsOverlayVisible } = useReaderOverlayContext();
const { hotkeys, pageScaleMode, shouldStretchPage, shouldOffsetDoubleSpreads, readingMode, readingDirection } =
ReaderService.useSettings();
const {
hotkeys,
pageScaleMode,
shouldStretchPage,
shouldOffsetDoubleSpreads,
readingMode,
readingDirection,
autoScroll,
} = ReaderService.useSettings();
const automaticScrolling = useReaderAutoScrollContext();
const openChapter = ReaderControls.useOpenChapter();
@@ -184,9 +192,26 @@ export const ReaderHotkeys = ({
[updateSetting, deleteSetting, readingDirection.value, readingDirection.isDefault],
);
useHotkeys(hotkeys[ReaderHotkey.TOGGLE_AUTO_SCROLL], automaticScrolling.toggleActive, { preventDefault: true }, [
updateSetting,
automaticScrolling.toggleActive,
]);
useHotkeys(
hotkeys[ReaderHotkey.AUTO_SCROLL_SPEED_INCREASE],
() =>
updateSetting('autoScroll', {
...autoScroll,
value: Math.min(AUTO_SCROLL_SPEED.max, autoScroll.value + AUTO_SCROLL_SPEED.step),
}),
[updateSetting, autoScroll.value],
);
useHotkeys(
hotkeys[ReaderHotkey.AUTO_SCROLL_SPEED_DECREASE],
() =>
updateSetting('autoScroll', {
...autoScroll,
value: Math.max(AUTO_SCROLL_SPEED.min, autoScroll.value - AUTO_SCROLL_SPEED.step),
}),
[updateSetting, autoScroll.value],
);
useEffect(() => {
enableScope(HotkeyScope.READER);

View File

@@ -34,6 +34,8 @@ const READER_HOTKEY_TO_TITLE: Record<ReaderHotkey, TranslationKey> = {
[ReaderHotkey.CYCLE_READING_MODE]: 'reader.settings.hotkey.reading_mode',
[ReaderHotkey.CYCLE_READING_DIRECTION]: 'reader.settings.hotkey.reading_direction',
[ReaderHotkey.TOGGLE_AUTO_SCROLL]: 'reader.settings.hotkey.auto_scroll',
[ReaderHotkey.AUTO_SCROLL_SPEED_INCREASE]: 'reader.settings.hotkey.auto_scroll_speed_increase',
[ReaderHotkey.AUTO_SCROLL_SPEED_DECREASE]: 'reader.settings.hotkey.auto_scroll_speed_decrease',
};
export const ReaderSettingHotkey = ({

View File

@@ -124,6 +124,8 @@ export const DEFAULT_READER_SETTINGS: IReaderSettings = {
[ReaderHotkey.CYCLE_READING_MODE]: ['r'],
[ReaderHotkey.CYCLE_READING_DIRECTION]: ['t'],
[ReaderHotkey.TOGGLE_AUTO_SCROLL]: ['space'],
[ReaderHotkey.AUTO_SCROLL_SPEED_INCREASE]: ['b'],
[ReaderHotkey.AUTO_SCROLL_SPEED_DECREASE]: ['v'],
},
imagePreLoadAmount: 5,
shouldUseAutoWebtoonMode: true,

View File

@@ -217,6 +217,8 @@ export enum ReaderHotkey {
CYCLE_READING_MODE,
CYCLE_READING_DIRECTION,
TOGGLE_AUTO_SCROLL,
AUTO_SCROLL_SPEED_INCREASE,
AUTO_SCROLL_SPEED_DECREASE,
}
export interface ReaderPagerProps