From 6d77dfbf48713804b6a83b2684f6927d830de87b Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Thu, 20 Apr 2023 23:23:46 +0900 Subject: [PATCH 1/4] uparrow = edit last message in chat ctrl+uparrow = edit last user message removed ctrl+uparrow for autoconnect hotkey --- public/scripts/RossAscends-mods.js | 47 ++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 1833bab7e..fe1dcf748 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -660,21 +660,21 @@ $("document").ready(function () { //Generate("regenerate"); } } - if (event.ctrlKey && event.key == "ArrowUp") { - //Ctrl+UpArrow for Connect to last server - console.log(main_api); - if (online_status === "no_connection") { - if (main_api == "kobold") { - document.getElementById("api_button").click(); - } - if (main_api == "novel") { - document.getElementById("api_button_novel").click(); - } - if (main_api == "textgenerationwebui") { - document.getElementById("api_button_textgenerationwebui").click(); - } - } - } + /* if (event.ctrlKey && event.key == "ArrowUp") { + //Ctrl+UpArrow for Connect to last server + console.log(main_api); + if (online_status === "no_connection") { + if (main_api == "kobold") { + document.getElementById("api_button").click(); + } + if (main_api == "novel") { + document.getElementById("api_button_novel").click(); + } + if (main_api == "textgenerationwebui") { + document.getElementById("api_button_textgenerationwebui").click(); + } + } + } */ if (event.ctrlKey && event.key == "ArrowLeft") { //for debug, show all local stored vars CheckLocal(); } @@ -705,8 +705,25 @@ $("document").ready(function () { $('.swipe_right:last').click(); } } + if (event.key == "ArrowUp") { //edits last message if chatbar is empty and focused console.log('got uparrow input'); + if ( + $("#send_textarea").val() === '' && + isInputElementInFocus("#send_textarea") && + $(".swipe_right:last").css('display') === 'flex' && + $("#character_popup").css("display") === "none" && + $("#shadow_select_chat_popup").css("display") === "none" + ) { + const lastMes = document.querySelector('.last_mes'); + const editMes = lastMes.querySelector('.mes_block .mes_edit'); + if (editMes !== null) { + $(editMes).click(); + } + } + } + if (event.ctrlKey && event.key == "ArrowUp") { //edits last message if chatbar is empty and focused + console.log('got ctrl+uparrow input'); if ( $("#send_textarea").val() === '' && isInputElementInFocus("#send_textarea") && From 516a61a5ee326192f6d137ec6571a2998f4f917b Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Thu, 20 Apr 2023 23:36:48 +0900 Subject: [PATCH 2/4] added proper focus filter to uparrow hotkeys --- public/scripts/RossAscends-mods.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index fe1dcf748..dc0e950e4 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -588,6 +588,17 @@ $("document").ready(function () { } else { SaveLocal('LNavOpened', 'false'); } }); + var chatbarInFocus = false; + $('#send_textarea').focus(function () { + chatbarInFocus = true; + console.log("chatbatInfocus =" + chatbarInFocus); + }); + + $('#send_textarea').blur(function () { + + chatbarInFocus = false; + console.log("chatbatInfocus =" + chatbarInFocus); + }); @@ -648,6 +659,7 @@ $("document").ready(function () { return $(document.activeElement).is(":input"); } + //Additional hotkeys CTRL+ENTER and CTRL+UPARROW document.addEventListener("keydown", (event) => { if (event.ctrlKey && event.key == "Enter") { @@ -706,11 +718,13 @@ $("document").ready(function () { } } + + if (event.key == "ArrowUp") { //edits last message if chatbar is empty and focused console.log('got uparrow input'); if ( $("#send_textarea").val() === '' && - isInputElementInFocus("#send_textarea") && + chatbarInFocus === true && $(".swipe_right:last").css('display') === 'flex' && $("#character_popup").css("display") === "none" && $("#shadow_select_chat_popup").css("display") === "none" @@ -722,11 +736,11 @@ $("document").ready(function () { } } } - if (event.ctrlKey && event.key == "ArrowUp") { //edits last message if chatbar is empty and focused + if (event.ctrlKey && event.key == "ArrowUp") { //edits last USER message if chatbar is empty and focused console.log('got ctrl+uparrow input'); if ( $("#send_textarea").val() === '' && - isInputElementInFocus("#send_textarea") && + chatbarInFocus === true && $(".swipe_right:last").css('display') === 'flex' && $("#character_popup").css("display") === "none" && $("#shadow_select_chat_popup").css("display") === "none" From 7fb3d1f578db496808d5a3891df82aa17e02c09f Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Thu, 20 Apr 2023 23:39:02 +0900 Subject: [PATCH 3/4] fixed listener order for proper key detection --- public/scripts/RossAscends-mods.js | 35 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index dc0e950e4..6cb852e00 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -719,23 +719,6 @@ $("document").ready(function () { } - - if (event.key == "ArrowUp") { //edits last message if chatbar is empty and focused - console.log('got uparrow input'); - if ( - $("#send_textarea").val() === '' && - chatbarInFocus === true && - $(".swipe_right:last").css('display') === 'flex' && - $("#character_popup").css("display") === "none" && - $("#shadow_select_chat_popup").css("display") === "none" - ) { - const lastMes = document.querySelector('.last_mes'); - const editMes = lastMes.querySelector('.mes_block .mes_edit'); - if (editMes !== null) { - $(editMes).click(); - } - } - } if (event.ctrlKey && event.key == "ArrowUp") { //edits last USER message if chatbar is empty and focused console.log('got ctrl+uparrow input'); if ( @@ -753,5 +736,23 @@ $("document").ready(function () { } } } + + if (event.key == "ArrowUp") { //edits last message if chatbar is empty and focused + console.log('got uparrow input'); + if ( + $("#send_textarea").val() === '' && + chatbarInFocus === true && + $(".swipe_right:last").css('display') === 'flex' && + $("#character_popup").css("display") === "none" && + $("#shadow_select_chat_popup").css("display") === "none" + ) { + const lastMes = document.querySelector('.last_mes'); + const editMes = lastMes.querySelector('.mes_block .mes_edit'); + if (editMes !== null) { + $(editMes).click(); + } + } + } + }); }); From d452467818af20478d27a165f54e23b8f6a46a96 Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Thu, 20 Apr 2023 23:58:12 +0900 Subject: [PATCH 4/4] - escape from edit message now focuses on send_textarea - allow swipes to happen when send_textarea is focused but empty --- public/script.js | 9 +++++---- public/scripts/RossAscends-mods.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/public/script.js b/public/script.js index 3a6cb7a15..be8782bea 100644 --- a/public/script.js +++ b/public/script.js @@ -3500,8 +3500,8 @@ $(document).ready(function () { } chat[chat.length - 1]['swipe_id']++; //make new slot in array // if message has memory attached - remove it to allow regen - if (chat[chat.length -1].extra && chat[chat.length -1].extra.memory) { - delete chat[chat.length -1].extra.memory; + if (chat[chat.length - 1].extra && chat[chat.length - 1].extra.memory) { + delete chat[chat.length - 1].extra.memory; } //console.log(chat[chat.length-1]['swipes']); if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { //if swipe id of last message is the same as the length of the 'swipes' array @@ -5073,12 +5073,13 @@ $(document).ready(function () { $(document).keyup(function (e) { if (e.key === "Escape") { closeMessageEditor(); + $("#send_textarea").focus(); } }); - $("#bg-filter").on("input", function() { + $("#bg-filter").on("input", function () { const filterValue = $(this).val().toLowerCase(); - $("#bg_menu_content > div").each(function() { + $("#bg_menu_content > div").each(function () { const $bgContent = $(this); if ($bgContent.attr("title").toLowerCase().includes(filterValue)) { $bgContent.show(); diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 6cb852e00..1f6f7870b 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -655,11 +655,23 @@ $("document").ready(function () { } }); + function isInputElementInFocus() { - return $(document.activeElement).is(":input"); + //return $(document.activeElement).is(":input"); + var focused = $(':focus'); + if (focused.is('input') || focused.is('textarea')) { + if (focused.attr('id') === 'send_textarea') { + return false; + } + return true; + } + return false; } + + + //Additional hotkeys CTRL+ENTER and CTRL+UPARROW document.addEventListener("keydown", (event) => { if (event.ctrlKey && event.key == "Enter") {