Skip to content

Don't focus the copy branch button keyboard shortcut

Thomas Randolph requested to merge tor/defect/copy-branch-name-button-focus into master

What does this MR do and why?

For #364195 (closed)

Problem

Using the 'b' shortcut on MR Issuables selects the "copy source branch name" button in the UI and clicks it.

Since this click is a "real" DOM click, the element is focused and it scrolls to view, losing the user's position.

Solution

This solution still relies on the in-DOM button to grab the branch name (as text), but otherwise uses only in-memory/code-side behavior to copy that text to the clipboard.
Notably, this is not as graceful as it should be, but it accomplishes the goal.

Screenshots or screen recordings

Notably, I have only captured a gif of the old behavior, as there's no page motion on the new behavior (the whole point of this issue).

Before After
Success old-copy-branch-name image
Failure (Nothing ?) image

How to set up and validate locally

There really isn't much to this.

  1. You'll need to have "Shortcuts" enabled (this is the default).
    • If they are not, click the Help menu in the top nav, click Keyboard shortcuts, and then toggle them on.
  2. You'll need an MR that is large enough so that the top content of the MR (the title, author, creation date, etc.) is at least a little off screen.
    • Even the empty Overview tab has enough content to scroll the top just off screen, which is enough.
  3. Scroll the top content off screen so you'll notice any scroll change
  4. Press b on your keyboard.
    • On master, note that your view is scrolled to just under the top content, and the "Copied" tooltip appears there
    • On this branch, note that your view doesn't move, and a toast appears to tell you that the source branch was copied.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Phil Hughes

Merge request reports