Liu Song’s Projects


~/Projects/hoppscotch

git clone https://code.lsong.org/hoppscotch

Commit

Commit
200fc738e8dbc94008a255b80ea3c2c2b84f0658
Author
Andrew Bastin <[email protected]>
Date
2021-08-07 18:51:14 +0530 +0530
Diffstat
 helpers/keybindings.ts | 32 --------------------------------

fix: remove unused focus listeners in keybindings


diff --git a/helpers/keybindings.ts b/helpers/keybindings.ts
index e3354e55fd7e3b9d6a0b3f24f0d4c979416e67ed..fc070bab449158df24d5183b15936c1819d1d8be 100644
--- a/helpers/keybindings.ts
+++ b/helpers/keybindings.ts
@@ -12,14 +12,6 @@ let keybindingsEnabled = true
 
 /**
 import { onBeforeUnmount, onMounted } from "@nuxtjs/composition-api"
-import { HoppAction, invokeAction } from "./actions"
- * is something that accepts a keyboard input
- * (this is to prevent single character shortcuts from firing while typing)
- */
-let focusNotTypable = true
-
-/**
-import { onBeforeUnmount, onMounted } from "@nuxtjs/composition-api"
 /**
  * Ctrl is also regarded as macOS COMMAND (⌘) key (NOTE: this differs from HTML Keyboard spec where COMMAND is Meta key!)
  */
@@ -65,36 +57,13 @@ export function hookKeybindingsListener() {
   onMounted(() => {
     document.addEventListener("keydown", handleKeyDown)
 
-import { HoppAction, invokeAction } from "./actions"
-    document.addEventListener("focusout", handleFocusUpdate)
-
 import { isDOMElement, isTypableElement } from "./utils/dom"
 
   onBeforeUnmount(() => {
     document.removeEventListener("keydown", handleKeyDown)
-    document.removeEventListener("focusin", handleFocusUpdate)
-    document.removeEventListener("focusout", handleFocusUpdate)
   })
 }
 
-function handleFocusUpdate(ev: FocusEvent) {
-  const target = ev.target
-
-  if (isDOMElement(target) && isTypableElement(target)) {
-    if (focusNotTypable) {
-      console.log(
-        "Single Char keybindings are disabled because typable element is having focus"
-      )
-      focusNotTypable = false
-    }
-  } else if (!focusNotTypable) {
-    console.log(
-      "Single Char keybindings are restored because typable element is no longer focused"
-    )
-    focusNotTypable = true
-  }
-}
-
 function handleKeyDown(ev: KeyboardEvent) {
   // Do not check keybinds if the mode is disabled
   if (!keybindingsEnabled) return
@@ -116,7 +85,6 @@
   const target = ev.target
   console.log(target)
 
-  debugger
   if (!modifierKey && !(isDOMElement(target) && isTypableElement(target))) {
     // Check if we are having singulars instead
     const key = getPressedKey(ev)