2018-04-13 19:28:03 +01:00
|
|
|
import { messageActiveTab } from "./messaging"
|
2017-11-08 23:20:41 +00:00
|
|
|
|
|
|
|
async function pushKey(key) {
|
2018-04-13 19:28:03 +01:00
|
|
|
return await messageActiveTab("hinting_content", "pushKey", [key])
|
2017-11-08 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function selectFocusedHint() {
|
2018-04-13 19:28:03 +01:00
|
|
|
return await messageActiveTab("hinting_content", "selectFocusedHint")
|
2017-11-08 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function reset() {
|
2018-04-13 19:28:03 +01:00
|
|
|
return await messageActiveTab("hinting_content", "reset")
|
2017-11-08 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 22:51:53 +00:00
|
|
|
|
2017-11-27 14:43:01 +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"
|
|
|
|
|
2018-04-13 19:28:03 +01:00
|
|
|
import { MsgSafeKeyboardEvent } from "./msgsafe"
|
2017-11-09 00:41:07 +00:00
|
|
|
|
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
|
|
|
*/
|
2017-11-09 00:41:07 +00:00
|
|
|
export function parser(keys: MsgSafeKeyboardEvent[]) {
|
2017-11-08 23:20:41 +00:00
|
|
|
const key = keys[0].key
|
2018-04-13 19:28:03 +01:00
|
|
|
if (key === "Escape") {
|
2017-11-08 23:20:41 +00:00
|
|
|
reset()
|
2018-04-13 19:28:03 +01:00
|
|
|
} 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])
|
|
|
|
}
|
2018-04-13 19:28:03 +01:00
|
|
|
return { keys: [], ex_str: "" }
|
2017-11-08 23:20:41 +00:00
|
|
|
}
|