Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
* make options names shorter
* deprecate those options names with "_"
* fix outdated info in readme
  • Loading branch information
gdh1995 committed Jan 7, 2020
1 parent 6f457d8 commit 7892a8d
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 44 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ and please read https://github.com/gdh1995/vimium-c/wiki/Known-issues-on-various
If you want to compile this project manually, please run:

``` bash
npm install typescript@3.4.3
node scripts/tsc all
#./scripts/make.sh output-file.zip
npm install typescript@3.7.4
npm install pngjs # needed for Chromium-based browsers
node scripts/tsc
# ./scripts/make.sh released-file.zip
```

`gulp local` can also compile files in place (using configurable build options),
Expand Down
4 changes: 2 additions & 2 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"message": "Close N tab(s)"
},
"removeTab_p": {
"message": "allow_close, goto=\"\"/left/right/previous"
"message": "mayClose, goto=\"\"/left/right/previous"
},
"restoreTab": {
"message": "Restore closed tab(s)"
Expand Down Expand Up @@ -279,7 +279,7 @@
"message": "Go up the URL hierarchy"
},
"goUp_p": {
"message": "trailing_slash=null/true/false"
"message": "trailingSlash=null/true/false"
},
"lastTab": {
"message": "Go to the last N-th tab"
Expand Down
25 changes: 12 additions & 13 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,15 +1144,15 @@
hud = cOptions.hideHUD != null ? !cOptions.hideHUD : cOptions.hideHud != null ? !cOptions.hideHud
: !Settings_.cache_.hideHud;
key = key && typeof key === "string" ? key : null;
code = key ? kKeyCode.esc : stat !== KeyStat.plain ? code || kKeyCode.esc : code === kKeyCode.esc ? 0 : code;
code = key ? kKeyCode.True : stat !== KeyStat.plain ? code || kKeyCode.esc : code === kKeyCode.esc ? 0 : code;
cPort.postMessage<1, kFgCmd.insertMode>({ N: kBgReq.execute,
S: hud ? ensureInnerCSS(cPort) : null,
c: kFgCmd.insertMode,
n: 1,
a: {
code, stat, key,
passExitKey: !!cOptions.passExitKey,
hud
c: code, s: stat, k: key,
p: !!cOptions.passExitKey,
h: hud ? [trans_("" + kTip.globalInsertMode, [code ? ": " + (key || code + "/" + stat) : ""])] : null
}
});
},
Expand Down Expand Up @@ -1562,7 +1562,7 @@
}
if (noCurrent) { return; }
}
if (count >= total && cOptions.allow_close !== true) {
if (count >= total && (cOptions.mayClose != null ? cOptions.mayClose : cOptions.allow_close) !== true) {
chrome.windows.getAll(removeAllTabsInWnd.bind(null, tab, tabs));
return;
}
Expand Down Expand Up @@ -1850,9 +1850,8 @@
});
},
/* kBgCmd.goToRoot: */ function (this: void, tabs: [Tab]): void {
const trail = cOptions.trailing_slash,
{ p: path, u: url } = requestHandlers[kFgReq.parseUpperUrl]({
t: trail != null ? !!trail : null,
const { p: path, u: url } = requestHandlers[kFgReq.parseUpperUrl]({
t: cOptions.trailingSlash, s: cOptions.trailing_slash,
u: tabs[0].url, p: cRepeat
});
if (path != null) {
Expand All @@ -1862,12 +1861,11 @@
return Backend_.showHUD_(url);
},
/* kBgCmd.goUp: */ function (this: void): void {
const trail = cOptions.trailing_slash;
requireURL({
H: kFgReq.parseUpperUrl,
u: "", // just a hack to make TypeScript compiler happy
p: -cRepeat,
t: trail != null ? !!trail : null,
t: cOptions.trailingSlash, s: cOptions.trailing_slash,
e: true
});
},
Expand Down Expand Up @@ -2220,7 +2218,7 @@
} else if (!hash && url_l.startsWith("ftp:")) {
endSlash = true;
} else {
endSlash = request.t != null ? !!request.t
endSlash = request.t != null ? !!request.t : request.s != null ? !!request.s
: path.length > 1 && path.endsWith("/")
|| (<RegExpI> /\.([a-z]{2,3}|apng|jpeg|tiff)$/i).test(path); // just a try: not include .html
}
Expand Down Expand Up @@ -2449,14 +2447,15 @@
Settings_.fetchFile_("helpDialog", resolve);
})
]).then(function (args): void {
const port2 = request.w && indexFrame(port.s.t, 0) || port;
const port2 = request.w && indexFrame(port.s.t, 0) || port,
options = request.a || {};
(port2.s as Frames.Sender).f |= Frames.Flags.hadHelpDialog;
port2.postMessage({
N: kBgReq.showHelpDialog,
S: ensureInnerCSS(port2),
h: args[0].render_(port2.s.u.startsWith(Settings_.CONST_.OptionsPage_)),
o: Settings_.CONST_.OptionsPage_,
a: request.a || {},
e: !!options.exitOnClick,
c: Settings_.get_("showAdvancedCommands", true)
});
}, Build.NDEBUG ? null : function (args): void {
Expand Down
14 changes: 7 additions & 7 deletions content/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
if (action = K.bubbleEvent_(event)) { /* empty */ }
else if (InsertMode.isActive_()) {
const g = InsertMode.global_;
if (g ? !g.code ? isEscape(event) : !g.key ? key === g.code && K.getKeyStat_(event) === g.stat
: (keyChar = K.char_(event)) && mapKey(keyChar, event) === g.key
if (g ? !g.c ? isEscape(event) : !g.k ? key === g.c && K.getKeyStat_(event) === g.s
: (keyChar = K.char_(event)) && mapKey(keyChar, event) === g.k
: key > kKeyCode.maxNotFn && key < kKeyCode.minNotFn
? (keyChar = K.getKeyName_(event))
&& ((action = checkKey(keyChar, key, event)) & ~HandlerResult.AdvancedEscFlag) === HandlerResult.Esc
Expand All @@ -167,7 +167,7 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
event.repeat && InsertMode.focusUpper_(key, true, event);
action = /* the real is HandlerResult.PassKey; here's for smaller code */ HandlerResult.Nothing;
} else {
action = g && g.passExitKey ? (
action = g && g.p ? (
Build.BTypes & BrowserType.Chrome && checkPotentialAccessKey(event),
HandlerResult.Nothing) : HandlerResult.Prevent;
InsertMode.exit_(event.target as Element);
Expand Down Expand Up @@ -490,9 +490,8 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
1000, [options.n, notBool ? JSON.stringify(val) : ""]);
},
/* kFgCmd.insertMode: */ function (_0: number, opt: CmdOptions[kFgCmd.insertMode]): void {
let { code, stat, key } = opt;
InsertMode.global_ = opt;
if (opt.hud) { HUD.show_(kTip.globalInsertMode, [code ? ": " + (key || code + "/" + stat) : ""]); }
if (opt.h) { HUD.show_(kTip.raw, opt.h); }
},
/* kFgCmd.passNextKey: */ function (count0: number, options: CmdOptions[kFgCmd.passNextKey]): void {
let keyCount = 0, count = Math.abs(count0);
Expand Down Expand Up @@ -1286,7 +1285,8 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
post({ H: kFgReq.cmd, c: request.c, n, i: request.i, r: count2 });
},
/* kBgReq.showHelpDialog: */
function ({ h: html, c: shouldShowAdvanced, o: optionUrl, S: CSS, a: options }: Req.bg<kBgReq.showHelpDialog>): void {
function ({ h: html, c: shouldShowAdvanced, o: optionUrl, S: CSS
, e: exitOnClick }: Req.bg<kBgReq.showHelpDialog>): void {
// Note: not suppress key on the top, because help dialog may need a while to render,
// and then a keyup may occur before or after it
if (CSS) { U.css_(CSS); }
Expand Down Expand Up @@ -1367,7 +1367,7 @@ if (Build.BTypes & BrowserType.Chrome && Build.BTypes & ~BrowserType.Chrome) { v
shouldShowAdvanced && toggleAdvanced();
U.ensureBorder_();
U.add_(box, AdjustType.Normal, true);
options.exitOnClick && U.setupExitOnClick_(1, hide);
exitOnClick && U.setupExitOnClick_(1, hide);
doc.hasFocus() || events.focusAndRun_();
// on FF66, `scrollIntoView` does not set tab-navigation node
// tslint:disable-next-line: no-unused-expression
Expand Down
8 changes: 4 additions & 4 deletions content/vomnibar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare namespace VomnibarNS {
interface ContentOptions extends GlobalOptions {
trailing_slash: boolean;
trailingSlash?: boolean;
trailing_slash?: boolean;
}
interface Port {
postMessage<K extends keyof CReq> (this: Port, msg: CReq[K]): void | 1;
Expand Down Expand Up @@ -124,10 +125,9 @@ var VOmni = {
if (VimiumInjector === null && (window as Window & {VData?: Element | VDataTy}).VData) {
url = VData.getOmni_(url);
}
const trail = options.trailing_slash;
VApi.send_(kFgReq.parseSearchUrl, {
t: trail != null ? !!trail : null,
p: upper, u: url
t: options.trailingSlash, s: options.trailing_slash,
p: upper, u: url
}, function (search): void {
options.p = search;
if (search != null) { options.url = ""; }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"pngjs": "^3.4.0",
"typescript": "^3.7.2"
"typescript": "^3.7.4"
},
"devDependencies": {
"clean-css": "^4.2.1",
Expand Down
9 changes: 4 additions & 5 deletions pages/options_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ Promise.all([ BG_.BgUtils_.require_("Exclusions"),
}

const bgExclusions = BG_.Exclusions as typeof Exclusions,
frameInfo: Frames.Sender = ref ? ref[0].s : {
frameInfo: Frames.Sender = ref && (!ref[0].s.i || BG_.BgUtils_.protocolRe_.test(ref[0].s.u)) ? ref[0].s : {
/** must keep aligned with {@link ../background/main.ts#formatPortSender} */
i: 0,
a: curTab.incognito,
Expand Down Expand Up @@ -707,10 +707,9 @@ Promise.all([ BG_.BgUtils_.require_("Exclusions"),
for (let _i = 0, _len = rules.length; _i < _len; _i++) {
ref1[rules[_i].pattern] = ref2[_i];
}
const sender = ref ? ref[0].s : <Readonly<Frames.Sender>> { s: Frames.Status.enabled, f: Frames.Flags.Default }
, toggleAction = sender.s !== Frames.Status.disabled ? "Disable" : "Enable"
, curIsLocked = !!(sender.f & Frames.Flags.locked);
curLockedStatus = curIsLocked ? sender.s : Frames.Status.__fake;
const toggleAction = frameInfo.s !== Frames.Status.disabled ? "Disable" : "Enable"
, curIsLocked = !!(frameInfo.f & Frames.Flags.locked);
curLockedStatus = curIsLocked ? frameInfo.s : Frames.Status.__fake;
let el0 = $<EnsuredMountedHTMLElement>("#toggleOnce"), el1 = el0.nextElementSibling;
nextTick_(() => {
el0.firstElementChild.textContent = (pTrans_(toggleAction) || toggleAction) + (curIsLocked ? "" : pTrans_("Once"));
Expand Down
10 changes: 10 additions & 0 deletions scripts/chrome2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ else
CHROME_ROOT='/d/Program Files/Google'
VC_ROOT=${VC_ROOT:-${dir%/*}}
fi
if test -z "$VER"; then
VER_MIN=63
for ((i=99;i>=VER_MIN;i--)); do
if test -f "$WORKING_DIR/$i/chrome.exe"; then
VER=$i; break
fi
done
if test -z "$VER" && test -f "$WORKING_DIR"/Chrome-bin/chrome.exe; then
VER=wo
fi
test "$VER" == cur && VER=
if test "$VER" == wo; then
EXE=$WORKING_DIR/Chrome-bin/chrome.exe
Expand Down
8 changes: 8 additions & 0 deletions scripts/firefox2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ else
FIREFOX_ROOT='/r/working'
VC_ROOT=${VC_ROOT:-${dir%/*}}
fi
if test -z "$VER"; then
VER_MIN=63
for ((i=99;i>=VER_MIN;i--)); do
if test -f "$WORKING_DIR/core$i/firefox.exe"; then
VER=$i; break
fi
done
fi
test "$VER" == cur && VER=
if test "$VER" == wo -o -z "$VER"; then
EXE=$WORKING_DIR/core/firefox.exe
Expand Down
2 changes: 1 addition & 1 deletion settings_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"map i focusInput keep select=\"all-line\"",
"map n nextFrame",
"map UU goToRoot",
"map Uu goUp trailing_slash",
"map Uu goUp trailingSlash",
"map Uf parentFrame",
"map N moveTabToNewWindow",
"map I moveTabToIncognito",
Expand Down
15 changes: 8 additions & 7 deletions types/messages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ interface BgReq {
[kBgReq.showHelpDialog]: {
/** html */ h: string | /** for Firefox */ { /** head->style */ h: string; /** body */ b: string; };
/** optionUrl */ o: string;
/** extra args */ a: CmdOptions[kFgCmd.showHelp];
/** exitOnClick */ e: boolean;
/** advanced */ c: boolean;
} & Partial<BgCSSReq>;
[kBgReq.settingsUpdate]: {
Expand Down Expand Up @@ -249,11 +249,11 @@ interface CmdOptions {
/** max of length limit list */ m: number;
};
[kFgCmd.insertMode]: {
key: string | null;
code: kKeyCode;
stat: KeyStat;
passExitKey: boolean;
hud: boolean;
k: string | null;
c: kKeyCode;
s: KeyStat;
p: boolean;
h: [string] | null;
};
[kFgCmd.visualMode]: {
/** mode */ m: VisualModeNS.Mode.Visual | VisualModeNS.Mode.Line | VisualModeNS.Mode.Caret;
Expand Down Expand Up @@ -323,7 +323,8 @@ interface FgReqWithRes {
/** url */ u: string;
/** upper */ p: number;
/** id */ i?: undefined;
/** trailing_slash */ t: boolean | null;
/** trailingSlash */ t: boolean | null | undefined;
/** @deprecated trailingSlash (old) */ s: boolean | null | undefined;
/** execute / e: unknown; */
};
[kFgReq.parseSearchUrl]: {
Expand Down
2 changes: 1 addition & 1 deletion types/vimium_c.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ declare const enum kCharCode {
}

declare const enum kKeyCode {
None = 0,
None = 0, True = 1,
backspace = 8, tab = 9, enter = 13, shiftKey = 16, ctrlKey = 17, altKey = 18, esc = 27,
minAcsKeys = 16, maxAcsKeys = 18,
maxNotPrintable = 32 - 1, space, maxNotPageUp = space, pageup, minNotSpace = pageup,
Expand Down

0 comments on commit 7892a8d

Please sign in to comment.