Skip to content

Fix creating permalink with shortcut key "y"

What does this MR do and why?

  • Keep ShortcutsBlob class to minimum and have it only add a shortcut.
  • moveToFilePermalink() and shortcircuitPermalinkButtons() become utility functions
  • I decided to keep the functions still in app/assets/javascripts/behaviors/shortcuts/shortcuts_blob.js file, because they need to be reused in Vue and JS version of Blob, and still relate to ShortcutsBlob class
  • Querying of the permalink button and url is done on the spot, inside utility functions to avoid instantiating a shortcuts class with data that becomes outdated after user navigates to a different file
  • As a bonus, we don't have to manipulate the url for specific lines, because it query for it, when the line hash is already present in the button's href attribute

MR acceptance checklist

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

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
Screen_Recording_2024-05-28_at_14.46.51 Screen_Recording_2024-05-28_at_14.46.00

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Open a project of choice
  2. Navigate to Repository and select a file to view
  3. When viewing a file, use y key to get the permalink. The url in your browser should update, for example from http://gdk.test:8080/flightjs/Flight/-/blob/master/CONTRIBUTING.md?ref_type=heads to http://gdk.test:8080/flightjs/Flight/-/blob/67f1ed1d2e7dfc9357cc82e3bc2bde2403264021/CONTRIBUTING.md
  4. Navigate back to the project overview with the browser "Go back" button.
  5. Select a different file.
  6. Use y key and make sure that the url changed and it contains the name of the file you're currently viewing (not the previous one).
  7. You should be able to repeat these steps and use Permalink button in the top right corner, to get the same urls.

Related to #454667 (closed)

Edited by Paulina Sedlak-Jakubowska

Merge request reports