hallo
Der folgende Code wird bei jedem Keydown Event (auf body registriert) ausgeführt:
var bindings={
"7:ArrowDown":"MOVE_SELECTED_LINES_DOWN",
"7:ArrowUp":"MOVE_SELECTED_LINES_UP",
"7:ArrowLeft":"OUTDENT_SELECTED_LINES",
"7:ArrowRight":"INDENT_SELECTED_LINES",
"1:Tab":"INSERT_TAB",
"4:u":"SELECT_URL_BAR",
"4: ":"SELECT_TEXTAREA",
"4:h":"OPEN_HELP",
"4:m":"OPEN_MENU_MORE",
"4:-":"SELECT_MENU_SECTION",
"4:p":"UPDATE_PREVIEW",
"5:<":"INPUT_HTML_ELEMENT",
"5:f":"OPEN_SEARCH_DIALOG",
"5:d":"DUPLICATE_SELECTED_LINES",
"5:e":"ENCODE_HTML",
};
var keyFunction={
"ENCODE_HTML":function(){
alert("ENCODE_HTML")
},
};
function keyController(ev, code){
//console.log(ev);
code = 0
+ (ev.target == ta ? 1 : 0)
+ (ev.shiftKey ? 2 : 0)
+ (ev.ctrlKey ? 4 : 0)
+ (ev.altKey ? 8 : 0);
code += ":" + ev.key;
if( bindings[code] !== undefined ){
//console.log(code);
ev.preventDefault();
ev.stopPropagation();
keyFunction[bindings[code]]();
}
}
~~~
Die Funktion soll möglichst performant sein.
Hat jemand eine Verbesserungsidee?
--
<https://beat-stoecklin.ch/pub/index.html>