From 41e239654b4652417aec3b9645b2360557842418 Mon Sep 17 00:00:00 2001
From: gdh1995
Date: Sun, 4 Apr 2021 01:50:22 +0800
Subject: [PATCH] add vimium://sed, sed-p and sed2
Usages:
* sed `context-keys: /^[#$]?[a-z]+$/` text (without default contexts)
* sed `rule: s/.../.../flags` text (without static rules)
* `sed-p|sed.p` context-keys|rule text (with a default context of `paste`)
* sed2 rule context-keys text (without default contexts)
It can be used on Vomnibar to do simple string replacement / preview seding
---
background/utils.ts | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/background/utils.ts b/background/utils.ts
index fae985de2..be9fdcb3d 100644
--- a/background/utils.ts
+++ b/background/utils.ts
@@ -477,6 +477,21 @@ var BgUtils_ = {
arr = arr[0].split(a.spacesRe_);
}
break;
+ case "sed": case "substitute": case "sed-p": case "sed.p": case "sed2":
+ const first = path.split(" ", 1)[0]
+ path = path.slice(first.length + 1).trim()
+ const second = cmd === "sed2" ? path.split(" ", 1)[0] : ""
+ path = path.slice(second.length).trim()
+ path = path && a.sed_(path, cmd.endsWith("p") ? SedContext.paste : SedContext.NONE,
+ second ? { r: first, k: second }
+ : ( /^[@#$-]?[a-z]+$|^\.$/).test(first) ? { r: null, k: first } : { r: first, k: null } )
+ return [path, Urls.kEval.paste]
+ case "sed2":
+ cmd = path.split(" ", 1)[0]
+ path = cmd.length === path.length ? ""
+ : a.sed_(path.slice(cmd.length + 1).trim(), SedContext.NONE
+ , ( /^[@#$-]?[a-z]+$|^\.$/).test(cmd) ? { r: null, k: cmd } : { r: cmd, k: null } )
+ return [path, Urls.kEval.paste]
case "u": case "url": case "search":
// here path is not empty, and so `decodeEscapedURL(path).trim()` is also not empty
arr = a.decodeEscapedURL_(path).split(a.spacesRe_);