Skip to content

Commit

Permalink
support vimium://status toggle ["^" ...hooked-keys]
Browse files Browse the repository at this point in the history
so a same key may be used to "disable" Vimium C and then re-enable it.
* here the action "disable" will set passKeys to the "only-hooked" mode

as said in point #2 of
#55 (comment)
  • Loading branch information
gdh1995 committed Jul 26, 2019
1 parent c3016c6 commit d4bcafc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion background/bg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ declare namespace Urls {

declare namespace Frames {
type ValidStatus = Status.enabled | Status.partial | Status.disabled;
type ForcedStatusText = "reset" | "enable" | "disable" | "toggle";
type ForcedStatusText = "reset" | "enable" | "disable" | "toggle" | "next";

interface Sender {
/** frameId */ readonly i: number;
Expand Down
19 changes: 16 additions & 3 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2732,15 +2732,28 @@ Are you sure you want to continue?`) ? count
const ref = framesForTab[tabId || (tabId = TabRecency_.last_)];
if (!ref) { return; }
act = act.toLowerCase() as Frames.ForcedStatusText;
let spaceInd = act.indexOf(" "), newPassedKeys = spaceInd > 0 ? act.slice(spaceInd + 1) : "";
if (spaceInd > 0) {
act = act.slice(0, spaceInd) as Frames.ForcedStatusText;
}
if (newPassedKeys && !newPassedKeys.startsWith("^ ")) {
console.log('"vimium://status" only accepts a list of hooked keys');
newPassedKeys = "";
}
const always_enabled = Exclusions == null || Exclusions.rules_.length <= 0, oldStatus = ref[0].s.s,
stat = act === "enable" ? Frames.Status.enabled : act === "disable" ? Frames.Status.disabled
: act === "toggle" ? oldStatus !== Frames.Status.enabled ? Frames.Status.enabled : Frames.Status.disabled
: act === "toggle" || act === "next"
? oldStatus !== Frames.Status.enabled ? Frames.Status.enabled : Frames.Status.disabled
: null,
locked = stat !== null, unknown = !(locked || always_enabled),
msg: Req.bg<kBgReq.reset> = { N: kBgReq.reset, p: stat !== Frames.Status.disabled ? null : "", f: locked };
msg: Req.bg<kBgReq.reset> = {
N: kBgReq.reset,
p: stat !== Frames.Status.disabled ? null : newPassedKeys,
f: locked
};
cPort = indexFrame(tabId, 0) || ref[0];
if (stat === null && tabId < 0) {
oldStatus !== Frames.Status.disabled && this.showHUD_("Got an unknown action on status: " + act);
oldStatus !== Frames.Status.disabled && this.showHUD_("Got an unknown action of status: " + act);
return;
}
let pattern: string | null, newStatus = locked ? stat as Frames.ValidStatus : Frames.Status.enabled;
Expand Down

0 comments on commit d4bcafc

Please sign in to comment.