shortcutListener()

in src/js/popup.js [417:462]


  shortcutListener(e){
    function openTopContainers() {
      const identities = Logic.identities();
      const key = e.code.substring(5);
      const identity = e.code === "Digit0" ? identities[9] : identities[key - 1];

      try {
        browser.tabs.create({
          cookieStoreId: identity.cookieStoreId
        });
        window.close();
      } catch (e) {
        window.close();
      }
    }

    // We monitor if the search input is focused so we can disable opening
    // containers by typing a digit between 0-9 while the popup is open.
    const searchInput = document.getElementById("search-terms");
    let isSearchInputFocused = false;

    if (document.activeElement === searchInput) {
      isSearchInputFocused = true;
    }

    if (Logic._currentPanel === "containersList" && !isSearchInputFocused) {
      switch(e.code) {
      case "Digit0":
      case "Digit1":
      case "Digit2":
      case "Digit3":
      case "Digit4":
      case "Digit5":
      case "Digit6":
      case "Digit7":
      case "Digit8":
      case "Digit9":
        openTopContainers();
        break;
      case "Slash":
        document.getElementById("search-terms").focus();
        e.preventDefault();
        break;
      }
    }
  },