Commit 9e594f98 authored by Phil Hughes's avatar Phil Hughes

Merge branch '292224-quote-reply-comment-to-last-focused-input-field' into 'master'

Use last focused markdown field for quoted reply

See merge request gitlab-org/gitlab!83284
parents 32f63fff bc23424a
......@@ -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;
......
......@@ -15,12 +15,20 @@ RSpec.describe 'Blob shortcuts', :js do
end
shared_examples "quotes the selected text" do
it "quotes the selected text", :quarantine do
select_element('.note-text')
it 'quotes the selected text in main comment form', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/356388' do
select_element('#notes-list .note:first-child .note-text')
find('body').native.send_key('r')
expect(find('.js-main-target-form .js-vue-comment-form').value).to include(note_text)
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
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