From 5d4af6b69e8106d86ae1fc0b25179dfbdadf05cd Mon Sep 17 00:00:00 2001 From: Syuilo Date: Sun, 16 Jul 2023 22:12:42 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=9A=A1=20improve=20performance?= =?UTF-8?q?=20of=20contextmenu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/assets/LICENSE | 13 +++++++++++++ packages/client/src/components/MkAutocomplete.vue | 10 ++-------- packages/client/src/components/MkContextMenu.vue | 8 ++------ 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 packages/backend/assets/LICENSE diff --git a/packages/backend/assets/LICENSE b/packages/backend/assets/LICENSE new file mode 100644 index 0000000000..342509dec1 --- /dev/null +++ b/packages/backend/assets/LICENSE @@ -0,0 +1,13 @@ +Copyright 2023 Calckey + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/client/src/components/MkAutocomplete.vue b/packages/client/src/components/MkAutocomplete.vue index 3e234ddbce..5fcee6e5ac 100644 --- a/packages/client/src/components/MkAutocomplete.vue +++ b/packages/client/src/components/MkAutocomplete.vue @@ -436,10 +436,7 @@ onMounted(() => { setPosition(); props.textarea.addEventListener("keydown", onKeydown); - - for (const el of Array.from(document.querySelectorAll("body *"))) { - el.addEventListener("mousedown", onMousedown); - } + document.body.addEventListener("mousedown", onMousedown); nextTick(() => { exec(); @@ -457,10 +454,7 @@ onMounted(() => { onBeforeUnmount(() => { props.textarea.removeEventListener("keydown", onKeydown); - - for (const el of Array.from(document.querySelectorAll("body *"))) { - el.removeEventListener("mousedown", onMousedown); - } + document.body.removeEventListener("mousedown", onMousedown); }); diff --git a/packages/client/src/components/MkContextMenu.vue b/packages/client/src/components/MkContextMenu.vue index a215477807..33506b96fd 100644 --- a/packages/client/src/components/MkContextMenu.vue +++ b/packages/client/src/components/MkContextMenu.vue @@ -57,15 +57,11 @@ onMounted(() => { rootEl.style.top = `${top}px`; rootEl.style.left = `${left}px`; - for (const el of Array.from(document.querySelectorAll("body *"))) { - el.addEventListener("mousedown", onMousedown); - } + document.body.addEventListener("mousedown", onMousedown); }); onBeforeUnmount(() => { - for (const el of Array.from(document.querySelectorAll("body *"))) { - el.removeEventListener("mousedown", onMousedown); - } + document.body.removeEventListener("mousedown", onMousedown); }); function onMousedown(evt: Event) {