mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-04-06 03:19:39 +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 { useFormFill } from '@app/tools/formFill/FormFillContext';
|
||||
import { FormSaveBar } from '@app/tools/formFill/FormSaveBar';
|
||||
import { useViewerKeyCommand } from '@app/hooks/useViewerKeyCommand';
|
||||
|
||||
// ─── Measure dictionary extraction ────────────────────────────────────────────
|
||||
|
||||
@@ -380,15 +381,19 @@ const EmbedPdfViewerContent = ({
|
||||
onZoomOut: zoomActions.zoomOut,
|
||||
});
|
||||
|
||||
const viewerKeyCommand = useViewerKeyCommand();
|
||||
|
||||
// Handle keyboard shortcuts
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
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.
|
||||
// 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"
|
||||
// or "reload page" behaviour.
|
||||
|
||||
if (mod) {
|
||||
const target = event.target as Element;
|
||||
const isInTextInput =
|
||||
@@ -397,12 +402,15 @@ const EmbedPdfViewerContent = ({
|
||||
(target as HTMLElement).isContentEditable;
|
||||
|
||||
if (!isInTextInput) {
|
||||
switch (event.key) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
event.preventDefault();
|
||||
printActions.print();
|
||||
return;
|
||||
const wasOverridden = viewerKeyCommand(event)
|
||||
if (!wasOverridden){
|
||||
switch (event.key) {
|
||||
case 'p':
|
||||
case 'P':
|
||||
event.preventDefault();
|
||||
printActions.print();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -509,7 +517,7 @@ const EmbedPdfViewerContent = ({
|
||||
}, [
|
||||
isViewerHovered, isSearchInterfaceVisible, zoomActions, searchInterfaceActions,
|
||||
scrollActions, printActions, exportActions, rotationActions, historyApiRef,
|
||||
viewerApplyChanges, cyclePdfRenderMode,
|
||||
viewerApplyChanges, cyclePdfRenderMode, viewerKeyCommand,
|
||||
]);
|
||||
|
||||
// Watch the annotation history API to detect when the document becomes "dirty".
|
||||
|
||||
4
frontend/src/core/hooks/useViewerKeyCommand.ts
Normal file
4
frontend/src/core/hooks/useViewerKeyCommand.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// Default implementation for non-desktop environments (overridden in desktop)
|
||||
export function useViewerKeyCommand(): (event: KeyboardEvent) => boolean {
|
||||
return () => false;
|
||||
}
|
||||
20
frontend/src/desktop/hooks/useViewerKeyCommand.ts
Normal file
20
frontend/src/desktop/hooks/useViewerKeyCommand.ts
Normal file
@@ -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