Add reverse option for findnext for better reverse finding

With the reverse option, we can do inverse findnext with number prefix.
This commit also import minimist as arguments parsing library.
This commit is contained in:
gholk 2022-08-24 22:07:58 +08:00
parent 090858e16b
commit 8e3d023cde
2 changed files with 26 additions and 17 deletions

View file

@ -18,6 +18,7 @@
"editor-adapter": "^0.0.3", "editor-adapter": "^0.0.3",
"esbuild": "^0.14.47", "esbuild": "^0.14.47",
"fuse.js": "^6.6.2", "fuse.js": "^6.6.2",
"minimist": "^1.2.6",
"nearley": "^2.20.1", "nearley": "^2.20.1",
"ramda": "^0.28.0", "ramda": "^0.28.0",
"semver-compare": "^1.0.0", "semver-compare": "^1.0.0",

View file

@ -96,6 +96,7 @@ import semverCompare from "semver-compare"
import * as hint_util from "@src/lib/hint_util" import * as hint_util from "@src/lib/hint_util"
import { OpenMode } from "@src/lib/hint_util" import { OpenMode } from "@src/lib/hint_util"
import * as Proxy from "@src/lib/proxy" import * as Proxy from "@src/lib/proxy"
import minimist from "minimist"
/** /**
* This is used to drive some excmd handling in `composite`. * This is used to drive some excmd handling in `composite`.
@ -1460,15 +1461,17 @@ export function find(...args: string[]) {
//#content //#content
export function findnext(...args: string[]) { export function findnext(...args: string[]) {
let n = 1 let n = 1
let searchFromView = false const option = minimist(args, {
if (args.length > 0) { boolean: Array.from("fr"),
if (args[0] == '-f' || args[0] == '--search-from-view') { alias: {
searchFromView = true f: ["search-from-view", "searchFromView"],
args.shift() r: "reverse",
} },
if (args.length > 0) n = Number(args[0]) default: { f: false, r: false },
} })
return finding.jumpToNextMatch(n, searchFromView) if (option._.length > 0) n = Number(option._[0])
if (option.reverse) n = -n
return finding.jumpToNextMatch(n, option.searchFromView)
} }
//#content //#content
@ -2314,7 +2317,7 @@ if (fullscreenApiIsPrefixed) {
/** @hidden */ /** @hidden */
//#content //#content
export async function loadaucmds(cmdType: "DocStart" | "DocLoad" | "DocEnd" | "TabEnter" | "TabLeft" | "FullscreenEnter" | "FullscreenLeft" | "FullscreenChange" | "UriChange" | "HistoryState" ) { export async function loadaucmds(cmdType: "DocStart" | "DocLoad" | "DocEnd" | "TabEnter" | "TabLeft" | "FullscreenEnter" | "FullscreenLeft" | "FullscreenChange" | "UriChange" | "HistoryState") {
const aucmds = await config.getAsync("autocmds", cmdType) const aucmds = await config.getAsync("autocmds", cmdType)
const ausites = Object.keys(aucmds) const ausites = Object.keys(aucmds)
const aukeyarr = ausites.filter(e => window.document.location.href.search(e) >= 0) const aukeyarr = ausites.filter(e => window.document.location.href.search(e) >= 0)
@ -2727,7 +2730,7 @@ export async function tabopen_helper({ addressarr = [], waitForDom = false }): P
const aucon = new AutoContain() const aucon = new AutoContain()
if (!container && aucon.autocontainConfigured()) { if (!container && aucon.autocontainConfigured()) {
const [autoContainer, ] = await aucon.getAuconAndProxiesForUrl(address) const [autoContainer] = await aucon.getAuconAndProxiesForUrl(address)
if (autoContainer && autoContainer !== "firefox-default") { if (autoContainer && autoContainer !== "firefox-default") {
container = autoContainer container = autoContainer
logger.debug("tabopen setting container automatically using autocontain directive") logger.debug("tabopen setting container automatically using autocontain directive")
@ -3423,11 +3426,16 @@ export async function tgroupcreate(name: string) {
await tabopen(initialUrl) await tabopen(initialUrl)
promises.push(tgroupTabs(name, true).then(tabs => browserBg.tabs.hide(tabs.map(tab => tab.id)))) promises.push(tgroupTabs(name, true).then(tabs => browserBg.tabs.hide(tabs.map(tab => tab.id))))
} else { } else {
promises.push(browser.tabs.query({currentWindow: true}).then((tabs) => { promises.push(
setTabTgroup(name, tabs.map(({ id }) => id)) browser.tabs.query({ currentWindow: true }).then(tabs => {
setTabTgroup(
name,
tabs.map(({ id }) => id),
)
// trigger status line update // trigger status line update
setContentStateGroup(name) setContentStateGroup(name)
})) }),
)
promises.push(setWindowTgroup(name)) promises.push(setWindowTgroup(name))
} }
@ -3446,7 +3454,7 @@ export async function tgroupcreate(name: string) {
*/ */
//#background //#background
export async function tgroupswitch(name: string) { export async function tgroupswitch(name: string) {
if (name == await windowTgroup()) { if (name == (await windowTgroup())) {
throw new Error(`Already on tab group "${name}"`) throw new Error(`Already on tab group "${name}"`)
} }