Monorepo for Tangled tangled.org

appview: highlight active file in PR filetree on scroll #1113

merged opened by j3s.sh targeting master

the tl;dr here is that i get lost when i'm looking at a file's content sometimes & a little highlighted file in the tree helps me find my way without having to scroll up and miss the impossibly tiny header (not a tangled issue, i have this issue on all git platforms) -- my hope is that a lil "bold" breadcrumb will help.

Labels

None yet.

assignee

None yet.

Participants 3
AT URI
at://did:plc:pxa3amkp7jhfclaads3zud7q/sh.tangled.repo.pull/3mg7g4f4jc422
+47 -1
Diff #0
+46
appview/pages/templates/repo/fragments/diff.html
··· 11 11 {{ template "diffTopbar" . }} 12 12 {{ block "diffLayout" . }} {{ end }} 13 13 {{ template "fragments/resizable" }} 14 + {{ template "activeFileHighlight" }} 14 15 {{ end }} 15 16 16 17 {{ define "diffTopbar" }} ··· 229 230 }); 230 231 </script> 231 232 {{ end }} 233 + 234 + {{ define "activeFileHighlight" }} 235 + <script> 236 + document.addEventListener('DOMContentLoaded', function() { 237 + const diffFiles = document.querySelectorAll('details[id^="file-"]'); 238 + const filetreeLinks = document.querySelectorAll('.filetree-link'); 239 + if (diffFiles.length === 0 || filetreeLinks.length === 0) return; 240 + 241 + const linkMap = new Map(); 242 + filetreeLinks.forEach(link => { 243 + const path = link.getAttribute('data-path'); 244 + if (path) linkMap.set('file-' + path, link); 245 + }); 246 + 247 + let currentActive = null; 248 + function setActive(link) { 249 + if (link && link !== currentActive) { 250 + if (currentActive) currentActive.classList.remove('font-bold'); 251 + link.classList.add('font-bold'); 252 + currentActive = link; 253 + } 254 + } 255 + 256 + filetreeLinks.forEach(link => { 257 + link.addEventListener('click', () => setActive(link)); 258 + }); 259 + 260 + const topbar = document.querySelector('.sticky.top-0.z-30'); 261 + const headerHeight = topbar ? topbar.offsetHeight : 0; 262 + 263 + function updateActiveFile() { 264 + for (const file of diffFiles) { 265 + const rect = file.getBoundingClientRect(); 266 + if (rect.top <= headerHeight && rect.bottom > headerHeight) { 267 + setActive(linkMap.get(file.id)); 268 + return; 269 + } 270 + } 271 + } 272 + 273 + document.addEventListener('scroll', updateActiveFile); 274 + updateActiveFile(); 275 + }); 276 + </script> 277 + {{ end }}
+1 -1
appview/pages/templates/repo/fragments/fileTree.html
··· 16 16 {{ else if .Name }} 17 17 <div class="tree-file flex items-center gap-2 pt-1"> 18 18 {{ i "file" "flex-shrink-0 size-4" }} 19 - <a href="#file-{{ .Path }}" class="filename truncate text-black dark:text-white no-underline hover:underline">{{ .Name }}</a> 19 + <a href="#file-{{ .Path }}" data-path="{{ .Path }}" class="filetree-link filename truncate text-black dark:text-white no-underline hover:underline">{{ .Name }}</a> 20 20 </div> 21 21 {{ else }} 22 22 {{ range $child := .Children }}

History

1 round 4 comments
sign up or login to add to the discussion
j3s.sh submitted #0
1 commit
expand
5ba055de
appview: highlight active file in PR filetree on scroll
expand 4 comments

Just tested and it works pretty well. Thank you for the contribution!

Style-wise, I feel the bold doesn't stand out enough here. Maybe we should try underline but I'm not sure if using same effect from hover is a good idea.

preview:

git/merge.go is highlighted

I'll toss final decision to @oppi.li

Ah forgot that was imgur link.

See here

agreed, it took me a sec to hunt out the bolded file in that screenshot. i wonder if a mild yellow highlight or similar could work. or honestly even a little arrow / dot prefix/suffix. i'll defer to @oppi.li as well :3

bold is good! i think we should just reduce the brightness of the default. its currently black/white but it could be gray-600/gray-400 perhaps. happy to merge this as is and noodle on that later!

pull request successfully merged