Merge branch 'master' of https://github.com/Azgaar/Fantasy-Map-Generator into charts-overview

This commit is contained in:
Azgaar 2022-06-23 23:29:43 +03:00
commit c1ee0b3094
4 changed files with 47 additions and 13 deletions

View file

@ -4,6 +4,8 @@ document.addEventListener("keydown", handleKeydown);
document.addEventListener("keyup", handleKeyup);
function handleKeydown(event) {
if (!allowHotkeys()) return; // in some cases (e.g. in a textarea) hotkeys are not allowed
const {code, ctrlKey, altKey} = event;
if (altKey && !ctrlKey) event.preventDefault(); // disallow alt key combinations
if (ctrlKey && ["KeyS", "KeyC"].includes(code)) event.preventDefault(); // disallow CTRL + S and CTRL + C
@ -12,11 +14,8 @@ function handleKeydown(event) {
function handleKeyup(event) {
if (!modules.editors) return; // if editors are not loaded, do nothing
if (!allowHotkeys()) return; // in some cases (e.g. in a textarea) hotkeys are not allowed
const {tagName, contentEditable} = document.activeElement;
if (["INPUT", "SELECT", "TEXTAREA"].includes(tagName)) return; // don't trigger if user inputs text
if (tagName === "DIV" && contentEditable === "true") return; // don't trigger if user inputs a text
if (document.getSelection().toString()) return; // don't trigger if user selects text
event.stopPropagation();
const {code, key, ctrlKey, metaKey, shiftKey, altKey} = event;
@ -110,6 +109,14 @@ function handleKeyup(event) {
else if (ctrl) toggleMode();
}
function allowHotkeys() {
const {tagName, contentEditable} = document.activeElement;
if (["INPUT", "SELECT", "TEXTAREA"].includes(tagName)) return false;
if (tagName === "DIV" && contentEditable === "true") return false;
if (document.getSelection().toString()) return false;
return true;
}
function pressNumpadSign(key) {
const change = key === "+" ? 1 : -1;
let brush = null;