mirror of https://github.com/JustKato/FreePad.git
				
				
				
			* Dynamic updates for highlights
This commit is contained in:
		
							parent
							
								
									0a3b5d50f2
								
							
						
					
					
						commit
						30dc23c847
					
				| 
						 | 
				
			
			@ -184,15 +184,27 @@ function updatePadContent(newContent, textArea = true) {
 | 
			
		|||
    const prev = document.getElementById(`textarea-preview`);
 | 
			
		||||
    const shouldScroll = prev.scrollTop >= (prev.scrollHeight - Number(getComputedStyle(prev).height.replace(/px/g, ''))) * 0.98;
 | 
			
		||||
 | 
			
		||||
    prev.innerHTML = newContent;
 | 
			
		||||
    prev.innerHTML = escapeHtml(newContent);
 | 
			
		||||
 | 
			
		||||
    prev.classList.remove(`language-undefined`);
 | 
			
		||||
 | 
			
		||||
    prev.classList.forEach( c => {
 | 
			
		||||
        if ( c.indexOf(`language-`) != -1 ) {
 | 
			
		||||
            prev.classList.remove(c);
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    try { // highlights
 | 
			
		||||
        hljs.highlightElement(document.getElementById(`textarea-preview`));
 | 
			
		||||
    } catch ( err ) {
 | 
			
		||||
        console.err(err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Check if we should follow the bottom scrolling
 | 
			
		||||
    if (shouldScroll) {
 | 
			
		||||
        prev.scrollTop = prev.scrollHeight;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: Re-run the syntax highlight
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function updatePadViewers(vc) {
 | 
			
		||||
| 
						 | 
				
			
			@ -223,4 +235,17 @@ function connectSocket() {
 | 
			
		|||
// wait for the whole window to load
 | 
			
		||||
window.addEventListener(`load`, e => {
 | 
			
		||||
    connectSocket()
 | 
			
		||||
})
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// lol
 | 
			
		||||
function escapeHtml(html){
 | 
			
		||||
    const text = document.createTextNode(html);
 | 
			
		||||
    const p = document.createElement('p');
 | 
			
		||||
 | 
			
		||||
    p.appendChild(text);
 | 
			
		||||
    const content = p.innerHTML;
 | 
			
		||||
    p.remove();
 | 
			
		||||
 | 
			
		||||
    return content;
 | 
			
		||||
  }
 | 
			
		||||
		Loading…
	
		Reference in New Issue