Make gi per-tab again

This commit is contained in:
Oliver Blanthorn 2020-12-21 16:21:42 +00:00
parent 43323b4ad7
commit a253d5dc10
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 13 additions and 6 deletions

View file

@ -509,7 +509,8 @@ export function focus(e: HTMLElement): void {
}
export async function getLastUsedInputSelector(): Promise<string> {
return State.getAsync("lastFocusInputSelector")
const tabid = await activeTabId()
return (await State.getAsync("lastFocusInputSelectors")).get(tabid)
}
export async function getLastUsedInput(): Promise<HTMLElement> {
@ -532,9 +533,12 @@ export async function getLastUsedInput(): Promise<HTMLElement> {
* 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<boolean> {
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)
}
})

View file

@ -28,7 +28,7 @@ class State {
},
]
last_ex_str = "echo"
lastFocusInputSelector = "" // used for focusinput, not for changing tabs like prevInputs
lastFocusInputSelectors: Map<number, string> = new Map() // used for focusinput, not for changing tabs like prevInputs
}
// Store these keys in the local browser storage to persist between restarts