editor: Prevent default browser action for keybinds when textarea is foccused

This commit is contained in:
Eragon 2023-05-15 12:40:17 +02:00
parent ed1a534aa6
commit f15186d4f8
Signed by: Eragon
GPG Key ID: 087126EBFC725006
1 changed files with 15 additions and 6 deletions

View File

@ -336,12 +336,15 @@ ta.addEventListener('keydown', function(e) {
e.target.selectionEnd = start + 1;
}
// TODO
// Ctrl+B adds bold
// Ctrl+I adds italic
// Ctrl+U adds underline
// Ctrl+Enter send the form
/*
* Keybindings for buttons. The default action of the keybinding is prevented.
* Ctrl+B adds bold
* Ctrl+I adds italic
* Ctrl+U adds underline
* Ctrl+S adds strikethrough
* Ctrl+H adds Header +1
* Ctrl+Enter send the form
*/
if (e.ctrlKey) {
switch (keyCode) {
case 13:
@ -354,21 +357,27 @@ ta.addEventListener('keydown', function(e) {
} catch(exception) {
t.submit.click();
}
e.preventDefault();
break;
case 66: // B
editor_inline(e, "bold", false);
e.preventDefault();
break;
case 72: // H
editor_title(e, 0, +1);
e.preventDefault();
break;
case 73: // I
editor_inline(e, "italic", false);
e.preventDefault();
break;
case 83: // S
editor_inline(e, "strike", false);
e.preventDefault();
break;
case 85: // U
editor_inline(e, "underline", false);
e.preventDefault();
break;
}
}