From 0f88d520ed05281994672c7d7740e23f3812ccfe Mon Sep 17 00:00:00 2001 From: somebody Date: Mon, 24 Jul 2023 21:45:52 -0500 Subject: [PATCH] UI: Replace shift_down code with builtin event.shiftKey Keeping a global variable that tracks shift is worse because it can get desynced if you leave the window while holding shift (which apparently happens a lot more than you would think) --- static/koboldai.js | 59 ++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index f775f3f0..242b77e0 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -58,7 +58,6 @@ var rename_return_emit_name = "popup_rename"; var popup_rows = []; var popup_style = ""; var popup_sort = {}; -var shift_down = false; var world_info_data = {}; var world_info_folder_data = {}; var saved_settings = {}; @@ -4925,49 +4924,44 @@ function getCookie(cname, default_return=null) { } function detect_enter_submit(e) { - if (((e.code == "Enter") || (e.code == "NumpadEnter")) && !(shift_down)) { - if (typeof e.stopPropagation != "undefined") { - e.stopPropagation(); - } else { - e.cancelBubble = true; - } - //console.log("submitting"); - document.getElementById("btnsubmit").onclick(); - setTimeout(function() {document.getElementById('input_text').value = '';}, 1); + if (e.shiftKey) return; + if (!["Enter", "NumpadEnter"].includes(e.key)) return; + + if (typeof e.stopPropagation != "undefined") { + e.stopPropagation(); + } else { + e.cancelBubble = true; } + + //console.log("submitting"); + document.getElementById("btnsubmit").onclick(); + setTimeout(function() {document.getElementById('input_text').value = '';}, 1); } function detect_enter_text(e) { - if (((e.code == "Enter") || (e.code == "NumpadEnter")) && !(shift_down)) { - if (typeof e.stopPropagation != "undefined") { - e.stopPropagation(); - } else { - e.cancelBubble = true; - } - //get element - //console.log("Doing Text Enter"); - //console.log(e.currentTarget.activeElement); - if (e.currentTarget.activeElement != undefined) { - var item = $(e.currentTarget.activeElement); - item.onchange(); - } + if (e.shiftKey) return; + if (!["Enter", "NumpadEnter"].includes(e.key)) return; + + if (typeof e.stopPropagation != "undefined") { + e.stopPropagation(); + } else { + e.cancelBubble = true; + } + //get element + //console.log("Doing Text Enter"); + //console.log(e.currentTarget.activeElement); + if (e.currentTarget.activeElement != undefined) { + var item = $(e.currentTarget.activeElement); + item.onchange(); } } function detect_key_down(e) { - if ((e.code == "ShiftLeft") || (e.code == "ShiftRight")) { - shift_down = true; - } else if (e.code == "Escape") { + if (e.code == "Escape") { close_menus(); } } -function detect_key_up(e) { - if ((e.code == "ShiftLeft") || (e.code == "ShiftRight")) { - shift_down = false; - } -} - function selectTab(tab) { let tabTarget = document.getElementById(tab.getAttribute("tab-target")); let tabClass = Array.from(tab.classList).filter((c) => c.startsWith("tab-"))[0]; @@ -5935,7 +5929,6 @@ function openClubImport() { //// INIT //// document.onkeydown = detect_key_down; -document.onkeyup = detect_key_up; document.getElementById("input_text").onkeydown = detect_enter_submit; /* -- Popups -- */