Fix Rapid Diffs file navigation shortcuts across modes

What does this MR do and why?

The j/k (and ]/[) next/previous file shortcuts did not work reliably in the Rapid Diffs merge request view, and the v (toggle reviewed) shortcut could act on the wrong file.

In single-file mode, j/k did nothing, because navigation was bounds-checked against files rendered in the DOM, and single-file mode only ever renders one file. In multi-file mode the current file was tracked by an internal counter that ignored scrolling and file-browser clicks, so the first j/k press after scrolling or clicking jumped to the wrong file, and v toggled the wrong file.

The fix makes file navigation mode-aware. In single-file mode it delegates to the existing store navigation, which walks the full file list. In multi-file mode the two concerns are answered separately: v targets the file with the largest visible area in the viewport (the file the reader is looking at), while j/k step an explicit cursor so repeated presses always advance one file at a time. The cursor resets to the most visible file whenever the reader scrolls or clicks, so navigation still follows scroll position and file-browser clicks. Marking a file as viewed also re-anchors the collapsed file so it stays on screen for an immediate un-toggle.

No new dependencies or primitives; it reuses existing store actions and an existing viewport helper. Frontend unit tests were updated to cover both modes.

How to set up and validate locally

  1. Open a merge request with several changed files on the Changes tab.
  2. In multi-file mode, scroll down a few files, then press j/k repeatedly: navigation should continue from the file on screen and advance exactly one file per press, without stalling or skipping. Press v: it should toggle the file you are looking at, and the collapsed file should stay in view. Press v again to un-toggle it.
  3. Click a file in the file browser, then press j: it should move to the neighbor of the clicked file.
  4. Switch to single-file mode (the file-by-file toggle) and press j/k: it should load the next/previous file.

Screen recording(s)

References

Edited by Thomas Randolph

Merge request reports

Loading
Loading