WIP: first go at change list jumping again

Related: #2677
This commit is contained in:
Oliver Blanthorn 2021-01-20 21:19:51 +01:00
parent 3050d81b26
commit 99941d796e
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 12 additions and 1 deletions

View file

@ -2070,6 +2070,7 @@ export async function changelistjump() {
const tail = state.prevInputs[state.prevInputs.length - 1] const tail = state.prevInputs[state.prevInputs.length - 1]
const jumppos = tail.jumppos ? tail.jumppos : state.prevInputs.length - 1 const jumppos = tail.jumppos ? tail.jumppos : state.prevInputs.length - 1
const input = state.prevInputs[jumppos] const input = state.prevInputs[jumppos]
state.storeNextInput = "false"
await browser.tabs.update(input.tab, { active: true }) await browser.tabs.update(input.tab, { active: true })
const id = input.inputId const id = input.inputId
// Not all elements have an ID, so this will do for now. // Not all elements have an ID, so this will do for now.

View file

@ -533,11 +533,15 @@ function onPageFocus(elem: HTMLElement): boolean {
async function setInput(el) { async function setInput(el) {
const tab = await activeTabId() const tab = await activeTabId()
// store maximum of 10 elements to stop this getting bonkers huge if ((await State.getAsync("storeNextInput")) === "false") {
state.storeNextInput = "true"
return
}
const arr = (await State.getAsync("prevInputs")).concat({ const arr = (await State.getAsync("prevInputs")).concat({
tab, tab,
inputId: el.id, inputId: el.id,
}) })
// store maximum of 10 elements to stop this getting bonkers huge
state.prevInputs = arr.slice(Math.max(arr.length - 10, 0)) state.prevInputs = arr.slice(Math.max(arr.length - 10, 0))
} }

View file

@ -20,6 +20,10 @@ const logger = new Logger("state")
class State { class State {
lastSearchQuery: string = undefined lastSearchQuery: string = undefined
cmdHistory: string[] = [] cmdHistory: string[] = []
// How should this work?
// - if I jump to a prevInput, then I leave that input and stay on that tab, then invoke the command again, jump to the previous prevInput
// - if I'm on a different tab, jump to the same prevInput <!-- don't bother doing this yet -->
// - unless a new one has been activated, then jump to that
prevInputs: Array<{ inputId: string; tab: number; jumppos?: number }> = [ prevInputs: Array<{ inputId: string; tab: number; jumppos?: number }> = [
{ {
inputId: undefined, inputId: undefined,
@ -27,6 +31,8 @@ class State {
jumppos: undefined, jumppos: undefined,
}, },
] ]
// For some reason `: boolean` doesn't work here
storeNextInput: "true" | "false" = "true"
last_ex_str = "echo" last_ex_str = "echo"
} }