Temporary fix to disable Back button navigation

This commit is contained in:
chrox
2024-11-03 12:14:44 +01:00
parent 82ff1b878e
commit b6b3bcee57
2 changed files with 17 additions and 1 deletions
@@ -48,6 +48,9 @@ const FoliateViewer: React.FC<{
};
const handleKeydown = (event: KeyboardEvent) => {
if (event.key === 'Backspace') {
event.preventDefault();
}
window.postMessage(
{
type: 'iframe-keydown',
@@ -82,9 +85,12 @@ const FoliateViewer: React.FC<{
const detail = (event as CustomEvent).detail;
if (detail.doc) {
if (!detail.doc.isEventListenersAdded) {
detail.doc.isEventListenersAdded = true;
detail.doc.addEventListener('keydown', handleKeydown);
detail.doc.addEventListener('mousedown', handleMousedown);
detail.doc.isEventListenersAdded = true;
detail.doc.addEventListener('contextmenu', (e: MouseEvent) => {
e.preventDefault();
});
}
}
};
@@ -13,6 +13,14 @@ interface KeyActionHandlers {
const useShortcuts = (actions: KeyActionHandlers, dependencies: React.DependencyList = []) => {
const [shortcuts, setShortcuts] = useState<ShortcutConfig>(loadShortcuts);
useEffect(() => {
if (process.env.NODE_ENV !== 'development') {
document.addEventListener('contextmenu', (event) => {
event.preventDefault();
});
}
}, []);
useEffect(() => {
const handleShortcutUpdate = () => {
setShortcuts(loadShortcuts());
@@ -58,6 +66,8 @@ const useShortcuts = (actions: KeyActionHandlers, dependencies: React.Dependency
metaKey: boolean,
shiftKey: boolean,
) => {
// FIXME: This is a temporary fix to disable Back button navigation
if (key === 'backspace') return true;
if (
shortcuts.switchSidebar.some((shortcut) =>
isShortcutMatch(shortcut, key, ctrlKey, altKey, metaKey, shiftKey),