mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 11:23:10 +02:00
Fix #5982 Behaviour of ctrl+r altered to support rotate on desktop, while the web version continue to use refresh as default.
This commit is contained in:
@@ -25,6 +25,7 @@ import type { PDFDict, PDFNumber } from '@cantoo/pdf-lib';
|
|||||||
import { useWheelZoom } from '@app/hooks/useWheelZoom';
|
import { useWheelZoom } from '@app/hooks/useWheelZoom';
|
||||||
import { useFormFill } from '@app/tools/formFill/FormFillContext';
|
import { useFormFill } from '@app/tools/formFill/FormFillContext';
|
||||||
import { FormSaveBar } from '@app/tools/formFill/FormSaveBar';
|
import { FormSaveBar } from '@app/tools/formFill/FormSaveBar';
|
||||||
|
import { useViewerKeyCommand } from '@app/hooks/useViewerKeyCommand';
|
||||||
|
|
||||||
// ─── Measure dictionary extraction ────────────────────────────────────────────
|
// ─── Measure dictionary extraction ────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -380,15 +381,19 @@ const EmbedPdfViewerContent = ({
|
|||||||
onZoomOut: zoomActions.zoomOut,
|
onZoomOut: zoomActions.zoomOut,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const viewerKeyCommand = useViewerKeyCommand();
|
||||||
|
|
||||||
// Handle keyboard shortcuts
|
// Handle keyboard shortcuts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
const mod = event.ctrlKey || event.metaKey;
|
const mod = event.ctrlKey || event.metaKey;
|
||||||
|
|
||||||
// Ctrl+P (print) and Ctrl+R (rotate) must be intercepted unconditionally
|
// Ctrl+P (print) must be intercepted unconditionally
|
||||||
// whenever the viewer is mounted, even before the user has hovered over it.
|
// whenever the viewer is mounted, even before the user has hovered over it.
|
||||||
|
// Ctrl+R (rotate) is intercepted only on desktop (Tauri), while on web it still falls through to browser refresh.
|
||||||
// Without this, the browser falls through to its native "print HTML page"
|
// Without this, the browser falls through to its native "print HTML page"
|
||||||
// or "reload page" behaviour.
|
// or "reload page" behaviour.
|
||||||
|
|
||||||
if (mod) {
|
if (mod) {
|
||||||
const target = event.target as Element;
|
const target = event.target as Element;
|
||||||
const isInTextInput =
|
const isInTextInput =
|
||||||
@@ -397,12 +402,15 @@ const EmbedPdfViewerContent = ({
|
|||||||
(target as HTMLElement).isContentEditable;
|
(target as HTMLElement).isContentEditable;
|
||||||
|
|
||||||
if (!isInTextInput) {
|
if (!isInTextInput) {
|
||||||
switch (event.key) {
|
const wasOverridden = viewerKeyCommand(event)
|
||||||
case 'p':
|
if (!wasOverridden){
|
||||||
case 'P':
|
switch (event.key) {
|
||||||
event.preventDefault();
|
case 'p':
|
||||||
printActions.print();
|
case 'P':
|
||||||
return;
|
event.preventDefault();
|
||||||
|
printActions.print();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -509,7 +517,7 @@ const EmbedPdfViewerContent = ({
|
|||||||
}, [
|
}, [
|
||||||
isViewerHovered, isSearchInterfaceVisible, zoomActions, searchInterfaceActions,
|
isViewerHovered, isSearchInterfaceVisible, zoomActions, searchInterfaceActions,
|
||||||
scrollActions, printActions, exportActions, rotationActions, historyApiRef,
|
scrollActions, printActions, exportActions, rotationActions, historyApiRef,
|
||||||
viewerApplyChanges, cyclePdfRenderMode,
|
viewerApplyChanges, cyclePdfRenderMode, viewerKeyCommand,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Watch the annotation history API to detect when the document becomes "dirty".
|
// Watch the annotation history API to detect when the document becomes "dirty".
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Default implementation for non-desktop environments (overridden in desktop)
|
||||||
|
export function useViewerKeyCommand(): (event: KeyboardEvent) => boolean {
|
||||||
|
return () => false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { useViewer } from "@app/contexts/ViewerContext"
|
||||||
|
import { useCallback } from "react";
|
||||||
|
|
||||||
|
export function useViewerKeyCommand(): (event: KeyboardEvent) => boolean {
|
||||||
|
const { rotationActions } = useViewer();
|
||||||
|
return useCallback((event:KeyboardEvent): boolean => {
|
||||||
|
switch (event.key) {
|
||||||
|
case 'r':
|
||||||
|
case 'R':
|
||||||
|
event.preventDefault();
|
||||||
|
if (event.shiftKey) {
|
||||||
|
rotationActions.rotateBackward();
|
||||||
|
} else {
|
||||||
|
rotationActions.rotateForward();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, [rotationActions]);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user