Skip to content

Commit 92f50c4

Browse files
committed
frontend/latex/output: make pinch to zoom actually work for the embedded PDFJS
1 parent 1fc4cbc commit 92f50c4

File tree

1 file changed

+20
-13
lines changed
  • src/packages/frontend/frame-editors/latex-editor

1 file changed

+20
-13
lines changed

src/packages/frontend/frame-editors/latex-editor/pdfjs.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,19 @@ export function PDFJS({
9292

9393
const divRef = useRef<HTMLDivElement>(null);
9494

95-
// When zoom prop is provided, use onZoom callback to handle pinch gestures
96-
// Otherwise, let usePinchToZoom handle font_size directly
97-
const pinchToZoomConfig = zoom !== undefined && onZoom ? {
95+
// Configure pinch-to-zoom with appropriate settings
96+
const pinchToZoomConfig = {
9897
target: divRef,
99-
onZoom: (data) => {
100-
// Pass the pinch-to-zoom data directly to parent
101-
onZoom(data);
102-
},
103-
getFontSize: () => {
104-
// Convert current zoom back to fontSize for pinch calculations
105-
return zoom * 14;
106-
}
107-
} : {
108-
target: divRef
98+
onZoom: onZoom || ((data) => {
99+
// Default behavior: set font size directly when no parent callback provided
100+
actions.set_font_size(id, data.fontSize);
101+
}),
102+
...(zoom !== undefined ? {
103+
getFontSize: () => {
104+
// Convert current zoom back to fontSize for pinch calculations
105+
return zoom * 14;
106+
}
107+
} : {})
109108
};
110109

111110
usePinchToZoom(pinchToZoomConfig);
@@ -803,6 +802,14 @@ export function PDFJS({
803802
cursor,
804803
textAlign: "center",
805804
backgroundColor: !loaded ? "white" : BG_COL,
805+
// Disable browser's native touch behaviors to allow our pinch-to-zoom to work
806+
touchAction: "none",
807+
WebkitTouchCallout: "none",
808+
WebkitUserSelect: "none",
809+
KhtmlUserSelect: "none",
810+
MozUserSelect: "none",
811+
msUserSelect: "none",
812+
userSelect: "none",
806813
}}
807814
ref={divRef}
808815
onMouseDown={onMouseDown}

0 commit comments

Comments
 (0)