Selaa lähdekoodia

단축키 버그 수정

잉여개발기 1 vuosi sitten
vanhempi
sitoutus
91556789c7
2 muutettua tiedostoa jossa 31 lisäystä ja 19 poistoa
  1. 1 1
      route/tool/func.py
  2. 30 18
      views/main_css/js/func/shortcut.js

+ 1 - 1
route/tool/func.py

@@ -1239,7 +1239,7 @@ def skin_check(conn, set_n = 0):
         return skin
     
 def cache_v():
-    return '.cache_v286'
+    return '.cache_v287'
 
 def wiki_css(data):
     # without_DB

+ 30 - 18
views/main_css/js/func/shortcut.js

@@ -1,39 +1,51 @@
 "use strict";
 
-let shortcut_key_list = [];
-document.onkeyup = function(e) {
-    delete shortcut_key_list[e.key];
-}
+let shortcut_key_list = {};
 
-document.onkeydown = function(e) {
+window.addEventListener("keyup", e => {
+    delete shortcut_key_list[e.code];
+});
+window.addEventListener("blur", () => {
+    shortcut_key_list = {};
+});
+document.addEventListener("visibilitychange", () => {
+    if(document.hidden) {
+        shortcut_key_list = {};
+    }
+});
+
+window.addEventListener("keydown", e => {
     let shortcut_check = e.target.tagName.toLowerCase();
-    if(
-        shortcut_check !== 'input' &&
-        shortcut_check !== 'textarea'
-    ) {
+    if(shortcut_check === 'input' || shortcut_check === 'textarea') {
+        return;
+    } else if(e.repeat) {
+        return;
+    }
+
+    shortcut_key_list[e.code] = 1;
+    if(Object.keys(shortcut_key_list).length === 1) {
         let doc_shortcut = /^\/(w|w_from|history|edit|acl|topic|xref)\//i;
 
-        shortcut_key_list[e.key] = 1;
-        if(shortcut_key_list['f'] === 1) {
+        if(shortcut_key_list['KeyF'] === 1) {
             window.location.href = '/';
-        } else if(shortcut_key_list['c'] === 1) {
+        } else if(shortcut_key_list['KeyC'] === 1) {
             window.location.href = '/recent_change';
-        } else if(shortcut_key_list['d'] === 1) {
+        } else if(shortcut_key_list['KeyD'] === 1) {
             window.location.href = '/recent_discuss';
-        } else if(shortcut_key_list['a'] === 1) {
+        } else if(shortcut_key_list['KeyA'] === 1) {
             window.location.href = '/random';
         }
 
         if(window.location.pathname.match(doc_shortcut)) {
             let doc_href = window.location.pathname.replace(doc_shortcut, '');
             
-            if(shortcut_key_list['w'] === 1) {
+            if(shortcut_key_list['KeyW'] === 1) {
                 window.location.pathname = '/w/' + doc_href;
-            } else if(shortcut_key_list['e'] === 1) {
+            } else if(shortcut_key_list['KeyE'] === 1) {
                 window.location.pathname = '/edit/' + doc_href;
-            } else if(shortcut_key_list['h'] === 1) {
+            } else if(shortcut_key_list['KeyH'] === 1) {
                 window.location.pathname = '/history/' + doc_href;
             }
         }
     }
-}
+});