* Better text update follow

This commit is contained in:
Daniel Legt 2022-06-07 00:37:35 +03:00
parent 6e401a416f
commit b4c47ded35
1 changed files with 14 additions and 2 deletions

View File

@ -176,9 +176,21 @@ class PadSocket {
*/
function updatePadContent(newContent, textArea = true) {
// Update the textarea
if ( textArea ) document.getElementById(`pad-content`).value = newContent;
if ( textArea ) {
document.getElementById(`pad-content`).value = newContent;
}
// Update the preview
document.getElementById(`textarea-preview`).innerHTML = newContent;
const prev = document.getElementById(`textarea-preview`);
const shouldScroll = prev.scrollTop >= (prev.scrollHeight - Number(getComputedStyle(prev).height.replace(/px/g, ''))) * 0.98;
prev.innerHTML = newContent;
// Check if we should follow the bottom scrolling
if (shouldScroll) {
prev.scrollTop = prev.scrollHeight;
}
// TODO: Re-run the syntax highlight
}