From 2456caf2b72f65aa5b55c5a84747411b6f8f5f96 Mon Sep 17 00:00:00 2001 From: barsdeveloper Date: Sat, 2 Apr 2022 23:12:26 +0200 Subject: [PATCH] Node selection fix --- dist/ueblueprint.js | 49 +++++++++++------------ js/element/ISelectableDraggableElement.js | 4 -- js/input/mouse/IMouseClickDrag.js | 17 ++++---- js/input/mouse/MouseMoveNodes.js | 12 ++++++ 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index 305a8cb..e8ef9ce 100755 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -2045,11 +2045,6 @@ class KeyboardCanc extends IKeyboardShortcut { */ class IPointing extends IContext { - /** - * @param {T} target - * @param {Blueprint} blueprint - * @param {Object} options - */ constructor(target, blueprint, options) { super(target, blueprint, options); this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement; @@ -2606,12 +2601,8 @@ class IMouseClickDrag extends IPointing { started = false - /** - * @param {T} target - * @param {Blueprint} blueprint - * @param {Object} options - */ constructor(target, blueprint, options) { + options.unlistenOnTextEdit; super(target, blueprint, options); this.clickButton = options?.clickButton ?? 0; this.exitAnyButton = options?.exitAnyButton ?? true; @@ -2696,12 +2687,20 @@ class IMouseClickDrag extends IPointing { } }; + this.listenEvents(); + } + + listenEvents() { this.target.addEventListener("mousedown", this.#mouseDownHandler); if (this.clickButton == 2) { this.target.addEventListener("contextmenu", e => e.preventDefault()); } } + unlistenEvents() { + this.target.removeEventListener("mousedown", this.#mouseDownHandler); + } + getEvent(eventName) { return new CustomEvent(eventName, { detail: { @@ -2712,12 +2711,6 @@ class IMouseClickDrag extends IPointing { }) } - unlistenDOMElement() { - super.unlistenDOMElement(); - this.target.removeEventListener("mousedown", this.#mouseDownHandler); - if (this.clickButton == 2) ; - } - /* Subclasses will override the following methods */ clicked(location) { } @@ -2831,15 +2824,13 @@ class MouseTracking extends IPointing { /** * @typedef {import("../../Blueprint").default} Blueprint * @typedef {import("../../element/ISelectableDraggableElement").default} ISelectableDraggableElement + */ + +/** * @extends {IMouseClickDrag} */ class MouseMoveNodes extends IMouseClickDrag { - /** - * @param {ISelectableDraggableElement} target - * @param {Blueprint} blueprint - * @param {Object} options - */ constructor(target, blueprint, options) { super(target, blueprint, options); this.stepSize = parseInt(options?.stepSize ?? this.blueprint.gridSize); @@ -2849,6 +2840,11 @@ class MouseMoveNodes extends IMouseClickDrag { startDrag() { // Get the current mouse position this.mouseLocation = Utility.snapToGrid(this.clickedPosition, this.stepSize); + + if (!this.target.selected) { + this.blueprint.unselectAll(); + this.target.setSelected(true); + } } dragTo(location, movement) { @@ -2873,6 +2869,13 @@ class MouseMoveNodes extends IMouseClickDrag { // Reassign the position of mouse this.mouseLocation = mouseLocation; } + + unclicked() { + if (!this.started) { + this.blueprint.unselectAll(); + this.target.setSelected(true); + } + } } // @ts-check @@ -2942,10 +2945,6 @@ class ISelectableDraggableElement extends IElement { } dispatchDragEvent(value) { - if (!this.selected) { - this.blueprint.unselectAll(); - this.setSelected(true); - } const dragEvent = new CustomEvent(this.blueprint.settings.nodeDragEventName, { detail: { value: value diff --git a/js/element/ISelectableDraggableElement.js b/js/element/ISelectableDraggableElement.js index 2374266..20eaaa0 100644 --- a/js/element/ISelectableDraggableElement.js +++ b/js/element/ISelectableDraggableElement.js @@ -68,10 +68,6 @@ export default class ISelectableDraggableElement extends IElement { } dispatchDragEvent(value) { - if (!this.selected) { - this.blueprint.unselectAll() - this.setSelected(true) - } const dragEvent = new CustomEvent(this.blueprint.settings.nodeDragEventName, { detail: { value: value diff --git a/js/input/mouse/IMouseClickDrag.js b/js/input/mouse/IMouseClickDrag.js index d91bf85..45f96f6 100644 --- a/js/input/mouse/IMouseClickDrag.js +++ b/js/input/mouse/IMouseClickDrag.js @@ -30,6 +30,7 @@ export default class IMouseClickDrag extends IPointing { started = false constructor(target, blueprint, options) { + options.unlistenOnTextEdit super(target, blueprint, options) this.clickButton = options?.clickButton ?? 0 this.exitAnyButton = options?.exitAnyButton ?? true @@ -114,12 +115,20 @@ export default class IMouseClickDrag extends IPointing { } } + this.listenEvents() + } + + listenEvents() { this.target.addEventListener("mousedown", this.#mouseDownHandler) if (this.clickButton == 2) { this.target.addEventListener("contextmenu", e => e.preventDefault()) } } + unlistenEvents() { + this.target.removeEventListener("mousedown", this.#mouseDownHandler) + } + getEvent(eventName) { return new CustomEvent(eventName, { detail: { @@ -130,14 +139,6 @@ export default class IMouseClickDrag extends IPointing { }) } - unlistenDOMElement() { - super.unlistenDOMElement() - this.target.removeEventListener("mousedown", this.#mouseDownHandler) - if (this.clickButton == 2) { - //this.target.removeEventListener("contextmenu", e => e.preventDefault()) - } - } - /* Subclasses will override the following methods */ clicked(location) { } diff --git a/js/input/mouse/MouseMoveNodes.js b/js/input/mouse/MouseMoveNodes.js index 9573333..44e6aa2 100755 --- a/js/input/mouse/MouseMoveNodes.js +++ b/js/input/mouse/MouseMoveNodes.js @@ -22,6 +22,11 @@ export default class MouseMoveNodes extends IMouseClickDrag { startDrag() { // Get the current mouse position this.mouseLocation = Utility.snapToGrid(this.clickedPosition, this.stepSize) + + if (!this.target.selected) { + this.blueprint.unselectAll() + this.target.setSelected(true) + } } dragTo(location, movement) { @@ -46,4 +51,11 @@ export default class MouseMoveNodes extends IMouseClickDrag { // Reassign the position of mouse this.mouseLocation = mouseLocation } + + unclicked() { + if (!this.started) { + this.blueprint.unselectAll() + this.target.setSelected(true) + } + } }