diff --git a/static/koboldai.js b/static/koboldai.js index f775f3f0..4902908f 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -85,6 +85,7 @@ var dirty_chunks = []; var initial_socketio_connection_occured = false; var selected_model_data; var privacy_mode_enabled = false; +var ai_busy = false; var streaming = { windowOpen: false, @@ -775,6 +776,11 @@ function update_status_bar(data) { } function do_ai_busy(data) { + console.log("AIBUSY", data.value) + ai_busy = data.value; + // Don't allow editing while Mr. Kobold is thinking + document.getElementById("Selected Text").contentEditable = !ai_busy; + if (data.value) { ai_busy_start = Date.now(); favicon.start_swap() @@ -3265,6 +3271,11 @@ function fix_dirty_game_text() { //This should get fired if we have deleted chunks or have added text outside of a node. //We wait until after the game text has lost focus to fix things otherwise it messes with typing var game_text = document.getElementById("Selected Text"); + + // Fix stray stream + const streamBufferEl = document.getElementById("#token-stream-buffer"); + if (streamBufferEl) streamBufferEl.remove(); + //Fix missing story prompt if (dirty_chunks.includes("-1")) { if (!document.getElementById("story_prompt")) { @@ -3277,6 +3288,7 @@ function fix_dirty_game_text() { game_text.prepend(story_prompt); } } + if (dirty_chunks.includes("game_text")) { dirty_chunks = dirty_chunks.filter(item => item != "game_text"); console.log("Firing Fix messed up text"); @@ -3312,7 +3324,7 @@ function fix_dirty_game_text() { function savegametextchanges() { fix_dirty_game_text(); - for (item of document.getElementsByClassName("editing")) { + for (const item of document.getElementsByClassName("editing")) { item.classList.remove("editing"); } if (dirty_chunks.length > 0) { @@ -7631,4 +7643,32 @@ $el("#gamescreen").addEventListener("paste", function(event) { false, event.clipboardData.getData("text/plain") ); +}); + +const gameText = document.getElementById("Selected Text"); +gameText.addEventListener("click", function(event) { + if (ai_busy) { + event.stopPropagation(); + return; + }; + + set_edit(event); +}); + +gameText.addEventListener("focusout", function(event) { + if (ai_busy) { + event.stopPropagation(); + return; + }; + + savegametextchanges(); +}); + +gameText.addEventListener("paste", function(event) { + if (ai_busy) { + event.stopPropagation(); + return; + }; + + check_game_after_paste(); }); \ No newline at end of file diff --git a/templates/index_new.html b/templates/index_new.html index 99b8c941..25dee500 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -53,7 +53,7 @@
-