From 00d4ed48a5f57cc04a44d725a2e976c8df54db7f Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 2 Jul 2021 00:20:16 -0500 Subject: [PATCH] Close context menu on resize --- src/scaffolding/context-menu.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scaffolding/context-menu.js b/src/scaffolding/context-menu.js index 7c57579..56e8e5d 100644 --- a/src/scaffolding/context-menu.js +++ b/src/scaffolding/context-menu.js @@ -7,7 +7,8 @@ class ContextMenu { this.root = document.createElement('div'); this.root.className = styles.contextMenu; - this._onmousedown = this._onmousedown.bind(this) + this._onmousedown = this._onmousedown.bind(this); + this._onresize = this._onresize.bind(this); } _onmousedown (e) { @@ -16,6 +17,10 @@ class ContextMenu { } } + _onresize () { + this.destroy(); + } + add (option) { const item = document.createElement('button'); item.className = styles.contextMenuItem; @@ -32,6 +37,7 @@ class ContextMenu { show (mouseEvent) { document.addEventListener('mousedown', this._onmousedown); + window.addEventListener('resize', this._onresize); const layersRect = this.parent.layersRect; const x = mouseEvent.clientX - layersRect.left + 1; const y = mouseEvent.clientY - layersRect.top + 1; @@ -41,6 +47,7 @@ class ContextMenu { destroy () { document.removeEventListener('mousedown', this._onmousedown); + window.removeEventListener('resize', this._onresize); this.root.remove(); } }