From 19b68ebde82d21db5b58563669ffb1925ce0e74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20=C5=A0olc=20AI?= Date: Fri, 2 Oct 2026 14:18:09 +0200 Subject: [PATCH] fix(gitlab-mark-viewed): pin below the file's sticky header The pin aligned the next file to the MR header only. The file's own sticky filename header sticks lower and covered the first diff rows. Pin to the larger of the two offsets. Bump to 0.5.1. --- gitlab-mark-viewed.user.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gitlab-mark-viewed.user.js b/gitlab-mark-viewed.user.js index f825853..8188405 100644 --- a/gitlab-mark-viewed.user.js +++ b/gitlab-mark-viewed.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name GitLab — mark file as Viewed with "v" // @namespace https://github.com/solcik/userscripts -// @version 0.5.0 +// @version 0.5.1 // @description In a GitLab merge request diff, press "v" to toggle the focused file's "Viewed" checkbox, advancing to the next file — pinned under the sticky header — only when marking one viewed. // @author David Solc // @match https://gitlab.com/*/-/merge_requests/* @@ -40,6 +40,18 @@ return bottom; } + // The file's own filename header is sticky too and sticks below the merge + // request header, usually lower than the point topChrome() probes. Pin to + // its real `top` so it does not cover the first rows of the diff. + function fileStickyTop(file) { + for (const el of file.querySelectorAll('*')) { + const style = getComputedStyle(el); + if (style.position === 'sticky') return parseFloat(style.top) || 0; + } + + return 0; + } + // In "show one file at a time" mode there is only ever one file in the DOM; // otherwise the file being read is the topmost one still visible below the // sticky merge request header. @@ -84,7 +96,10 @@ (function pin() { const file = focusedFile(); if (file && fileKey(file) !== previousKey) { - const top = window.scrollY + file.getBoundingClientRect().top - topChrome(); + const top = + window.scrollY + + file.getBoundingClientRect().top - + Math.max(topChrome(), fileStickyTop(file)); if (Math.abs(top - window.scrollY) > 1) { window.scrollTo({ top: Math.max(top, 0), left: window.scrollX }); }