Skip to content

Commit

Permalink
Merge pull request #17519 from calixteman/editor_movable_touchscreen
Browse files Browse the repository at this point in the history
[Editor] Make editors draggable with touchscreens
  • Loading branch information
calixteman authored Jan 16, 2024
2 parents 3110865 + b8aab5d commit 51413be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class AnnotationEditor {

#moveInDOMTimeout = null;

#prevDragX = 0;

#prevDragY = 0;

_initialOptions = Object.create(null);

_uiManager = null;
Expand Down Expand Up @@ -1035,9 +1039,18 @@ class AnnotationEditor {

let pointerMoveOptions, pointerMoveCallback;
if (isSelected) {
this.div.classList.add("moving");
pointerMoveOptions = { passive: true, capture: true };
this.#prevDragX = event.clientX;
this.#prevDragY = event.clientY;
pointerMoveCallback = e => {
const [tx, ty] = this.screenToPageTranslation(e.movementX, e.movementY);
const { clientX: x, clientY: y } = e;
const [tx, ty] = this.screenToPageTranslation(
x - this.#prevDragX,
y - this.#prevDragY
);
this.#prevDragX = x;
this.#prevDragY = y;
this._uiManager.dragSelectedEditors(tx, ty);
};
window.addEventListener(
Expand All @@ -1051,6 +1064,7 @@ class AnnotationEditor {
window.removeEventListener("pointerup", pointerUpCallback);
window.removeEventListener("blur", pointerUpCallback);
if (isSelected) {
this.div.classList.remove("moving");
window.removeEventListener(
"pointermove",
pointerMoveCallback,
Expand Down
4 changes: 4 additions & 0 deletions web/annotation_editor_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
cursor: move;
}

&.moving {
touch-action: none;
}

&.selectedEditor {
border: var(--focus-outline);
outline: var(--focus-outline-around);
Expand Down

0 comments on commit 51413be

Please sign in to comment.