lang/js/ KeyboardShortcutHandler


const shortcuts = new Map()
shortcuts.set("S-l",e => {
  console.log("hello")
})
shortcuts.set("C-S-k",e => {
  console
  console.log("world")
})
addEventListener("load",_ => {
  addEventListener("keydown", e => {
    let t = e.key.toLowerCase()
    if( t === "control" || t === "shift" || t === "alt" || t === "meta" ) return true
    // in order: M-A-C-S -- Meta Alt Ctrl Shift (Win=Cmd=Meta, Option=Alt) -- homage to EMACS
    if( e.shiftKey ) t = "S-"+t
    if( e.ctrlKey ) t = "C-"+t
    if( e.altKey ) t = "A-"+t
    if( e.metaKey ) t = "M-"+t
    if( t === "C-r" ) return true
    let ae = document.activeElement.tagName.toLowerCase()
    if( ( ae == "textarea" || ae == "input" ) && ! ( e.ctrlKey | e.altKey | e.metaKey ) ) {
      // if typing into a textarea or input, ignore keys unless ctrl alt or meta is held
      return true
    }
    if( shortcuts.has(t) ) { return shortcuts.get(t)(e) }
  })
})