Switch to KeyboardEvent.code rather than KeyboardEvent.which, which is deprecated

This commit is contained in:
Henrik Giesel 2021-01-16 20:23:46 +01:00
parent 318cc01c73
commit a898224d3d

View file

@ -50,13 +50,13 @@ interface Selection {
function onKey(evt: KeyboardEvent) { function onKey(evt: KeyboardEvent) {
// esc clears focus, allowing dialog to close // esc clears focus, allowing dialog to close
if (evt.which === 27) { if (evt.code === "Escape") {
currentField.blur(); currentField.blur();
return; return;
} }
// prefer <br> instead of <div></div> // prefer <br> instead of <div></div>
if (evt.which === 13 && !inListItem()) { if (evt.code === "Enter" && !inListItem()) {
evt.preventDefault(); evt.preventDefault();
document.execCommand("insertLineBreak"); document.execCommand("insertLineBreak");
return; return;
@ -73,11 +73,11 @@ function onKey(evt: KeyboardEvent) {
if (evt.shiftKey) { if (evt.shiftKey) {
alter = "extend"; alter = "extend";
} }
if (evt.which === 39) { if (evt.code === "ArrowRight") {
selection.modify(alter, "right", granularity); selection.modify(alter, "right", granularity);
evt.preventDefault(); evt.preventDefault();
return; return;
} else if (evt.which === 37) { } else if (evt.code === "ArrowLeft") {
selection.modify(alter, "left", granularity); selection.modify(alter, "left", granularity);
evt.preventDefault(); evt.preventDefault();
return; return;
@ -89,7 +89,7 @@ function onKey(evt: KeyboardEvent) {
function onKeyUp(evt: KeyboardEvent) { function onKeyUp(evt: KeyboardEvent) {
// Avoid div element on remove // Avoid div element on remove
if (evt.which === 8 || evt.which === 13) { if (evt.code === "Enter" || evt.code === "Backspace") {
const anchor = window.getSelection().anchorNode; const anchor = window.getSelection().anchorNode;
if ( if (