From a253d5dc1086da82a278ba6531ba3d7ce488ba47 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Mon, 21 Dec 2020 16:21:42 +0000 Subject: [PATCH] Make `gi` per-tab again --- src/lib/dom.ts | 17 ++++++++++++----- src/state.ts | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/dom.ts b/src/lib/dom.ts index d37deef5..182ae0bc 100644 --- a/src/lib/dom.ts +++ b/src/lib/dom.ts @@ -509,7 +509,8 @@ export function focus(e: HTMLElement): void { } export async function getLastUsedInputSelector(): Promise { - return State.getAsync("lastFocusInputSelector") + const tabid = await activeTabId() + return (await State.getAsync("lastFocusInputSelectors")).get(tabid) } export async function getLastUsedInput(): Promise { @@ -532,9 +533,12 @@ export async function getLastUsedInput(): Promise { * https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements * https://bugzilla.mozilla.org/show_bug.cgi?id=1406825 * */ -function onPageFocus(elem: HTMLElement): boolean { +async function onPageFocus(elem: HTMLElement): Promise { if (isTextEditable(elem)) { - state.lastFocusInputSelector = getSelector(elem) + const t = await activeTabId() + state.lastFocusInputSelectors = ( + await State.getAsync("lastFocusInputSelectors") + ).set(t, getSelector(elem)) } return config.get("allowautofocus") === "true" } @@ -566,9 +570,12 @@ function hijackPageFocusFunction(): void { export function setupFocusHandler(): void { // Handles when a user selects an input - document.addEventListener("focusin", e => { + document.addEventListener("focusin", async e => { if (isTextEditable(e.target as HTMLElement)) { - state.lastFocusInputSelector = getSelector(e.target as HTMLElement) + const t = await activeTabId() + state.lastFocusInputSelectors = ( + await State.getAsync("lastFocusInputSelectors") + ).set(t, getSelector(e.target as HTMLElement)) setInput(e.target as HTMLInputElement) } }) diff --git a/src/state.ts b/src/state.ts index f76bd560..359ba709 100644 --- a/src/state.ts +++ b/src/state.ts @@ -28,7 +28,7 @@ class State { }, ] last_ex_str = "echo" - lastFocusInputSelector = "" // used for focusinput, not for changing tabs like prevInputs + lastFocusInputSelectors: Map = new Map() // used for focusinput, not for changing tabs like prevInputs } // Store these keys in the local browser storage to persist between restarts