Prevent default action on hotkey by default

This commit is contained in:
schroda
2025-11-16 22:32:18 +01:00
parent 64d5f3b8e1
commit d093fe0281

View File

@@ -33,7 +33,7 @@ import {
const useHotkeys = (...args: Parameters<typeof useHotKeysHook>): ReturnType<typeof useHotKeysHook> => { const useHotkeys = (...args: Parameters<typeof useHotKeysHook>): ReturnType<typeof useHotKeysHook> => {
const [keys, callback, options, dependencies] = args; const [keys, callback, options, dependencies] = args;
return useHotKeysHook(keys, callback, { ...options, ...HOTKEY_SCOPES.reader }, dependencies); return useHotKeysHook(keys, callback, { preventDefault: true, ...options, ...HOTKEY_SCOPES.reader }, dependencies);
}; };
const updateSettingCycleThrough = <Setting extends keyof IReaderSettings>( const updateSettingCycleThrough = <Setting extends keyof IReaderSettings>(
@@ -73,60 +73,52 @@ export const ReaderHotkeys = ({
useHotkeys(hotkeys[ReaderHotkey.PREVIOUS_PAGE], () => ReaderControls.openPage('previous')); useHotkeys(hotkeys[ReaderHotkey.PREVIOUS_PAGE], () => ReaderControls.openPage('previous'));
useHotkeys(hotkeys[ReaderHotkey.NEXT_PAGE], () => ReaderControls.openPage('next')); useHotkeys(hotkeys[ReaderHotkey.NEXT_PAGE], () => ReaderControls.openPage('next'));
useHotkeys( useHotkeys(hotkeys[ReaderHotkey.SCROLL_BACKWARD], () => {
hotkeys[ReaderHotkey.SCROLL_BACKWARD], const autoScroll = getReaderAutoScrollStore();
() => { const { readingMode, readingDirection, scrollAmount } = getReaderSettingsStore();
const autoScroll = getReaderAutoScrollStore();
const { readingMode, readingDirection, scrollAmount } = getReaderSettingsStore();
if (autoScroll.isActive) { if (autoScroll.isActive) {
autoScroll.setDirection(ScrollOffset.BACKWARD); autoScroll.setDirection(ScrollOffset.BACKWARD);
return; return;
} }
if (!scrollElementRef.current) { if (!scrollElementRef.current) {
return; return;
} }
ReaderControls.scroll( ReaderControls.scroll(
ScrollOffset.BACKWARD, ScrollOffset.BACKWARD,
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value], CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value],
readingMode.value, readingMode.value,
readingDirection.value, readingDirection.value,
scrollElementRef.current, scrollElementRef.current,
getReaderTapZoneStore().setShowPreview, getReaderTapZoneStore().setShowPreview,
scrollAmount, scrollAmount,
); );
}, });
{ preventDefault: true }, useHotkeys(hotkeys[ReaderHotkey.SCROLL_FORWARD], () => {
); const autoScroll = getReaderAutoScrollStore();
useHotkeys( const { readingMode, readingDirection, scrollAmount } = getReaderSettingsStore();
hotkeys[ReaderHotkey.SCROLL_FORWARD],
() => {
const autoScroll = getReaderAutoScrollStore();
const { readingMode, readingDirection, scrollAmount } = getReaderSettingsStore();
if (autoScroll.isActive) { if (autoScroll.isActive) {
autoScroll.setDirection(ScrollOffset.FORWARD); autoScroll.setDirection(ScrollOffset.FORWARD);
return; return;
} }
if (!scrollElementRef.current) { if (!scrollElementRef.current) {
return; return;
} }
ReaderControls.scroll( ReaderControls.scroll(
ScrollOffset.FORWARD, ScrollOffset.FORWARD,
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value], CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value],
readingMode.value, readingMode.value,
readingDirection.value, readingDirection.value,
scrollElementRef.current, scrollElementRef.current,
getReaderTapZoneStore().setShowPreview, getReaderTapZoneStore().setShowPreview,
scrollAmount, scrollAmount,
); );
}, });
{ preventDefault: true },
);
useHotkeys( useHotkeys(
hotkeys[ReaderHotkey.PREVIOUS_CHAPTER], hotkeys[ReaderHotkey.PREVIOUS_CHAPTER],
() => ReaderControls.openChapter(getOptionForDirection('previous', 'next', readerThemeDirection)), () => ReaderControls.openChapter(getOptionForDirection('previous', 'next', readerThemeDirection)),
@@ -180,9 +172,7 @@ export const ReaderHotkeys = ({
true, true,
); );
}); });
useHotkeys(hotkeys[ReaderHotkey.TOGGLE_AUTO_SCROLL], () => getReaderAutoScrollStore().toggleActive(), { useHotkeys(hotkeys[ReaderHotkey.TOGGLE_AUTO_SCROLL], () => getReaderAutoScrollStore().toggleActive(), {});
preventDefault: true,
});
useHotkeys(hotkeys[ReaderHotkey.AUTO_SCROLL_SPEED_DECREASE], () => useHotkeys(hotkeys[ReaderHotkey.AUTO_SCROLL_SPEED_DECREASE], () =>
ReaderService.updateSetting('autoScroll', { ReaderService.updateSetting('autoScroll', {
...getReaderSettingsStore().autoScroll, ...getReaderSettingsStore().autoScroll,