- proper send_textarea focus retention logic

- for send_but, options_button, and option_regenerate
This commit is contained in:
RossAscends
2023-04-23 05:07:06 +09:00
parent e299089775
commit 8fb9b79c02

View File

@ -203,7 +203,6 @@ let exportPopper = Popper.createPopper(document.getElementById('export_button'),
let dialogueResolve = null; let dialogueResolve = null;
let chat_metadata = {}; let chat_metadata = {};
let streamingProcessor = null; let streamingProcessor = null;
let ChatBarInFocus = false;
const durationSaveEdit = 200; const durationSaveEdit = 200;
@ -1504,10 +1503,10 @@ async function Generate(type, automatic_trigger, force_name2) {
////////////////////////////////// //////////////////////////////////
var count_exm_add = 0; var count_exm_add = 0;
console.log('emptying chat2'); //console.log('emptying chat2');
var chat2 = []; var chat2 = [];
var j = 0; var j = 0;
console.log('pre-replace chat.length = ' + chat.length); //console.log('pre-replace chat.length = ' + chat.length);
for (var i = chat.length - 1; i >= 0; i--) { for (var i = chat.length - 1; i >= 0; i--) {
let charName = selected_group ? chat[j].name : name2; let charName = selected_group ? chat[j].name : name2;
if (j == 0) { if (j == 0) {
@ -1538,7 +1537,7 @@ async function Generate(type, automatic_trigger, force_name2) {
//console.log('replacing chat2 {}s'); //console.log('replacing chat2 {}s');
j++; j++;
} }
console.log('post replace chat.length = ' + chat.length); //console.log('post replace chat.length = ' + chat.length);
//chat2 = chat2.reverse(); //chat2 = chat2.reverse();
var this_max_context = 1487; var this_max_context = 1487;
if (main_api == 'kobold' || main_api == 'textgenerationwebui') { if (main_api == 'kobold' || main_api == 'textgenerationwebui') {
@ -1583,14 +1582,14 @@ async function Generate(type, automatic_trigger, force_name2) {
/////////////////////// swipecode /////////////////////// swipecode
if (type == 'swipe') { if (type == 'swipe') {
console.log('pre swipe shift: ' + chat2.length); //console.log('pre swipe shift: ' + chat2.length);
console.log('shifting swipe chat2'); //console.log('shifting swipe chat2');
chat2.shift(); chat2.shift();
} }
let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2); let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2);
console.log('post swipe shift:' + chat2.length); //console.log('post swipe shift:' + chat2.length);
var i = 0; var i = 0;
// hack for regeneration of the first message // hack for regeneration of the first message
@ -1610,7 +1609,7 @@ async function Generate(type, automatic_trigger, force_name2) {
//if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item; //if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item;
arrMes[arrMes.length] = item; arrMes[arrMes.length] = item;
} else { } else {
console.log('reducing chat.length by 1'); //console.log('reducing chat.length by 1');
i = chat2.length - 1; i = chat2.length - 1;
} }
@ -1776,7 +1775,7 @@ async function Generate(type, automatic_trigger, force_name2) {
//console.log('Generated Prompt Cache length: '+generatedPromtCache.length); //console.log('Generated Prompt Cache length: '+generatedPromtCache.length);
checkPromtSize(); checkPromtSize();
} else { } else {
console.log('calling setPromtString') //console.log('calling setPromtString')
setPromtString(); setPromtString();
} }
@ -2088,7 +2087,7 @@ async function Generate(type, automatic_trigger, force_name2) {
} }
is_send_press = false; is_send_press = false;
} }
console.log('generate ending'); //console.log('generate ending');
} //generate ends } //generate ends
function shouldContinueMultigen(getMessage) { function shouldContinueMultigen(getMessage) {
@ -2431,6 +2430,10 @@ async function getChat() {
} }
getChatResult(); getChatResult();
saveChat(); saveChat();
setTimeout(function () {
$('#send_textarea').click();
$('#send_textarea').focus();
}, 200);
} catch (error) { } catch (error) {
getChatResult(); getChatResult();
console.log(error); console.log(error);
@ -3484,8 +3487,36 @@ window["TavernAI"].getContext = function () {
$(document).ready(function () { $(document).ready(function () {
//////////INPUT BAR FOCUS-KEEPING LOGIC/////////////
let S_TAFocused = false;
let S_TAPreviouslyFocused = false;
$('#send_textarea').on('focusin focus click', () => {
S_TAFocused = true;
S_TAPreviouslyFocused = true;
});
$('#send_textarea').on('focusout blur', () => S_TAFocused = false);
$('#options_button, #send_but, #option_regenerate').on('click', () => {
if (S_TAPreviouslyFocused) {
$('#send_textarea').focus();
S_TAFocused = true;
}
});
$(document).click(event => {
if ($(':focus').attr('id') !== 'send_textarea') {
if (!$(event.target.id).is("#options_button, #send_but, #send_textarea, #option_regenerate")) {
S_TAFocused = false;
S_TAPreviouslyFocused = false;
}
} else {
S_TAFocused = true;
S_TAPreviouslyFocused = true;
}
});
/////////////////
$('#swipes-checkbox').change(function () { $('#swipes-checkbox').change(function () {
console.log('detected swipes-checkbox changed values')
swipes = !!$('#swipes-checkbox').prop('checked'); swipes = !!$('#swipes-checkbox').prop('checked');
if (swipes) { if (swipes) {
//console.log('toggle change calling showswipebtns'); //console.log('toggle change calling showswipebtns');
@ -3764,10 +3795,6 @@ $(document).ready(function () {
if (is_send_press == false) { if (is_send_press == false) {
is_send_press = true; is_send_press = true;
Generate(); Generate();
if (ChatBarInFocus !== false) {
console.log("send_but -- refocusing chatbar");
$('#send_textarea').focus();
}
} }
}); });
@ -3779,16 +3806,6 @@ $(document).ready(function () {
} }
}); });
$("#send_textarea").on('focus', function () {
ChatBarInFocus = true;
console.log('chatbar focused');
});
$("#send_textarea").on('blur', function () {
ChatBarInFocus = '';
console.log('chatbarInFocus set to ambiguous');
});
//menu buttons setup //menu buttons setup
$("#rm_button_settings").click(function () { $("#rm_button_settings").click(function () {
@ -4072,6 +4089,7 @@ $(document).ready(function () {
$("#selected_chat_pole").val(characters[this_chid].chat); $("#selected_chat_pole").val(characters[this_chid].chat);
saveCharacterDebounced(); saveCharacterDebounced();
getChat(); getChat();
} }
if (dialogueResolve) { if (dialogueResolve) {
@ -4367,10 +4385,6 @@ $(document).ready(function () {
$("#options_button").click(function () { $("#options_button").click(function () {
// this is the options button click function, shows the options menu if closed // this is the options button click function, shows the options menu if closed
if (ChatBarInFocus !== false) {
console.log('options button - refocusing chatbar');
$("#send_textarea").focus();
}
if ( if (
$("#options").css("display") === "none" && $("#options").css("display") === "none" &&
$("#options").css("opacity") == 0.0 $("#options").css("opacity") == 0.0
@ -4391,10 +4405,6 @@ $(document).ready(function () {
$("#options [id]").on("click", function () { $("#options [id]").on("click", function () {
var id = $(this).attr("id"); var id = $(this).attr("id");
if (ChatBarInFocus !== false) {
console.log('options item - refocusing chatbar');
$("#send_textarea").focus();
}
if (id == "option_select_chat") { if (id == "option_select_chat") {
if (selected_group) { if (selected_group) {
// will open a chat selection screen // will open a chat selection screen