From 4bfa29c0abb68b217b486a75f48316da1b56e621 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 25 Oct 2020 11:01:03 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=86=E3=82=AD=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=83=A1=E3=83=8B=E3=83=A5=E3=83=BC=E3=81=AE=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E8=A8=88=E7=AE=97=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/components/ui/context-menu.vue | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/client/components/ui/context-menu.vue b/src/client/components/ui/context-menu.vue index 3a11589e8..1b4d386eb 100644 --- a/src/client/components/ui/context-menu.vue +++ b/src/client/components/ui/context-menu.vue @@ -35,8 +35,30 @@ export default defineComponent({ }, }, mounted() { - this.$el.style.top = this.ev.pageY + 'px'; - this.$el.style.left = this.ev.pageX + 'px'; + let left = this.ev.pageX + 1; // 間違って右ダブルクリックした場合に意図せずアイテムがクリックされるのを防ぐため + 1 + let top = this.ev.pageY + 1; // 間違って右ダブルクリックした場合に意図せずアイテムがクリックされるのを防ぐため + 1 + + const width = this.$el.offsetWidth; + const height = this.$el.offsetHeight; + + if (left + width - window.pageXOffset > window.innerWidth) { + left = window.innerWidth - width + window.pageXOffset; + } + + if (top + height - window.pageYOffset > window.innerHeight) { + top = window.innerHeight - height + window.pageYOffset; + } + + if (top < 0) { + top = 0; + } + + if (left < 0) { + left = 0; + } + + this.$el.style.top = top + 'px'; + this.$el.style.left = left + 'px'; for (const el of Array.from(document.querySelectorAll('body *'))) { el.addEventListener('mousedown', this.onMousedown);