Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com

Jump to paragraph and highlight it when clicking a comment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

+42
+15
static/css/editor.css
··· 272 272 border: 1px solid var(--border); 273 273 border-radius: var(--radius); 274 274 overflow: hidden; 275 + cursor: pointer; 276 + } 277 + 278 + .comment-thread:hover { 279 + border-color: var(--primary); 280 + } 281 + 282 + @keyframes para-highlight { 283 + 0% { background: color-mix(in srgb, var(--primary) 20%, transparent); } 284 + 100% { background: transparent; } 285 + } 286 + 287 + .para-highlight { 288 + animation: para-highlight 1.2s ease-out forwards; 289 + border-radius: 3px; 275 290 } 276 291 277 292 .comment-thread-label {
+27
templates/document_edit.html
··· 817 817 } 818 818 }); 819 819 820 + (function attachThreadClickHandler() { 821 + const container = document.getElementById('comment-threads'); 822 + if (!container) return; 823 + container.addEventListener('click', e => { 824 + const thread = e.target.closest('.comment-thread'); 825 + if (!thread) return; 826 + jumpToParagraph(thread.dataset.paragraph || ''); 827 + }); 828 + })(); 829 + 820 830 function renderCommentThreads(comments) { 821 831 const container = document.getElementById('comment-threads'); 822 832 if (!container) return; ··· 867 877 } catch (e) { 868 878 console.error('Load comments failed:', e); 869 879 } 880 + } 881 + 882 + function jumpToParagraph(pid) { 883 + if (pid === 'general') return; 884 + const idx = parseInt(pid.replace('p-', ''), 10); 885 + if (isNaN(idx)) return; 886 + const pmEl = document.querySelector('#editor-rich .ProseMirror'); 887 + if (!pmEl) return; 888 + const blocks = Array.from(pmEl.children); 889 + const target = blocks[idx]; 890 + if (!target) return; 891 + target.scrollIntoView({ behavior: 'smooth', block: 'center' }); 892 + target.classList.remove('para-highlight'); 893 + // Force reflow so the animation restarts if clicked twice. 894 + void target.offsetWidth; 895 + target.classList.add('para-highlight'); 896 + target.addEventListener('animationend', () => target.classList.remove('para-highlight'), { once: true }); 870 897 } 871 898 872 899 function setupParagraphCommentTrigger() {