Allow text-selection, but not copying, when enablePermissions is set (PR 16320 follow-up)

This commit is contained in:
Jonas Jenwald 2023-04-22 13:07:07 +02:00
parent 1b79b0cd21
commit 8a9d7a18cc
5 changed files with 46 additions and 33 deletions

View file

@ -38,6 +38,8 @@ import { removeNullCharacters } from "./ui_utils.js";
* contain text that matches the PDF text they are overlaying.
*/
class TextLayerBuilder {
#enablePermissions = false;
#rotation = 0;
#scale = 0;
@ -48,6 +50,7 @@ class TextLayerBuilder {
highlighter = null,
accessibilityManager = null,
isOffscreenCanvasSupported = true,
enablePermissions = false,
}) {
this.textContentItemsStr = [];
this.renderingDone = false;
@ -57,6 +60,7 @@ class TextLayerBuilder {
this.highlighter = highlighter;
this.accessibilityManager = accessibilityManager;
this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
this.#enablePermissions = enablePermissions === true;
this.div = document.createElement("div");
this.div.className = "textLayer";
@ -215,11 +219,13 @@ class TextLayerBuilder {
});
div.addEventListener("copy", event => {
const selection = document.getSelection();
event.clipboardData.setData(
"text/plain",
removeNullCharacters(normalizeUnicode(selection.toString()))
);
if (!this.#enablePermissions) {
const selection = document.getSelection();
event.clipboardData.setData(
"text/plain",
removeNullCharacters(normalizeUnicode(selection.toString()))
);
}
event.preventDefault();
event.stopPropagation();
});