mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Fix #3364: add tabsort
command
This commit is contained in:
parent
2787a36dcb
commit
6377634fb7
1 changed files with 21 additions and 0 deletions
|
@ -90,6 +90,7 @@ import * as Native from "@src/lib/native"
|
|||
import * as TTS from "@src/lib/text_to_speech"
|
||||
import * as excmd_parser from "@src/parsers/exmode"
|
||||
import * as escape from "@src/lib/escape"
|
||||
import * as R from "ramda"
|
||||
|
||||
/**
|
||||
* This is used to drive some excmd handling in `composite`.
|
||||
|
@ -2655,6 +2656,26 @@ export async function tabmove(index = "$") {
|
|||
return browser.tabs.move(aTab.id, { index: newindex })
|
||||
}
|
||||
|
||||
/**
|
||||
* Move tabs in current window according to various criteria:
|
||||
*
|
||||
* - `--containers` groups tabs by containers
|
||||
* - `--title` sorts tabs by title
|
||||
* - `--url` sorts tabs by url (the default)
|
||||
* - `(tab1, tab2) => true|false`
|
||||
* - sort by arbitrary comparison function. `tab{1,2}` are objects with properties described here: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/Tab
|
||||
*/
|
||||
//#background
|
||||
export async function tabsort(...callbackchunks: string[]) {
|
||||
const argument = callbackchunks.join(" ")
|
||||
const comparator = argument == "--containers" ? (l, r) => l.cookieStoreId < r.cookieStoreId : argument == "--title" ? (l, r) => l.title < r.title : argument == "--url" || argument == "" ? (l, r) => l.url < r.url : eval(argument)
|
||||
const windowTabs = await browser.tabs.query({ currentWindow: true })
|
||||
windowTabs.sort(comparator)
|
||||
R.forEachObjIndexed((tab, index) => {
|
||||
browser.tabs.move((tab as browser.tabs.Tab).id, { index: parseInt(index as string) })
|
||||
}, windowTabs)
|
||||
}
|
||||
|
||||
/** Pin the current tab */
|
||||
//#background
|
||||
export async function pin() {
|
||||
|
|
Loading…
Add table
Reference in a new issue