Merge pull request #15211 from calixteman/selection
[Editor] Fix multi-selection on touch screens
This commit is contained in:
commit
bf00068731
@ -548,6 +548,14 @@ class AnnotationEditorLayer {
|
|||||||
this.#uiManager.setSelected(editor);
|
this.#uiManager.setSelected(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add or remove an editor the current selection.
|
||||||
|
* @param {AnnotationEditor} editor
|
||||||
|
*/
|
||||||
|
toggleSelected(editor) {
|
||||||
|
this.#uiManager.toggleSelected(editor);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the editor is selected.
|
* Check if the editor is selected.
|
||||||
* @param {AnnotationEditor} editor
|
* @param {AnnotationEditor} editor
|
||||||
@ -564,18 +572,6 @@ class AnnotationEditorLayer {
|
|||||||
this.#uiManager.unselect(editor);
|
this.#uiManager.unselect(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isMultipleSelection() {
|
|
||||||
return this.#uiManager.isMultipleSelection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An editor just got a mousedown with ctrl key pressed.
|
|
||||||
* @param {boolean}} isMultiple
|
|
||||||
*/
|
|
||||||
set isMultipleSelection(isMultiple) {
|
|
||||||
this.#uiManager.isMultipleSelection = isMultiple;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pointerup callback.
|
* Pointerup callback.
|
||||||
* @param {PointerEvent} event
|
* @param {PointerEvent} event
|
||||||
|
@ -35,16 +35,12 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
#boundFocusout = this.focusout.bind(this);
|
#boundFocusout = this.focusout.bind(this);
|
||||||
|
|
||||||
|
#hasBeenSelected = false;
|
||||||
|
|
||||||
#isEditing = false;
|
#isEditing = false;
|
||||||
|
|
||||||
#isFocused = false;
|
|
||||||
|
|
||||||
#isInEditMode = false;
|
#isInEditMode = false;
|
||||||
|
|
||||||
#wasSelected = false;
|
|
||||||
|
|
||||||
#wasFocused = false;
|
|
||||||
|
|
||||||
#zIndex = AnnotationEditor._zIndex++;
|
#zIndex = AnnotationEditor._zIndex++;
|
||||||
|
|
||||||
static _colorManager = new ColorManager();
|
static _colorManager = new ColorManager();
|
||||||
@ -96,26 +92,14 @@ class AnnotationEditor {
|
|||||||
this.div.style.zIndex = this.#zIndex;
|
this.div.style.zIndex = this.#zIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#select() {
|
|
||||||
if (this.#wasSelected) {
|
|
||||||
this.parent.unselect(this);
|
|
||||||
this.unselect();
|
|
||||||
this.#wasSelected = true;
|
|
||||||
} else {
|
|
||||||
this.parent.setSelected(this);
|
|
||||||
this.select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onfocus callback.
|
* onfocus callback.
|
||||||
*/
|
*/
|
||||||
focusin(event) {
|
focusin(event) {
|
||||||
this.#isFocused =
|
if (!this.#hasBeenSelected) {
|
||||||
event.target === this.div ||
|
this.parent.setSelected(this);
|
||||||
!!event.relatedTarget?.closest(`#${this.id}`);
|
} else {
|
||||||
if (event.target === this.div) {
|
this.#hasBeenSelected = false;
|
||||||
this.#select();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,14 +123,8 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
this.#isFocused = false;
|
|
||||||
if (!this.parent.isMultipleSelection) {
|
if (!this.parent.isMultipleSelection) {
|
||||||
this.commitOrRemove();
|
this.commitOrRemove();
|
||||||
if (target?.closest(".annotationEditorLayer")) {
|
|
||||||
// We only unselect the element when another editor (or its parent)
|
|
||||||
// is grabbing the focus.
|
|
||||||
this.parent.unselect(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +239,7 @@ class AnnotationEditor {
|
|||||||
const [tx, ty] = this.getInitialTranslation();
|
const [tx, ty] = this.getInitialTranslation();
|
||||||
this.translate(tx, ty);
|
this.translate(tx, ty);
|
||||||
|
|
||||||
bindEvents(this, this.div, ["dragstart", "pointerdown", "pointerup"]);
|
bindEvents(this, this.div, ["dragstart", "pointerdown"]);
|
||||||
|
|
||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
@ -276,22 +254,13 @@ class AnnotationEditor {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
const isMultipleSelection = (this.parent.isMultipleSelection =
|
if (event.ctrlKey || event.shiftKey) {
|
||||||
event.ctrlKey || event.shiftKey);
|
this.parent.toggleSelected(this);
|
||||||
this.#wasSelected = isMultipleSelection && this.parent.isSelected(this);
|
} else {
|
||||||
this.#wasFocused = this.#isFocused;
|
this.parent.setSelected(this);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Onmouseup callback.
|
|
||||||
* @param {PointerEvent} event
|
|
||||||
*/
|
|
||||||
pointerup(event) {
|
|
||||||
if (this.#wasFocused) {
|
|
||||||
this.#select();
|
|
||||||
}
|
}
|
||||||
this.parent.isMultipleSelection = false;
|
|
||||||
this.#wasFocused = false;
|
this.#hasBeenSelected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRect(tx, ty) {
|
getRect(tx, ty) {
|
||||||
@ -545,7 +514,6 @@ class AnnotationEditor {
|
|||||||
set isEditing(value) {
|
set isEditing(value) {
|
||||||
this.#isEditing = value;
|
this.#isEditing = value;
|
||||||
if (value) {
|
if (value) {
|
||||||
this.select();
|
|
||||||
this.parent.setSelected(this);
|
this.parent.setSelected(this);
|
||||||
this.parent.setActiveEditor(this);
|
this.parent.setActiveEditor(this);
|
||||||
} else {
|
} else {
|
||||||
|
@ -377,8 +377,6 @@ class AnnotationEditorUIManager {
|
|||||||
|
|
||||||
#currentPageIndex = 0;
|
#currentPageIndex = 0;
|
||||||
|
|
||||||
#isMultipleSelection = false;
|
|
||||||
|
|
||||||
#editorTypes = null;
|
#editorTypes = null;
|
||||||
|
|
||||||
#eventBus = null;
|
#eventBus = null;
|
||||||
@ -740,35 +738,44 @@ class AnnotationEditorUIManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add or remove an editor the current selection.
|
||||||
|
* @param {AnnotationEditor} editor
|
||||||
|
*/
|
||||||
|
toggleSelected(editor) {
|
||||||
|
if (this.#selectedEditors.has(editor)) {
|
||||||
|
this.#selectedEditors.delete(editor);
|
||||||
|
editor.unselect();
|
||||||
|
this.#dispatchUpdateStates({
|
||||||
|
hasSelectedEditor: this.hasSelection,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#selectedEditors.add(editor);
|
||||||
|
editor.select();
|
||||||
|
this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
||||||
|
this.#dispatchUpdateStates({
|
||||||
|
hasSelectedEditor: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the last selected editor.
|
* Set the last selected editor.
|
||||||
* @param {AnnotationEditor} editor
|
* @param {AnnotationEditor} editor
|
||||||
*/
|
*/
|
||||||
setSelected(editor) {
|
setSelected(editor) {
|
||||||
if (!this.#isMultipleSelection) {
|
for (const ed of this.#selectedEditors) {
|
||||||
if (this.#selectedEditors.has(editor)) {
|
if (ed !== editor) {
|
||||||
if (this.#selectedEditors.size > 1) {
|
|
||||||
for (const ed of this.#selectedEditors) {
|
|
||||||
if (ed !== editor) {
|
|
||||||
ed.unselect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.#selectedEditors.clear();
|
|
||||||
this.#selectedEditors.add(editor);
|
|
||||||
this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const ed of this.#selectedEditors) {
|
|
||||||
ed.unselect();
|
ed.unselect();
|
||||||
}
|
}
|
||||||
this.#selectedEditors.clear();
|
|
||||||
}
|
}
|
||||||
|
this.#selectedEditors.clear();
|
||||||
|
|
||||||
this.#selectedEditors.add(editor);
|
this.#selectedEditors.add(editor);
|
||||||
|
editor.select();
|
||||||
this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
this.#dispatchUpdateUI(editor.propertiesToUpdate);
|
||||||
this.#dispatchUpdateStates({
|
this.#dispatchUpdateStates({
|
||||||
hasSelectedEditor: this.hasSelection,
|
hasSelectedEditor: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,18 +803,6 @@ class AnnotationEditorUIManager {
|
|||||||
return this.#selectedEditors.size !== 0;
|
return this.#selectedEditors.size !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isMultipleSelection() {
|
|
||||||
return this.#isMultipleSelection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An editor just got a mousedown with ctrl key pressed.
|
|
||||||
* @param {boolean} isMultiple
|
|
||||||
*/
|
|
||||||
set isMultipleSelection(isMultiple) {
|
|
||||||
this.#isMultipleSelection = isMultiple;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undo the last command.
|
* Undo the last command.
|
||||||
*/
|
*/
|
||||||
@ -863,6 +858,11 @@ class AnnotationEditorUIManager {
|
|||||||
* Delete the current editor or all.
|
* Delete the current editor or all.
|
||||||
*/
|
*/
|
||||||
delete() {
|
delete() {
|
||||||
|
if (this.#activeEditor) {
|
||||||
|
// An editor is being edited so just commit it.
|
||||||
|
this.#activeEditor.commitOrRemove();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.hasSelection) {
|
if (!this.hasSelection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -886,8 +886,22 @@ class AnnotationEditorUIManager {
|
|||||||
* Copy the selected editor.
|
* Copy the selected editor.
|
||||||
*/
|
*/
|
||||||
copy() {
|
copy() {
|
||||||
|
if (this.#activeEditor) {
|
||||||
|
// An editor is being edited so just commit it.
|
||||||
|
this.#activeEditor.commitOrRemove();
|
||||||
|
}
|
||||||
if (this.hasSelection) {
|
if (this.hasSelection) {
|
||||||
this.#clipboardManager.copy([...this.#selectedEditors]);
|
const editors = [];
|
||||||
|
for (const editor of this.#selectedEditors) {
|
||||||
|
if (!editor.isEmpty()) {
|
||||||
|
editors.push(editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (editors.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#clipboardManager.copy(editors);
|
||||||
this.#dispatchUpdateStates({ hasEmptyClipboard: false });
|
this.#dispatchUpdateStates({ hasEmptyClipboard: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user