Commit bc23424a authored by Kushal Pandya's avatar Kushal Pandya

Use last focused markdown field for quoted reply

Fixes a bug where pressing `r` for quoted reply always
added the block quote on main comment form instead
of last opened comment form which can also be
discussion reply form.

Changelog: fixed
parent 0dc514c2
...@@ -33,10 +33,37 @@ export default class ShortcutsIssuable extends Shortcuts { ...@@ -33,10 +33,37 @@ export default class ShortcutsIssuable extends Shortcuts {
Mousetrap.bind(keysFor(ISSUABLE_COMMENT_OR_REPLY), ShortcutsIssuable.replyWithSelectedText); Mousetrap.bind(keysFor(ISSUABLE_COMMENT_OR_REPLY), ShortcutsIssuable.replyWithSelectedText);
Mousetrap.bind(keysFor(ISSUABLE_EDIT_DESCRIPTION), ShortcutsIssuable.editIssue); Mousetrap.bind(keysFor(ISSUABLE_EDIT_DESCRIPTION), ShortcutsIssuable.editIssue);
Mousetrap.bind(keysFor(MR_COPY_SOURCE_BRANCH_NAME), ShortcutsIssuable.copyBranchName); 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() { 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 */) { if (!$replyField.length || $replyField.is(':hidden') /* Other tab selected in MR */) {
return false; return false;
......
...@@ -15,12 +15,20 @@ RSpec.describe 'Blob shortcuts', :js do ...@@ -15,12 +15,20 @@ RSpec.describe 'Blob shortcuts', :js do
end end
shared_examples "quotes the selected text" do shared_examples "quotes the selected text" do
it "quotes the selected text", :quarantine do it 'quotes the selected text in main comment form', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/356388' do
select_element('.note-text') select_element('#notes-list .note:first-child .note-text')
find('body').native.send_key('r') find('body').native.send_key('r')
expect(find('.js-main-target-form .js-vue-comment-form').value).to include(note_text) expect(find('.js-main-target-form .js-vue-comment-form').value).to include(note_text)
end end
it 'quotes the selected text in the discussion reply form', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/356388' do
find('#notes-list .note:first-child .js-reply-button').click
select_element('#notes-list .note:first-child .note-text')
find('body').native.send_key('r')
expect(find('#notes-list .note:first-child .js-vue-markdown-field .js-gfm-input').value).to include(note_text)
end
end end
describe 'pressing "r"' do describe 'pressing "r"' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment