[Editor] Refactor dragging and dropping an editor (bugs 1802895, 1844618)

It'll help to have a full control on what's happening when moving an editor.
This commit is contained in:
Calixte Denizet 2023-08-02 20:08:09 +02:00
parent 0725b6299f
commit b59b1a81a9
11 changed files with 170 additions and 75 deletions

View file

@ -587,6 +587,8 @@ class AnnotationEditorUIManager {
#container = null;
#viewer = null;
static TRANSLATE_SMALL = 1; // page units.
static TRANSLATE_BIG = 10; // page units.
@ -687,8 +689,9 @@ class AnnotationEditorUIManager {
);
}
constructor(container, eventBus, pdfDocument, pageColors) {
constructor(container, viewer, eventBus, pdfDocument, pageColors) {
this.#container = container;
this.#viewer = viewer;
this.#eventBus = eventBus;
this.#eventBus._on("editingaction", this.#boundOnEditingAction);
this.#eventBus._on("pagechanging", this.#boundOnPageChanging);
@ -741,6 +744,30 @@ class AnnotationEditorUIManager {
this.#container.focus();
}
findParent(x, y) {
for (const layer of this.#allLayers.values()) {
const {
x: layerX,
y: layerY,
width,
height,
} = layer.div.getBoundingClientRect();
if (
x >= layerX &&
x <= layerX + width &&
y >= layerY &&
y <= layerY + height
) {
return layer;
}
}
return null;
}
disableUserSelect(value = false) {
this.#viewer.classList.toggle("noUserSelect", value);
}
addShouldRescale(editor) {
this.#editorsToRescale.add(editor);
}
@ -962,6 +989,7 @@ class AnnotationEditorUIManager {
this.#dispatchUpdateStates({
isEditing: false,
});
this.disableUserSelect(false);
}
}