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

@ -5076,6 +5076,7 @@ $(document).ready(function () {
$(document).keyup(function (e) { $(document).keyup(function (e) {
if (e.key === "Escape") { if (e.key === "Escape") {
closeMessageEditor(); closeMessageEditor();
$("#send_textarea").focus();
} }
}); });

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,9 +655,22 @@ $("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) => {
@ -660,7 +684,7 @@ $("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") {
@ -674,7 +698,7 @@ $("document").ready(function () {
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();
}
}
}
}); });
}); });