diff options
Diffstat (limited to 'app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js')
-rw-r--r-- | app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js b/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js index f7b327b2af1..5a5a67334d3 100644 --- a/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js +++ b/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js @@ -4,6 +4,8 @@ import Sidebar from '../../right_sidebar'; import Shortcuts from './shortcuts'; import { CopyAsGFM } from '../markdown/copy_as_gfm'; import { getSelectedFragment } from '~/lib/utils/common_utils'; +import { isElementVisible } from '~/lib/utils/dom_utils'; +import { clickCopyToClipboardButton } from '~/behaviors/copy_to_clipboard'; export default class ShortcutsIssuable extends Shortcuts { constructor() { @@ -14,6 +16,7 @@ export default class ShortcutsIssuable extends Shortcuts { Mousetrap.bind('l', () => ShortcutsIssuable.openSidebarDropdown('labels')); Mousetrap.bind('r', ShortcutsIssuable.replyWithSelectedText); Mousetrap.bind('e', ShortcutsIssuable.editIssue); + Mousetrap.bind('b', ShortcutsIssuable.copyBranchName); } static replyWithSelectedText() { @@ -98,4 +101,18 @@ export default class ShortcutsIssuable extends Shortcuts { Sidebar.instance.openDropdown(name); return false; } + + static copyBranchName() { + // There are two buttons - one that is shown when the sidebar + // is expanded, and one that is shown when it's collapsed. + const allCopyBtns = Array.from(document.querySelectorAll('.sidebar-source-branch button')); + + // Select whichever button is currently visible so that + // the "Copied" tooltip is shown when a click is simulated. + const visibleBtn = allCopyBtns.find(isElementVisible); + + if (visibleBtn) { + clickCopyToClipboardButton(visibleBtn); + } + } } |