Skip to content

Commit

Permalink
fix(copy-paste-issue): PDFJS copy paste fix (#1489)
Browse files Browse the repository at this point in the history
* fix(copy-paste-issue): Fix Copy Paste issue for pdfs

* fix(copy-paste-issue): Fix test

* fix(copy-paste-issue): Add comments to test

* fix(copy-paste-issue): noop
  • Loading branch information
JChan106 authored Jul 21, 2023
1 parent f937052 commit 9625e46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const PAGES_UNIT_NAME = 'pages';
const PDFJS_TEXT_LAYER_MODE = {
DISABLE: 0, // Should match TextLayerMode enum in pdf_viewer.js
ENABLE: 1,
ENABLE_ENHANCE: 2,
ENABLE_PERMISSIONS: 2,
};
const PINCH_PAGE_CLASS = 'pinch-page';
const PINCHING_CLASS = 'pinching';
Expand Down Expand Up @@ -796,7 +796,6 @@ class DocBaseViewer extends BaseViewer {
const assetUrlCreator = createAssetUrlCreator(location);
const hasDownload = checkPermission(file, PERMISSION_DOWNLOAD);
const hasTextLayer = hasDownload && !this.getViewerOption('disableTextLayer');
const textLayerMode = this.isMobile ? PDFJS_TEXT_LAYER_MODE.ENABLE : PDFJS_TEXT_LAYER_MODE.ENABLE_ENHANCE;

return new PdfViewerClass({
annotationMode: PDFAnnotationMode.ENABLE, // Show annotations, but not forms
Expand All @@ -807,7 +806,7 @@ class DocBaseViewer extends BaseViewer {
linkService: this.pdfLinkService,
maxCanvasPixels: this.isMobile ? MOBILE_MAX_CANVAS_SIZE : -1,
renderInteractiveForms: false, // Enabling prevents unverified signatures from being displayed
textLayerMode: hasTextLayer ? textLayerMode : PDFJS_TEXT_LAYER_MODE.DISABLE,
textLayerMode: hasTextLayer ? PDFJS_TEXT_LAYER_MODE.ENABLE : PDFJS_TEXT_LAYER_MODE.DISABLE,
});
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,16 +1145,18 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

return docBase.initViewer('').then(() => {
expect(stubs.checkPermission).toBeCalledWith(docBase.options.file, PERMISSION_DOWNLOAD);
expect(stubs.pdfViewerClass).toBeCalledWith(expect.objectContaining({ textLayerMode: 2 }));
// Text Layer mode 1 = enabled
expect(stubs.pdfViewerClass).toBeCalledWith(expect.objectContaining({ textLayerMode: 1 }));
});
});

test('should simplify the text layer if the user is on mobile', () => {
test('should enable the text layer if the user is on mobile', () => {
docBase.isMobile = true;
stubs.checkPermission.mockReturnValueOnce(true);

return docBase.initViewer('').then(() => {
expect(stubs.checkPermission).toBeCalledWith(docBase.options.file, PERMISSION_DOWNLOAD);
// Text Layer mode 1 = enabled
expect(stubs.pdfViewerClass).toBeCalledWith(expect.objectContaining({ textLayerMode: 1 }));
});
});
Expand All @@ -1164,6 +1166,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

return docBase.initViewer('').then(() => {
expect(stubs.checkPermission).toBeCalledWith(docBase.options.file, PERMISSION_DOWNLOAD);
// Text Layer mode 0 = disabled
expect(stubs.pdfViewerClass).toBeCalledWith(expect.objectContaining({ textLayerMode: 0 }));
});
});
Expand All @@ -1175,6 +1178,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
return docBase.initViewer('').then(() => {
expect(stubs.checkPermission).toBeCalledWith(docBase.options.file, PERMISSION_DOWNLOAD);
expect(stubs.getViewerOption).toBeCalledWith('disableTextLayer');
// Text Layer mode 0 = disabled
expect(stubs.pdfViewerClass).toBeCalledWith(expect.objectContaining({ textLayerMode: 0 }));
});
});
Expand Down

0 comments on commit 9625e46

Please sign in to comment.