Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1947248

Browse files
calixtemanpull[bot]
authored andcommittedDec 8, 2022
[Editor] Fix multi-selection on touch screens
1 parent 9bedd8e commit 1947248

File tree

3 files changed

+68
-90
lines changed

3 files changed

+68
-90
lines changed
 

‎src/display/editor/annotation_editor_layer.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,14 @@ class AnnotationEditorLayer {
548548
this.#uiManager.setSelected(editor);
549549
}
550550

551+
/**
552+
* Add or remove an editor the current selection.
553+
* @param {AnnotationEditor} editor
554+
*/
555+
toggleSelected(editor) {
556+
this.#uiManager.toggleSelected(editor);
557+
}
558+
551559
/**
552560
* Check if the editor is selected.
553561
* @param {AnnotationEditor} editor
@@ -564,18 +572,6 @@ class AnnotationEditorLayer {
564572
this.#uiManager.unselect(editor);
565573
}
566574

567-
get isMultipleSelection() {
568-
return this.#uiManager.isMultipleSelection;
569-
}
570-
571-
/**
572-
* An editor just got a mousedown with ctrl key pressed.
573-
* @param {boolean}} isMultiple
574-
*/
575-
set isMultipleSelection(isMultiple) {
576-
this.#uiManager.isMultipleSelection = isMultiple;
577-
}
578-
579575
/**
580576
* Pointerup callback.
581577
* @param {PointerEvent} event

‎src/display/editor/editor.js

+13-45
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,12 @@ class AnnotationEditor {
3535

3636
#boundFocusout = this.focusout.bind(this);
3737

38-
#isEditing = false;
38+
#hasBeenSelected = false;
3939

40-
#isFocused = false;
40+
#isEditing = false;
4141

4242
#isInEditMode = false;
4343

44-
#wasSelected = false;
45-
46-
#wasFocused = false;
47-
4844
#zIndex = AnnotationEditor._zIndex++;
4945

5046
static _colorManager = new ColorManager();
@@ -96,26 +92,14 @@ class AnnotationEditor {
9692
this.div.style.zIndex = this.#zIndex;
9793
}
9894

99-
#select() {
100-
if (this.#wasSelected) {
101-
this.parent.unselect(this);
102-
this.unselect();
103-
this.#wasSelected = true;
104-
} else {
105-
this.parent.setSelected(this);
106-
this.select();
107-
}
108-
}
109-
11095
/**
11196
* onfocus callback.
11297
*/
11398
focusin(event) {
114-
this.#isFocused =
115-
event.target === this.div ||
116-
!!event.relatedTarget?.closest(`#${this.id}`);
117-
if (event.target === this.div) {
118-
this.#select();
99+
if (!this.#hasBeenSelected) {
100+
this.parent.setSelected(this);
101+
} else {
102+
this.#hasBeenSelected = false;
119103
}
120104
}
121105

@@ -139,14 +123,8 @@ class AnnotationEditor {
139123

140124
event.preventDefault();
141125

142-
this.#isFocused = false;
143126
if (!this.parent.isMultipleSelection) {
144127
this.commitOrRemove();
145-
if (target?.closest(".annotationEditorLayer")) {
146-
// We only unselect the element when another editor (or its parent)
147-
// is grabbing the focus.
148-
this.parent.unselect(this);
149-
}
150128
}
151129
}
152130

@@ -261,7 +239,7 @@ class AnnotationEditor {
261239
const [tx, ty] = this.getInitialTranslation();
262240
this.translate(tx, ty);
263241

264-
bindEvents(this, this.div, ["dragstart", "pointerdown", "pointerup"]);
242+
bindEvents(this, this.div, ["dragstart", "pointerdown"]);
265243

266244
return this.div;
267245
}
@@ -276,22 +254,13 @@ class AnnotationEditor {
276254
event.preventDefault();
277255
}
278256

279-
const isMultipleSelection = (this.parent.isMultipleSelection =
280-
event.ctrlKey || event.shiftKey);
281-
this.#wasSelected = isMultipleSelection && this.parent.isSelected(this);
282-
this.#wasFocused = this.#isFocused;
283-
}
284-
285-
/**
286-
* Onmouseup callback.
287-
* @param {PointerEvent} event
288-
*/
289-
pointerup(event) {
290-
if (this.#wasFocused) {
291-
this.#select();
257+
if (event.ctrlKey || event.shiftKey) {
258+
this.parent.toggleSelected(this);
259+
} else {
260+
this.parent.setSelected(this);
292261
}
293-
this.parent.isMultipleSelection = false;
294-
this.#wasFocused = false;
262+
263+
this.#hasBeenSelected = true;
295264
}
296265

297266
getRect(tx, ty) {
@@ -545,7 +514,6 @@ class AnnotationEditor {
545514
set isEditing(value) {
546515
this.#isEditing = value;
547516
if (value) {
548-
this.select();
549517
this.parent.setSelected(this);
550518
this.parent.setActiveEditor(this);
551519
} else {

‎src/display/editor/tools.js

+47-33
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,6 @@ class AnnotationEditorUIManager {
377377

378378
#currentPageIndex = 0;
379379

380-
#isMultipleSelection = false;
381-
382380
#editorTypes = null;
383381

384382
#eventBus = null;
@@ -740,35 +738,44 @@ class AnnotationEditorUIManager {
740738
}
741739
}
742740

741+
/**
742+
* Add or remove an editor the current selection.
743+
* @param {AnnotationEditor} editor
744+
*/
745+
toggleSelected(editor) {
746+
if (this.#selectedEditors.has(editor)) {
747+
this.#selectedEditors.delete(editor);
748+
editor.unselect();
749+
this.#dispatchUpdateStates({
750+
hasSelectedEditor: this.hasSelection,
751+
});
752+
return;
753+
}
754+
this.#selectedEditors.add(editor);
755+
editor.select();
756+
this.#dispatchUpdateUI(editor.propertiesToUpdate);
757+
this.#dispatchUpdateStates({
758+
hasSelectedEditor: true,
759+
});
760+
}
761+
743762
/**
744763
* Set the last selected editor.
745764
* @param {AnnotationEditor} editor
746765
*/
747766
setSelected(editor) {
748-
if (!this.#isMultipleSelection) {
749-
if (this.#selectedEditors.has(editor)) {
750-
if (this.#selectedEditors.size > 1) {
751-
for (const ed of this.#selectedEditors) {
752-
if (ed !== editor) {
753-
ed.unselect();
754-
}
755-
}
756-
this.#selectedEditors.clear();
757-
this.#selectedEditors.add(editor);
758-
this.#dispatchUpdateUI(editor.propertiesToUpdate);
759-
}
760-
return;
761-
}
762-
763-
for (const ed of this.#selectedEditors) {
767+
for (const ed of this.#selectedEditors) {
768+
if (ed !== editor) {
764769
ed.unselect();
765770
}
766-
this.#selectedEditors.clear();
767771
}
772+
this.#selectedEditors.clear();
773+
768774
this.#selectedEditors.add(editor);
775+
editor.select();
769776
this.#dispatchUpdateUI(editor.propertiesToUpdate);
770777
this.#dispatchUpdateStates({
771-
hasSelectedEditor: this.hasSelection,
778+
hasSelectedEditor: true,
772779
});
773780
}
774781

@@ -796,18 +803,6 @@ class AnnotationEditorUIManager {
796803
return this.#selectedEditors.size !== 0;
797804
}
798805

799-
get isMultipleSelection() {
800-
return this.#isMultipleSelection;
801-
}
802-
803-
/**
804-
* An editor just got a mousedown with ctrl key pressed.
805-
* @param {boolean} isMultiple
806-
*/
807-
set isMultipleSelection(isMultiple) {
808-
this.#isMultipleSelection = isMultiple;
809-
}
810-
811806
/**
812807
* Undo the last command.
813808
*/
@@ -863,6 +858,11 @@ class AnnotationEditorUIManager {
863858
* Delete the current editor or all.
864859
*/
865860
delete() {
861+
if (this.#activeEditor) {
862+
// An editor is being edited so just commit it.
863+
this.#activeEditor.commitOrRemove();
864+
}
865+
866866
if (!this.hasSelection) {
867867
return;
868868
}
@@ -886,8 +886,22 @@ class AnnotationEditorUIManager {
886886
* Copy the selected editor.
887887
*/
888888
copy() {
889+
if (this.#activeEditor) {
890+
// An editor is being edited so just commit it.
891+
this.#activeEditor.commitOrRemove();
892+
}
889893
if (this.hasSelection) {
890-
this.#clipboardManager.copy([...this.#selectedEditors]);
894+
const editors = [];
895+
for (const editor of this.#selectedEditors) {
896+
if (!editor.isEmpty()) {
897+
editors.push(editor);
898+
}
899+
}
900+
if (editors.length === 0) {
901+
return;
902+
}
903+
904+
this.#clipboardManager.copy(editors);
891905
this.#dispatchUpdateStates({ hasEmptyClipboard: false });
892906
}
893907
}

0 commit comments

Comments
 (0)
Please sign in to comment.