tridactyl/src/hinting_background.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

import { messageActiveTab } from "./messaging"
2017-11-08 23:20:41 +00:00
async function pushKey(key) {
return await messageActiveTab("hinting_content", "pushKey", [key])
2017-11-08 23:20:41 +00:00
}
async function selectFocusedHint() {
return await messageActiveTab("hinting_content", "selectFocusedHint")
2017-11-08 23:20:41 +00:00
}
async function reset() {
return await messageActiveTab("hinting_content", "reset")
2017-11-08 23:20:41 +00:00
}
/** Type for "hint save" actions:
* - "link": elements that point to another resource (eg
* links to pages/files) - the link target is saved
* - "img": image elements
*/
export type HintSaveType = "link" | "img"
import { MsgSafeKeyboardEvent } from "./msgsafe"
2017-11-08 23:20:41 +00:00
/** At some point, this might be turned into a real keyseq parser
2017-11-19 07:57:30 +00:00
reset and selectFocusedHints are OK candidates for map targets in the
future. pushKey less so, I think.
2017-11-08 23:20:41 +00:00
*/
export function parser(keys: MsgSafeKeyboardEvent[]) {
2017-11-08 23:20:41 +00:00
const key = keys[0].key
if (key === "Escape") {
2017-11-08 23:20:41 +00:00
reset()
} else if (["Enter", " "].includes(key)) {
2017-11-19 07:57:30 +00:00
selectFocusedHint()
2017-11-08 23:20:41 +00:00
} else {
pushKey(keys[0])
}
return { keys: [], ex_str: "" }
2017-11-08 23:20:41 +00:00
}