From 8e3d023cde7314be1cdc48e058afab552067c460 Mon Sep 17 00:00:00 2001 From: gholk Date: Wed, 24 Aug 2022 22:07:58 +0800 Subject: [PATCH] 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. --- package.json | 1 + src/excmds.ts | 42 +++++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 1e12cac1..a726c427 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "editor-adapter": "^0.0.3", "esbuild": "^0.14.47", "fuse.js": "^6.6.2", + "minimist": "^1.2.6", "nearley": "^2.20.1", "ramda": "^0.28.0", "semver-compare": "^1.0.0", diff --git a/src/excmds.ts b/src/excmds.ts index b33d3874..b4a14875 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -96,6 +96,7 @@ import semverCompare from "semver-compare" import * as hint_util from "@src/lib/hint_util" import { OpenMode } from "@src/lib/hint_util" import * as Proxy from "@src/lib/proxy" +import minimist from "minimist" /** * This is used to drive some excmd handling in `composite`. @@ -1460,15 +1461,17 @@ export function find(...args: string[]) { //#content export function findnext(...args: string[]) { let n = 1 - let searchFromView = false - if (args.length > 0) { - if (args[0] == '-f' || args[0] == '--search-from-view') { - searchFromView = true - args.shift() - } - if (args.length > 0) n = Number(args[0]) - } - return finding.jumpToNextMatch(n, searchFromView) + const option = minimist(args, { + boolean: Array.from("fr"), + alias: { + f: ["search-from-view", "searchFromView"], + r: "reverse", + }, + default: { f: false, r: false }, + }) + if (option._.length > 0) n = Number(option._[0]) + if (option.reverse) n = -n + return finding.jumpToNextMatch(n, option.searchFromView) } //#content @@ -2314,7 +2317,7 @@ if (fullscreenApiIsPrefixed) { /** @hidden */ //#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 ausites = Object.keys(aucmds) 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() if (!container && aucon.autocontainConfigured()) { - const [autoContainer, ] = await aucon.getAuconAndProxiesForUrl(address) + const [autoContainer] = await aucon.getAuconAndProxiesForUrl(address) if (autoContainer && autoContainer !== "firefox-default") { container = autoContainer logger.debug("tabopen setting container automatically using autocontain directive") @@ -3423,11 +3426,16 @@ export async function tgroupcreate(name: string) { await tabopen(initialUrl) promises.push(tgroupTabs(name, true).then(tabs => browserBg.tabs.hide(tabs.map(tab => tab.id)))) } else { - promises.push(browser.tabs.query({currentWindow: true}).then((tabs) => { - setTabTgroup(name, tabs.map(({ id }) => id)) - // trigger status line update - setContentStateGroup(name) - })) + promises.push( + browser.tabs.query({ currentWindow: true }).then(tabs => { + setTabTgroup( + name, + tabs.map(({ id }) => id), + ) + // trigger status line update + setContentStateGroup(name) + }), + ) promises.push(setWindowTgroup(name)) } @@ -3446,7 +3454,7 @@ export async function tgroupcreate(name: string) { */ //#background export async function tgroupswitch(name: string) { - if (name == await windowTgroup()) { + if (name == (await windowTgroup())) { throw new Error(`Already on tab group "${name}"`) }