mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 08:07:56 +01:00
UI: improve the performance of code syntax highlighting
This commit is contained in:
parent
0b193b8553
commit
d5bde7babc
32
js/main.js
32
js/main.js
@ -144,22 +144,21 @@ targetElement.addEventListener("scroll", function() {
|
|||||||
|
|
||||||
// Create a MutationObserver instance
|
// Create a MutationObserver instance
|
||||||
const observer = new MutationObserver(function(mutations) {
|
const observer = new MutationObserver(function(mutations) {
|
||||||
mutations.forEach(function(mutation) {
|
updateCssProperties();
|
||||||
updateCssProperties();
|
|
||||||
|
|
||||||
const firstChild = targetElement.children[0];
|
const firstChild = targetElement.children[0];
|
||||||
if (firstChild.classList.contains("generating")) {
|
if (firstChild.classList.contains("generating")) {
|
||||||
typing.parentNode.classList.add("visible-dots");
|
typing.parentNode.classList.add("visible-dots");
|
||||||
document.getElementById("stop").style.display = "flex";
|
document.getElementById("stop").style.display = "flex";
|
||||||
document.getElementById("Generate").style.display = "none";
|
document.getElementById("Generate").style.display = "none";
|
||||||
} else {
|
} else {
|
||||||
typing.parentNode.classList.remove("visible-dots");
|
typing.parentNode.classList.remove("visible-dots");
|
||||||
document.getElementById("stop").style.display = "none";
|
document.getElementById("stop").style.display = "none";
|
||||||
document.getElementById("Generate").style.display = "flex";
|
document.getElementById("Generate").style.display = "flex";
|
||||||
}
|
}
|
||||||
|
|
||||||
doSyntaxHighlighting();
|
|
||||||
});
|
doSyntaxHighlighting();
|
||||||
|
|
||||||
if(!isScrolled) {
|
if(!isScrolled) {
|
||||||
targetElement.scrollTop = targetElement.scrollHeight;
|
targetElement.scrollTop = targetElement.scrollHeight;
|
||||||
@ -215,6 +214,9 @@ function doSyntaxHighlighting() {
|
|||||||
indexes.forEach((index) => {
|
indexes.forEach((index) => {
|
||||||
const element = elements[index];
|
const element = elements[index];
|
||||||
|
|
||||||
|
// Tag this element to prevent it from being highlighted twice
|
||||||
|
element.setAttribute("data-highlighted", "true");
|
||||||
|
|
||||||
// Perform syntax highlighting
|
// Perform syntax highlighting
|
||||||
const codeBlocks = element.querySelectorAll("pre code");
|
const codeBlocks = element.querySelectorAll("pre code");
|
||||||
|
|
||||||
@ -231,8 +233,6 @@ function doSyntaxHighlighting() {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tag this element to indicate it has been syntax highlighted
|
|
||||||
element.setAttribute("data-highlighted", "true");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe(targetElement, config);
|
observer.observe(targetElement, config);
|
||||||
|
Loading…
Reference in New Issue
Block a user