Change bufferall argument to WINDOW_INDEX.TAB_INDEX

This commit is contained in:
glacambre 2018-06-19 19:42:35 +02:00
parent 4bd8216a41
commit 8fe7d039bc
No known key found for this signature in database
GPG key ID: B9625DB1767553AC
2 changed files with 18 additions and 14 deletions

View file

@ -4,10 +4,10 @@ import * as Completions from "../completions"
class BufferAllCompletionOption extends Completions.CompletionOptionHTML
implements Completions.CompletionOptionFuse {
public fuseKeys = []
constructor(public value: string, tab: browser.tabs.Tab, winindex: number) {
super()
this.fuseKeys.push(String(tab.id), tab.title, tab.url)
this.value = `${winindex}.${tab.index + 1}`
this.fuseKeys.push(this.value, tab.title, tab.url)
// Create HTMLElement
const favIconUrl = tab.favIconUrl
@ -16,7 +16,7 @@ class BufferAllCompletionOption extends Completions.CompletionOptionHTML
this.html = html`<tr class="BufferAllCompletionOption option">
<td class="prefix"></td>
<td><img src=${favIconUrl} /></td>
<td>${winindex}.${tab.index + 1}: ${tab.title}</td>
<td>${this.value}: ${tab.title}</td>
<td><a class="url" target="_blank" href=${tab.url}>${
tab.url
}</a></td>
@ -51,17 +51,17 @@ export class BufferAllCompletionSource extends Completions.CompletionSourceFuse
return a.windowId - b.windowId
})
// Window Ids don't make sense so we're using LASTID and IDCOUNT to compute a window index
// Window Ids don't make sense so we're using LASTID and WININDEX to compute a window index
// This relies on the fact that tabs are sorted by window ids
let lastId = 0
let index = 0
let winindex = 0
for (const tab of tabs) {
if (lastId != tab.windowId) {
lastId = tab.windowId
index += 1
winindex += 1
}
options.push(
new BufferAllCompletionOption(tab.id.toString(), tab, index),
new BufferAllCompletionOption(tab.id.toString(), tab, winindex),
)
}

View file

@ -1977,17 +1977,21 @@ export async function buffer(index: number | "#") {
/** Change active tab.
@param id
The id of the tab that should be selected.
A string following the following format: "[0-9]+.[0-9]+", the first number being the index of the window that should be selected and the second one being the index of the tab within that window.
This is different from [[buffer]] because `id` is the internal firefox id of the tab, this means that you can focus tabs that aren't in the current window.
*/
//#background
export async function bufferall(id: number) {
if (id === null || id === undefined) {
id = (await activeTab()).id
export async function bufferall(id: string) {
let windows = (await browser.windows.getAll()).map(w => w.id).sort()
if (id === null || id === undefined || !id.match(/\d+\.\d+/)) {
const tab = await activeTab()
let prevId = id
id = windows.indexOf(tab.windowId) + "." + (tab.index + 1)
logger.info(`bufferall: Bad tab id: ${prevId}, defaulting to ${id}`)
}
await browser.windows.update((await browser.tabs.get(id)).windowId, { focused: true })
await browser.tabs.update(id, { active: true })
let [winindex, tabindex] = id.split(".")
await browser.windows.update(windows[parseInt(winindex) - 1], { focused: true })
return browser.tabs.update(await idFromIndex(tabindex), { active: true })
}
// }}}