Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/pages: PR comment link button when comment box is closed

Signed-off-by: Lewis <lewis@tangled.org>

authored by

Lewis and committed by tangled.org 2c7b9392 3d739f81

+71 -41
+71 -41
appview/pages/templates/fragments/line-quote-button.html
··· 107 107 let dragCurrent = null; 108 108 let hoverTarget = null; 109 109 110 + const commentBtn = () => 111 + document.querySelector('[hx-get$="/comment"]:not(form *)'); 112 + 113 + const openCommentForm = () => { 114 + const ta = textarea(); 115 + if (ta) return Promise.resolve(ta); 116 + const trigger = commentBtn(); 117 + if (!trigger) return Promise.resolve(null); 118 + trigger.click(); 119 + return new Promise(resolve => { 120 + const handler = () => { 121 + const ta = textarea(); 122 + if (!ta) return; 123 + document.body.removeEventListener('htmx:afterSettle', handler); 124 + clearTimeout(timer); 125 + resolve(ta); 126 + }; 127 + const timer = setTimeout(() => { 128 + document.body.removeEventListener('htmx:afterSettle', handler); 129 + resolve(null); 130 + }, 5000); 131 + document.body.addEventListener('htmx:afterSettle', handler); 132 + }); 133 + }; 134 + 110 135 const showBtn = (lineEl) => { 111 - if (!textarea() || !anchorOf(lineEl)) return; 136 + if ((!textarea() && !commentBtn()) || !anchorOf(lineEl)) return; 112 137 const rect = lineEl.getBoundingClientRect(); 113 138 Object.assign(btn.style, { 114 139 top: `${rect.top + rect.height / 2 - btn.offsetHeight / 2}px`, ··· 207 182 stretchBtn(dragAnchor, dragCurrent); 208 183 }); 209 184 185 + const insertIntoTextarea = (ta, selected) => { 186 + const first = selected[0]; 187 + const last = selected[selected.length - 1]; 188 + const fNum = lineNumOf(first); 189 + const firstAnchor = anchorOf(first); 190 + 191 + if (!fNum || !firstAnchor) return; 192 + 193 + const file = fileOf(first); 194 + const lNum = lineNumOf(last); 195 + const lastAnchor = anchorOf(last); 196 + 197 + const label = selected.length === 1 198 + ? (file ? `${file}:${fNum}` : `L${fNum}`) 199 + : (file ? `${file}:${fNum}-${lNum}` : `L${fNum}-${lNum}`); 200 + 201 + const fragment = selected.length === 1 202 + ? firstAnchor 203 + : `${firstAnchor}~${lastAnchor}`; 204 + 205 + const md = `[\`${label}\`](${window.location.pathname}${window.location.search}#${fragment})`; 206 + 207 + const { selectionStart: s, selectionEnd: end, value } = ta; 208 + const before = value.slice(0, s); 209 + const after = value.slice(end); 210 + let pre = '', suf = ''; 211 + if (s === end && before.length > 0) { 212 + const cur = before.slice(before.lastIndexOf('\n') + 1); 213 + if (cur.length > 0) { 214 + const nextNl = after.indexOf('\n'); 215 + const rest = nextNl === -1 ? after : after.slice(0, nextNl); 216 + if (rest.trim().length === 0) { pre = '\n'; } 217 + else { pre = before.endsWith(' ') ? '' : ' '; suf = after.startsWith(' ') ? '' : ' '; } 218 + } 219 + } 220 + ta.value = before + pre + md + suf + after; 221 + ta.selectionStart = ta.selectionEnd = s + pre.length + md.length + suf.length; 222 + ta.focus(); 223 + ta.dispatchEvent(new Event('input', { bubbles: true })); 224 + }; 225 + 210 226 document.addEventListener('mouseup', () => { 211 227 if (!dragging) return; 212 228 dragging = false; 213 229 document.body.style.userSelect = ''; 214 230 215 231 const selected = rangeBetween(dragAnchor, dragCurrent); 216 - const ta = textarea(); 217 - if (ta && selected.length > 0) { 218 - const first = selected[0]; 219 - const last = selected[selected.length - 1]; 220 - const fNum = lineNumOf(first); 221 - const firstAnchor = anchorOf(first); 222 - 223 - if (fNum && firstAnchor) { 224 - const file = fileOf(first); 225 - const lNum = lineNumOf(last); 226 - const lastAnchor = anchorOf(last); 227 - 228 - const label = selected.length === 1 229 - ? (file ? `${file}:${fNum}` : `L${fNum}`) 230 - : (file ? `${file}:${fNum}-${lNum}` : `L${fNum}-${lNum}`); 231 - 232 - const fragment = selected.length === 1 233 - ? firstAnchor 234 - : `${firstAnchor}~${lastAnchor}`; 235 - 236 - const md = `[\`${label}\`](${window.location.pathname}${window.location.search}#${fragment})`; 237 - 238 - const { selectionStart: s, selectionEnd: end, value } = ta; 239 - const before = value.slice(0, s); 240 - const after = value.slice(end); 241 - let pre = '', suf = ''; 242 - if (s === end && before.length > 0) { 243 - const cur = before.slice(before.lastIndexOf('\n') + 1); 244 - if (cur.length > 0) { 245 - const nextNl = after.indexOf('\n'); 246 - const rest = nextNl === -1 ? after : after.slice(0, nextNl); 247 - if (rest.trim().length === 0) { pre = '\n'; } 248 - else { pre = before.endsWith(' ') ? '' : ' '; suf = after.startsWith(' ') ? '' : ' '; } 249 - } 250 - } 251 - ta.value = before + pre + md + suf + after; 252 - ta.selectionStart = ta.selectionEnd = s + pre.length + md.length + suf.length; 253 - ta.focus(); 254 - ta.dispatchEvent(new Event('input', { bubbles: true })); 255 - } 232 + if (selected.length > 0) { 233 + openCommentForm().then(ta => { 234 + if (ta) insertIntoTextarea(ta, selected); 235 + }); 256 236 } 257 237 258 238 clearHl('line-quote-hl');