keydown: Make normal mode suppression more predictable

This commit is contained in:
Colin Caine 2017-11-19 03:33:15 +00:00
parent 23f064a9bc
commit 17cff21b8d

View file

@ -27,11 +27,16 @@ function suppressKey(ke: KeyboardEvent) {
import state from './state'
// Keys not to suppress in normal mode.
const normalmodewhitelist = ['/']
function TerribleModeSpecificSuppression(ke: KeyboardEvent) {
switch (state.mode) {
case "normal":
// StartsWith happens to work for our maps so far. Obviously won't in the future.
if (Object.getOwnPropertyNames(nmaps).find((map) => map.startsWith(ke.key))) {
/* if (Object.getOwnPropertyNames(nmaps).find((map) => map.startsWith(ke.key))) { */
if (! ke.ctrlKey && ! ke.metaKey && ! ke.altKey && ! normalmodewhitelist.includes(ke.key)) {
ke.preventDefault()
ke.stopImmediatePropagation()
}
@ -47,63 +52,6 @@ function TerribleModeSpecificSuppression(ke: KeyboardEvent) {
}
}
// Normal-mode mappings.
// keystr -> ex_str
// TODO: Move these into a tridactyl-wide state namespace
// TODO: stop stealing keys from "insert mode"
// r -> refresh page is particularly unhelpful
// Can't stringify a map -> just use an object
let nmaps = {
"o": "fillcmdline open",
"O": "current_url open",
"w": "fillcmdline winopen",
"W": "current_url winopen",
"t": "tabopen",
//["t": "fillcmdline tabopen", // for now, use mozilla completion
"]]": "clicknext",
"[[": "clicknext prev",
"T": "current_url tabopen",
"yy": "clipboard yank",
"p": "clipboard open",
"P": "clipboard tabopen",
"j": "scrollline 10",
"k": "scrollline -10",
"h": "scrollpx -50",
"l": "scrollpx 50",
"G": "scrollto 100",
"gg": "scrollto 0",
"H": "back",
"L": "forward",
"d": "tabclose",
"u": "undo",
"r": "reload",
"R": "reloadhard",
"gt": "tabnext",
"gT": "tabprev",
"gr": "reader",
":": "fillcmdline",
"s": "fillcmdline open google",
"S": "fillcmdline tabopen google",
"xx": "something",
"b": "openbuffer",
"ZZ": "qall",
"f": "hint",
"F": "hint -b",
"I": "mode ignore",
// Special keys must be prepended with 🄰
// ["🄰Backspace", "something"],
}
// Allow config to be changed in settings
// TODO: make this more general
browser.storage.sync.get("nmaps").then(lazyloadconfig)
async function lazyloadconfig(config_obj){
let nmaps_config = config_obj["nmaps"]
nmaps_config = (nmaps_config == undefined) ? {} : nmaps_config
nmaps = Object.assign(nmaps, nmaps_config)
console.log(nmaps)
}
// }}}
// Add listeners