File tree Expand file tree Collapse file tree 4 files changed +23
-22
lines changed
src/packages/frontend/frame-editors/latex-editor Expand file tree Collapse file tree 4 files changed +23
-22
lines changed Original file line number Diff line number Diff line change @@ -111,12 +111,8 @@ export default function CanvasPage({
111
111
clickAnnotation = { clickAnnotation }
112
112
syncHighlight = { syncHighlight }
113
113
/>
114
- < TextLayer
115
- page = { page }
116
- scale = { scale }
117
- viewport = { viewport }
118
- />
119
114
< div ref = { divRef } />
115
+ < TextLayer page = { page } scale = { scale } viewport = { viewport } />
120
116
</ div >
121
117
) ;
122
118
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.
3
+ * License: MS-RSL – see LICENSE.md for details
4
+ */
5
+
1
6
/* See https://github.com/mozilla/pdf.js/blob/a7e1bf64c4c7a42c7577ce9490054faa1c4eda99/test/text_layer_test.css */
2
7
3
8
.cocalc-pdfjs-text-layer {
7
12
opacity : 1 ;
8
13
9
14
: is (span , br ) {
10
- color : black ;
15
+ color : transparent ;
11
16
position : absolute;
12
17
white-space : pre;
13
18
transform-origin : 0% 0% ;
14
- border : solid 1px rgb (255 0 0 / 0.5 );
15
- background-color : rgb (255 255 32 / 0.1 );
16
19
box-sizing : border-box;
20
+ cursor : text;
17
21
}
18
22
19
23
.markedContent {
Original file line number Diff line number Diff line change 1
1
/*
2
- * This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
2
+ * This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.
3
3
* License: MS-RSL – see LICENSE.md for details
4
4
*/
5
5
@@ -8,16 +8,11 @@ Render the text layer on top of a page to support selection.
8
8
9
9
How the hell did I figure this code out? First, there is nightmare of misleading and
10
10
useless outdated google hits from the last 10+ years. Finally, searching the
11
- pdfjs git repo yielded this, which was helpful, which is I guess how this is
12
- implemented for their own viewer:
13
-
11
+ pdfjs git repo yielded a complicated trail and I eventually figured out what pdfjs's
12
+ own complete renderer does (we can't use it since we need integration with the latex
13
+ editor, etc.):
14
14
15
15
https://github.com/mozilla/pdf.js/blob/a7e1bf64c4c7a42c7577ce9490054faa1c4eda99/web/text_layer_builder.js#L40
16
-
17
-
18
- This wasn't helpful:
19
-
20
- https://github.com/mozilla/pdf.js/blob/a7e1bf64c4c7a42c7577ce9490054faa1c4eda99/examples/text-only/pdf2svg.mjs#L24
21
16
*/
22
17
23
18
import type { PDFPageProxy } from "pdfjs-dist/webpack.mjs" ;
@@ -34,10 +29,6 @@ interface Props {
34
29
export default function PdfjsTextLayer ( { page, scale, viewport } : Props ) {
35
30
const divRef = useRef < HTMLDivElement | null > ( null ) ;
36
31
37
- // useEffect(() => {
38
- // (async () => setTextContent(await page.getTextContent()))();
39
- // }, [page]);
40
-
41
32
useEffect ( ( ) => {
42
33
const elt = divRef . current ;
43
34
if ( ! elt ) {
Original file line number Diff line number Diff line change @@ -582,12 +582,22 @@ export function PDFJS({
582
582
const lastMousePosRef = useRef < null | { x : number ; y : number } > ( null ) ;
583
583
584
584
const onMouseDown = useCallback ( ( e ) => {
585
+ if ( e . target ?. nodeName == "SPAN" ) {
586
+ // selection layer text -- allows for selecting instead of dragging around
587
+ return ;
588
+ }
585
589
lastMousePosRef . current = getClientPos ( e ) ;
586
590
setCursor ( "grabbing" ) ;
587
591
} , [ ] ) ;
588
592
589
593
const onMouseMove = useCallback ( ( e ) => {
590
- if ( ! e . buttons || lastMousePosRef . current == null ) return ;
594
+ if (
595
+ ! e . buttons ||
596
+ lastMousePosRef . current == null ||
597
+ ! window . getSelection ( ) ?. isCollapsed
598
+ ) {
599
+ return ;
600
+ }
591
601
const { x, y } = getClientPos ( e ) ;
592
602
const deltaX = lastMousePosRef . current . x - x ;
593
603
const deltaY = lastMousePosRef . current . y - y ;
You can’t perform that action at this time.
0 commit comments