[v7.0/forgejo] fix(ui): handle out-of-bounds end line in code selection (#4820)

Backport of https://codeberg.org/forgejo/forgejo/pulls/4788.

- fallback to the last line, preventing TypeError
- add E2E test

Co-authored-by: Solomon Victorino <git@solomonvictorino.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4820
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
forgejo-backport-action 2024-08-05 05:56:37 +00:00 committed by 0ko
parent ae2312b767
commit 0f7cd8d46a
2 changed files with 55 additions and 1 deletions

View file

@ -156,7 +156,8 @@ export function initRepoCodeView() {
if (m) {
$first = $linesEls.filter(`[rel=${m[1]}]`);
if ($first.length) {
selectRange($linesEls, $first, $linesEls.filter(`[rel=${m[2]}]`));
const $last = $linesEls.filter(`[rel=${m[2]}]`);
selectRange($linesEls, $first, $last.length ? $last : $linesEls.last());
// show code view menu marker (don't show in blame page)
if (!isBlame()) {