mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2025-06-07 14:17:09 -04:00
Further optimize handleMorphdomUpdate a bit
This commit is contained in:
parent
1a086adec0
commit
6f25e6d6ac
1 changed files with 16 additions and 13 deletions
|
@ -230,9 +230,22 @@ function removeLastClick() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMorphdomUpdate(data) {
|
function handleMorphdomUpdate(data) {
|
||||||
|
// Determine target element and use it as query scope
|
||||||
|
var target_element, target_html;
|
||||||
|
if (data.last_message_only) {
|
||||||
|
const childNodes = document.getElementsByClassName("messages")[0].childNodes;
|
||||||
|
target_element = childNodes[childNodes.length - 1];
|
||||||
|
target_html = data.html;
|
||||||
|
} else {
|
||||||
|
target_element = document.getElementById("chat").parentNode;
|
||||||
|
target_html = "<div class=\"prose svelte-1ybaih5\">" + data.html + "</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryScope = target_element;
|
||||||
|
|
||||||
// Track open blocks
|
// Track open blocks
|
||||||
const openBlocks = new Set();
|
const openBlocks = new Set();
|
||||||
document.querySelectorAll(".thinking-block").forEach(block => {
|
queryScope.querySelectorAll(".thinking-block").forEach(block => {
|
||||||
const blockId = block.getAttribute("data-block-id");
|
const blockId = block.getAttribute("data-block-id");
|
||||||
// If block exists and is open, add to open set
|
// If block exists and is open, add to open set
|
||||||
if (blockId && block.hasAttribute("open")) {
|
if (blockId && block.hasAttribute("open")) {
|
||||||
|
@ -242,7 +255,7 @@ function handleMorphdomUpdate(data) {
|
||||||
|
|
||||||
// Store scroll positions for any open blocks
|
// Store scroll positions for any open blocks
|
||||||
const scrollPositions = {};
|
const scrollPositions = {};
|
||||||
document.querySelectorAll(".thinking-block[open]").forEach(block => {
|
queryScope.querySelectorAll(".thinking-block[open]").forEach(block => {
|
||||||
const content = block.querySelector(".thinking-content");
|
const content = block.querySelector(".thinking-content");
|
||||||
const blockId = block.getAttribute("data-block-id");
|
const blockId = block.getAttribute("data-block-id");
|
||||||
if (content && blockId) {
|
if (content && blockId) {
|
||||||
|
@ -254,16 +267,6 @@ function handleMorphdomUpdate(data) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var target_element, target_html;
|
|
||||||
if (data.last_message_only) {
|
|
||||||
const childNodes = document.getElementsByClassName("messages")[0].childNodes;
|
|
||||||
target_element = childNodes[childNodes.length - 1];
|
|
||||||
target_html = data.html;
|
|
||||||
} else {
|
|
||||||
target_element = document.getElementById("chat").parentNode;
|
|
||||||
target_html = "<div class=\"prose svelte-1ybaih5\">" + data.html + "</div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
morphdom(
|
morphdom(
|
||||||
target_element,
|
target_element,
|
||||||
target_html,
|
target_html,
|
||||||
|
@ -317,7 +320,7 @@ function handleMorphdomUpdate(data) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add toggle listeners for new blocks
|
// Add toggle listeners for new blocks
|
||||||
document.querySelectorAll(".thinking-block").forEach(block => {
|
queryScope.querySelectorAll(".thinking-block").forEach(block => {
|
||||||
if (!block._hasToggleListener) {
|
if (!block._hasToggleListener) {
|
||||||
block.addEventListener("toggle", function(e) {
|
block.addEventListener("toggle", function(e) {
|
||||||
if (this.open) {
|
if (this.open) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue