Support markdown anchors and multi-line in permalink

What does this MR do and why?

AI Summary

This change improves how line numbers and URL hashes are handled in the code viewer. The main improvements are:

  1. The code now properly synchronizes the URL hash (the part after # in the URL) with the application state when users navigate to specific lines of code.
  2. A new utility function getAbsolutePermalinkPath was created to consistently generate permalink URLs that include the correct line numbers or section anchors.
  3. The code now properly handles different hash formats (like line numbers "L42", line ranges "L10-19", and section anchors like "#section-heading").
  4. Event listeners were added to detect when the URL hash changes, ensuring the application state stays in sync with the browser's URL.
  5. Removed redundant click handling code that was updating line numbers, as this is now handled more consistently through the hash change mechanism.

References

Resolves #537733 (closed) #521756 (closed)

Screenshots or screen recordings

Cases Expected Url
link without hash https://gdk.test:3443/gitlab-org/gitlab-shell/-/blob/ad635be1b8710b5531dc0f22f4d408d5bfb3bc91/README.md
link with line number https://gdk.test:3443/gitlab-org/gitlab-shell/-/blob/ad635be1b8710b5531dc0f22f4d408d5bfb3bc91/README.md#L14
link with multi-line https://gdk.test:3443/gitlab-org/gitlab-shell/-/blob/ad635be1b8710b5531dc0f22f4d408d5bfb3bc91/README.md#L35-42
link with markdown anchors https://gdk.test:3443/gitlab-org/gitlab-shell/-/blob/ad635be1b8710b5531dc0f22f4d408d5bfb3bc91/README.md#development-documentation

How to set up and validate locally

  1. Go to a file/Open a file link
  2. Select line/multi-lines/markdown anchor
  3. Select permalink from overflow menu or press y

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Chaoyue Zhao

Merge request reports

Loading