This commit is contained in:
SillyLossy
2023-04-20 18:18:10 +03:00
2 changed files with 68 additions and 23 deletions

View File

@ -3503,8 +3503,8 @@ $(document).ready(function () {
} }
chat[chat.length - 1]['swipe_id']++; //make new slot in array chat[chat.length - 1]['swipe_id']++; //make new slot in array
// if message has memory attached - remove it to allow regen // if message has memory attached - remove it to allow regen
if (chat[chat.length -1].extra && 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; delete chat[chat.length - 1].extra.memory;
} }
//console.log(chat[chat.length-1]['swipes']); //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 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
@ -5076,12 +5076,13 @@ $(document).ready(function () {
$(document).keyup(function (e) { $(document).keyup(function (e) {
if (e.key === "Escape") { if (e.key === "Escape") {
closeMessageEditor(); closeMessageEditor();
$("#send_textarea").focus();
} }
}); });
$("#bg-filter").on("input", function() { $("#bg-filter").on("input", function () {
const filterValue = $(this).val().toLowerCase(); const filterValue = $(this).val().toLowerCase();
$("#bg_menu_content > div").each(function() { $("#bg_menu_content > div").each(function () {
const $bgContent = $(this); const $bgContent = $(this);
if ($bgContent.attr("title").toLowerCase().includes(filterValue)) { if ($bgContent.attr("title").toLowerCase().includes(filterValue)) {
$bgContent.show(); $bgContent.show();

View File

@ -588,6 +588,17 @@ $("document").ready(function () {
} else { SaveLocal('LNavOpened', 'false'); } } 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);
});
@ -644,10 +655,23 @@ $("document").ready(function () {
} }
}); });
function isInputElementInFocus() { 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 //Additional hotkeys CTRL+ENTER and CTRL+UPARROW
document.addEventListener("keydown", (event) => { document.addEventListener("keydown", (event) => {
if (event.ctrlKey && event.key == "Enter") { if (event.ctrlKey && event.key == "Enter") {
@ -660,21 +684,21 @@ $("document").ready(function () {
//Generate("regenerate"); //Generate("regenerate");
} }
} }
if (event.ctrlKey && event.key == "ArrowUp") { /* if (event.ctrlKey && event.key == "ArrowUp") {
//Ctrl+UpArrow for Connect to last server //Ctrl+UpArrow for Connect to last server
console.log(main_api); console.log(main_api);
if (online_status === "no_connection") { if (online_status === "no_connection") {
if (main_api == "kobold") { if (main_api == "kobold") {
document.getElementById("api_button").click(); document.getElementById("api_button").click();
} }
if (main_api == "novel") { if (main_api == "novel") {
document.getElementById("api_button_novel").click(); document.getElementById("api_button_novel").click();
} }
if (main_api == "textgenerationwebui") { if (main_api == "textgenerationwebui") {
document.getElementById("api_button_textgenerationwebui").click(); document.getElementById("api_button_textgenerationwebui").click();
} }
} }
} } */
if (event.ctrlKey && event.key == "ArrowLeft") { //for debug, show all local stored vars if (event.ctrlKey && event.key == "ArrowLeft") { //for debug, show all local stored vars
CheckLocal(); CheckLocal();
} }
@ -705,11 +729,13 @@ $("document").ready(function () {
$('.swipe_right:last').click(); $('.swipe_right:last').click();
} }
} }
if (event.key == "ArrowUp") { //edits last message if chatbar is empty and focused
console.log('got uparrow input');
if (event.ctrlKey && event.key == "ArrowUp") { //edits last USER message if chatbar is empty and focused
console.log('got ctrl+uparrow input');
if ( if (
$("#send_textarea").val() === '' && $("#send_textarea").val() === '' &&
isInputElementInFocus("#send_textarea") && chatbarInFocus === true &&
$(".swipe_right:last").css('display') === 'flex' && $(".swipe_right:last").css('display') === 'flex' &&
$("#character_popup").css("display") === "none" && $("#character_popup").css("display") === "none" &&
$("#shadow_select_chat_popup").css("display") === "none" $("#shadow_select_chat_popup").css("display") === "none"
@ -722,5 +748,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();
}
}
}
}); });
}); });