From 434db03ab0012f0b7d463b3d36524f278ea2d691 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 11 Dec 2023 13:30:18 -0500 Subject: [PATCH] show less for large blocks --- templates/chat.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/templates/chat.html b/templates/chat.html index 4ffd2f7..d999843 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -421,10 +421,24 @@ function truncateCodeBlock(block, maxLines = 100) { // Reapply syntax highlighting hljs.highlightElement(block); addLineNumbers(block); - // Remove the expand button - expandButton.remove(); + // Change the button text to "Show Less" + expandButton.textContent = 'Show Less'; + // Change the onclick function to truncate the block again + expandButton.onclick = function() { + block.textContent = truncatedText; + // Reapply syntax highlighting + hljs.highlightElement(block); + addLineNumbers(block); + // Change the button text back to "Show More" + expandButton.textContent = 'Show More'; + // Set the onclick function back to the original expand function + expandButton.onclick = originalExpandFunction; + }; }; + // Keep a reference to the original expand function + const originalExpandFunction = expandButton.onclick; + // Insert the expand button after the code block block.parentNode.insertBefore(expandButton, block.nextSibling); }