diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js')
-rw-r--r-- | app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js b/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js index e58c51104c5..6124befd3b6 100644 --- a/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js +++ b/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js @@ -4,7 +4,7 @@ import { clickCopyToClipboardButton } from '~/behaviors/copy_to_clipboard'; import { getSelectedFragment } from '~/lib/utils/common_utils'; import { isElementVisible } from '~/lib/utils/dom_utils'; import { DEBOUNCE_DROPDOWN_DELAY } from '~/vue_shared/components/sidebar/labels_select_widget/constants'; -import Sidebar from '../../right_sidebar'; +import Sidebar from '~/right_sidebar'; import { CopyAsGFM } from '../markdown/copy_as_gfm'; import { keysFor, @@ -33,10 +33,37 @@ export default class ShortcutsIssuable extends Shortcuts { Mousetrap.bind(keysFor(ISSUABLE_COMMENT_OR_REPLY), ShortcutsIssuable.replyWithSelectedText); Mousetrap.bind(keysFor(ISSUABLE_EDIT_DESCRIPTION), ShortcutsIssuable.editIssue); Mousetrap.bind(keysFor(MR_COPY_SOURCE_BRANCH_NAME), ShortcutsIssuable.copyBranchName); + + /** + * We're attaching a global focus event listener on document for + * every markdown input field. + */ + $(document).on( + 'focus', + '.js-vue-markdown-field .js-gfm-input', + ShortcutsIssuable.handleMarkdownFieldFocus, + ); + } + + /** + * This event handler preserves last focused markdown input field. + * @param {Object} event + */ + static handleMarkdownFieldFocus({ currentTarget }) { + ShortcutsIssuable.$lastFocusedReplyField = $(currentTarget); } static replyWithSelectedText() { - const $replyField = $('.js-main-target-form .js-vue-comment-form'); + let $replyField = $('.js-main-target-form .js-vue-comment-form'); + + // Ensure that markdown input is still present in the DOM + // otherwise fall back to main comment input field. + if ( + ShortcutsIssuable.$lastFocusedReplyField && + isElementVisible(ShortcutsIssuable.$lastFocusedReplyField?.get(0)) + ) { + $replyField = ShortcutsIssuable.$lastFocusedReplyField; + } if (!$replyField.length || $replyField.is(':hidden') /* Other tab selected in MR */) { return false; |