Hopefully better infinity scroll

This commit is contained in:
ebolam
2022-10-05 09:41:29 -04:00
parent 7b31190b93
commit 7f9c26332d
4 changed files with 37 additions and 34 deletions

View File

@@ -9056,7 +9056,7 @@ def UI_2_get_next_100_actions(data):
data_to_send = [] data_to_send = []
for i in reversed(list(koboldai_vars.actions.actions)): for i in reversed(list(koboldai_vars.actions.actions)):
if i < data: if i < data:
if sent >= 50: if sent >= 100:
break break
data_to_send.append({"id": i, "action": koboldai_vars.actions.actions[i]}) data_to_send.append({"id": i, "action": koboldai_vars.actions.actions[i]})
sent += 1 sent += 1

View File

@@ -2398,7 +2398,7 @@ textarea {
} }
.single_pulse { .single_pulse {
animation: pulse-text 1s 1; animation: pulse-text 0.5s 1;
} }
.drag-over { .drag-over {

View File

@@ -155,6 +155,7 @@ function reset_story() {
finder_last_input = null; finder_last_input = null;
on_new_wi_item = null; on_new_wi_item = null;
current_chunk_number = null; current_chunk_number = null;
console.log("resetting scroll_trigger_element");
scroll_trigger_element = undefined; scroll_trigger_element = undefined;
var story_area = document.getElementById('Selected Text'); var story_area = document.getElementById('Selected Text');
let temp = [] let temp = []
@@ -348,24 +349,13 @@ function do_story_text_updates(action) {
//need to find the closest element //need to find the closest element
next_id = action.id+1; next_id = action.id+1;
while (true) { if (Math.max.apply(null,Object.keys(actions_data)) <= next_id) {
if (next_id in actions_data) { story_area.append(span);
story_area.insertBefore(span, document.getElementById('Selected Text Chunk '+next_id)); } else {
break; story_area.prepend(span);
} else if (Math.max.apply(null,Object.keys(actions_data)) <= next_id) {
story_area.append(span);
break;
}
next_id += 1;
} }
span.classList.add("single_pulse"); span.classList.add("single_pulse");
if (action.id.toString() == document.getElementById('action_count').textContent) {
console.log("Scrolling. Action Count: "+document.getElementById('action_count').textContent);
document.getElementById("Selected Text").scrollTop = document.getElementById("Selected Text").scrollHeight;
}
//clearTimeout(game_text_scroll_timeout);
//game_text_scroll_timeout = setTimeout(function() {document.getElementById("Selected Text").scrollTop = document.getElementById("Selected Text").scrollHeight;}, 500);
if (span.textContent != "") { if (span.textContent != "") {
assign_world_info_to_action(action.id, null); assign_world_info_to_action(action.id, null);
} }
@@ -554,11 +544,18 @@ function var_changed(data) {
} }
//Special Case for Actions //Special Case for Actions
if ((data.classname == "story") && (data.name == "actions")) { if ((data.classname == "story") && (data.name == "actions")) {
start_time = Date.now();
if (document.getElementById("Selected Text").firstElementChild.id == "story_prompt") {
first_story_element = document.getElementById("Selected Text").firstElementChild.nextElementSibling;
} else {
first_story_element = document.getElementById("Selected Text").firstElementChild;
}
if (Array.isArray(data.value)) { if (Array.isArray(data.value)) {
actions = data.value; actions = data.value;
} else { } else {
actions = [data.value]; actions = [data.value];
} }
if (actions.length == 0) {return;}
for (action of actions) { for (action of actions) {
if (action.length != 0) { if (action.length != 0) {
actions_data[action.id] = action.action; actions_data[action.id] = action.action;
@@ -575,23 +572,27 @@ function var_changed(data) {
} }
} }
} }
//check to see if our new action is before the scroll triggering action //if we hit the top, unhide the prompt and move it to the top
if (actions.length > 0) { if (actions[0].id == 0) {
if ((scroll_trigger_element == undefined) || (actions[actions.length-1].id < parseInt(scroll_trigger_element.getAttribute("chunk")))) { prompt_span = document.getElementById("story_prompt");
if (scroll_trigger_element != undefined) { document.getElementById("Selected Text").prepend(prompt_span);
scroll_trigger_element.scrollIntoView(false); prompt_span.classList.remove("hidden");
} else { } else if (actions[actions.length-1].id != current_action) {
document.getElementById("Selected Text Chunk "+actions[actions.length-1].id).scrollIntoView(false); //we are bringing in old data (not adding to the end of the game text), so set the scroll event back up
} //and scroll so that the old top is at the top again (IE new text added is before the top of the screen)
if (first_story_element) {
scroll_trigger_element = document.getElementById("Selected Text Chunk "+actions[0].id); first_story_element.scrollIntoView(true);
//if we hit the top, unhide the prompt and clear the scroll trigger
if (actions[0].id == 0) {
document.getElementById("story_prompt").classList.remove("hidden");
scroll_trigger_element = null;
}
} }
scroll_trigger_element = document.getElementById('Selected Text Chunk '+actions[actions.length-1].id);
} else {
//We are adding new game text to the screen (not past actions)
//If this is the first add, then we need to set our scroll trigger up
if (document.getElementsByClassName("rawtext").length == actions.length+1) {
scroll_trigger_element = document.getElementById('Selected Text Chunk '+actions[0].id);
}
document.getElementById('Selected Text Chunk '+actions[actions.length-1].id).scrollIntoView(false);
} }
//console.log("Took "+((Date.now()-start_time)/1000)+"s to process");
//Special Case for Presets //Special Case for Presets
} else if ((data.classname == 'model') && (data.name == 'presets')) { } else if ((data.classname == 'model') && (data.name == 'presets')) {
@@ -4796,9 +4797,9 @@ document.addEventListener("keydown", function(event) {
document.getElementById("Selected Text").onscroll = function(){ document.getElementById("Selected Text").onscroll = function(){
//TOP //TOP
if ((scroll_trigger_element != undefined) && (scroll_trigger_element != null)) { if ((scroll_trigger_element != undefined) && (scroll_trigger_element != null)) {
if(scroll_trigger_element.getBoundingClientRect().top >= 0){ if(scroll_trigger_element.getBoundingClientRect().bottom >= 0){
console.log("Asking for more actions");
socket.emit("get_next_100_actions", parseInt(scroll_trigger_element.getAttribute("chunk"))); socket.emit("get_next_100_actions", parseInt(scroll_trigger_element.getAttribute("chunk")));
scroll_trigger_element == null;
} }
} }
} }

View File

@@ -101,6 +101,8 @@
<span class="setting_maxlabel"><span style="top: -4px; position: relative;"></span></span> <span class="setting_maxlabel"><span style="top: -4px; position: relative;"></span></span>
</div> </div>
</div> </div>
<button class="settings_button" onclick="console.log('Getting actions from '+parseInt(document.getElementById('Selected Text').firstElementChild.nextElementSibling.getAttribute('chunk')));
socket.emit('get_next_100_actions', parseInt(document.getElementById('Selected Text').firstElementChild.nextElementSibling.getAttribute('chunk')));">Get more story chunks</button>
<div id="probabilities"> <div id="probabilities">
</div> </div>