mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-01-23 13:50:25 +01:00
Fix restorePrompt()
in application.js
When the prompt is deleted by the user, the topmost remaining chunk of the story that has at most one non-whitespace character is now made the new prompt chunk. Also fixed issues in Chromium-based browsers (desktop and Android) where selecting all text in the story, typing some new text to replace the entire story and then defocusing causes the editor to break.
This commit is contained in:
parent
00f611b207
commit
4a852d7f95
@ -1476,14 +1476,59 @@ function syncAllModifiedChunks(including_selected_chunks=false) {
|
||||
}
|
||||
|
||||
function restorePrompt() {
|
||||
if(game_text[0].firstChild && game_text[0].firstChild.nodeType === 3) {
|
||||
saved_prompt = formatChunkInnerText(game_text[0].firstChild);
|
||||
if($("#n0").length && formatChunkInnerText($("#n0")[0]).length === 0) {
|
||||
$("#n0").remove();
|
||||
}
|
||||
var shadow_text = $("<b>" + game_text.html() + "</b>");
|
||||
var detected = false;
|
||||
var ref = null;
|
||||
try {
|
||||
if(shadow_text.length && shadow_text[0].firstChild && (shadow_text[0].firstChild.nodeType === 3 || shadow_text[0].firstChild.tagName === "BR")) {
|
||||
detected = true;
|
||||
ref = shadow_text;
|
||||
} else if(game_text.length && game_text[0].firstChild && game_text[0].firstChild.nodeType === 3 || game_text[0].firstChild.tagName === "BR") {
|
||||
detected = true;
|
||||
ref = game_text;
|
||||
}
|
||||
} catch (e) {
|
||||
detected = false;
|
||||
}
|
||||
if(detected) {
|
||||
unbindGametext();
|
||||
game_text[0].innerText = "";
|
||||
var text = [];
|
||||
while(true) {
|
||||
if(ref.length && ref[0].firstChild && ref[0].firstChild.nodeType === 3) {
|
||||
text.push(ref[0].firstChild.textContent.replace(/\u00a0/g, " "));
|
||||
} else if(ref.length && ref[0].firstChild && ref[0].firstChild.tagName === "BR") {
|
||||
text.push("\n");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
ref[0].removeChild(ref[0].firstChild);
|
||||
}
|
||||
text = text.join("").trim();
|
||||
if(text.length) {
|
||||
saved_prompt = text;
|
||||
}
|
||||
game_text[0].innerHTML = "";
|
||||
bindGametext();
|
||||
}
|
||||
if($("#n0").length) {
|
||||
$("#n0").remove();
|
||||
game_text.children().each(function() {
|
||||
if(this.tagName !== "CHUNK") {
|
||||
this.parentNode.removeChild(this);
|
||||
}
|
||||
});
|
||||
if(!detected) {
|
||||
game_text.children().each(function() {
|
||||
if(this.innerText.trim().length) {
|
||||
saved_prompt = this.innerText.trim();
|
||||
socket.send({'cmd': 'inlinedelete', 'data': this.getAttribute("n")});
|
||||
this.parentNode.removeChild(this);
|
||||
return false;
|
||||
}
|
||||
socket.send({'cmd': 'inlinedelete', 'data': this.getAttribute("n")});
|
||||
this.parentNode.removeChild(this);
|
||||
});
|
||||
}
|
||||
var prompt_chunk = document.createElement("chunk");
|
||||
prompt_chunk.setAttribute("n", "0");
|
||||
|
@ -10,7 +10,7 @@
|
||||
<script src="static/bootstrap.min.js"></script>
|
||||
<script src="static/bootstrap-toggle.min.js"></script>
|
||||
<script src="static/rangy-core.min.js"></script>
|
||||
<script src="static/application.js?ver=1.16.4l"></script>
|
||||
<script src="static/application.js?ver=1.16.4m"></script>
|
||||
|
||||
<link rel="stylesheet" href="static/jquery-ui.sortable.min.css">
|
||||
<link rel="stylesheet" href="static/bootstrap.min.css">
|
||||
|
Loading…
Reference in New Issue
Block a user