1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Editor] Avoid editor creation/selection on right click (bug 1781762)

This commit is contained in:
Calixte Denizet 2022-07-27 14:11:29 +02:00
parent 8ebd2d3dfd
commit ce4144eee4
6 changed files with 100 additions and 18 deletions

View file

@ -21,8 +21,8 @@
/** @typedef {import("../../web/interfaces").IL10n} IL10n */
import { AnnotationEditorType, shadow } from "../../shared/util.js";
import { bindEvents, KeyboardManager } from "./tools.js";
import { binarySearchFirstItem } from "../display_utils.js";
import { bindEvents } from "./tools.js";
import { FreeTextEditor } from "./freetext.js";
import { InkEditor } from "./ink.js";
@ -577,6 +577,12 @@ class AnnotationEditorLayer {
* @param {PointerEvent} event
*/
pointerup(event) {
const isMac = KeyboardManager.platform.isMac;
if (event.button !== 0 || (event.ctrlKey && isMac)) {
// Don't create an editor on right click.
return;
}
if (event.target !== this.div) {
return;
}
@ -594,6 +600,12 @@ class AnnotationEditorLayer {
* @param {PointerEvent} event
*/
pointerdown(event) {
const isMac = KeyboardManager.platform.isMac;
if (event.button !== 0 || (event.ctrlKey && isMac)) {
// Do nothing on right click.
return;
}
if (event.target !== this.div) {
return;
}

View file

@ -253,6 +253,7 @@ class AnnotationEditor {
if (event.button !== 0 || (event.ctrlKey && isMac)) {
// Avoid to focus this editor because of a non-left click.
event.preventDefault();
return;
}
if (

View file

@ -217,6 +217,10 @@ class FreeTextEditor extends AnnotationEditor {
/** @inheritdoc */
enableEditMode() {
if (this.isInEditMode()) {
return;
}
this.parent.setEditingState(false);
this.parent.updateToolbar(AnnotationEditorType.FREETEXT);
super.enableEditMode();
@ -230,6 +234,10 @@ class FreeTextEditor extends AnnotationEditor {
/** @inheritdoc */
disableEditMode() {
if (!this.isInEditMode()) {
return;
}
this.parent.setEditingState(true);
super.disableEditMode();
this.overlayDiv.classList.add("enabled");
@ -239,6 +247,10 @@ class FreeTextEditor extends AnnotationEditor {
this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
// On Chrome, the focus is given to <body> when contentEditable is set to
// false, hence we focus the div.
this.div.focus();
// In case the blur callback hasn't been called.
this.isEditing = false;
}

View file

@ -244,6 +244,7 @@ class KeyboardManager {
return;
}
callback.bind(self)();
event.stopPropagation();
event.preventDefault();
}
}