Change the reply shortcut to focus the field even without a selection.
This commit is contained in:
parent
b78d06b781
commit
7bf6df8463
4 changed files with 21 additions and 5 deletions
|
@ -162,6 +162,7 @@
|
|||
|
||||
w.gl.utils.getSelectedFragment = () => {
|
||||
const selection = window.getSelection();
|
||||
if (selection.rangeCount === 0) return null;
|
||||
const documentFragment = selection.getRangeAt(0).cloneContents();
|
||||
if (documentFragment.textContent.length === 0) return null;
|
||||
|
||||
|
|
|
@ -39,17 +39,20 @@
|
|||
}
|
||||
|
||||
ShortcutsIssuable.prototype.replyWithSelectedText = function() {
|
||||
var quote, replyField, documentFragment, selected, separator;
|
||||
var quote, documentFragment, selected, separator;
|
||||
var replyField = $('.js-main-target-form #note_note');
|
||||
|
||||
documentFragment = window.gl.utils.getSelectedFragment();
|
||||
if (!documentFragment) return;
|
||||
if (!documentFragment) {
|
||||
replyField.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the documentFragment contains more than just Markdown, don't copy as GFM.
|
||||
if (documentFragment.querySelector('.md, .wiki')) return;
|
||||
|
||||
selected = window.gl.CopyAsGFM.nodeToGFM(documentFragment);
|
||||
|
||||
replyField = $('.js-main-target-form #note_note');
|
||||
if (selected.trim() === "") {
|
||||
return;
|
||||
}
|
||||
|
|
4
changelogs/unreleased/empty-selection-reply-shortcut.yml
Normal file
4
changelogs/unreleased/empty-selection-reply-shortcut.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Change the reply shortcut to focus the field even without a selection.
|
||||
merge_request: 8873
|
||||
author: Brian Hall
|
|
@ -27,11 +27,19 @@
|
|||
return this.selector = 'form.js-main-target-form textarea#note_note';
|
||||
});
|
||||
describe('with empty selection', function() {
|
||||
return it('does nothing', function() {
|
||||
stubSelection('');
|
||||
it('does not return an error', function() {
|
||||
this.shortcut.replyWithSelectedText();
|
||||
return expect($(this.selector).val()).toBe('');
|
||||
});
|
||||
return it('triggers `input`', function() {
|
||||
var focused;
|
||||
focused = false;
|
||||
$(this.selector).on('focus', function() {
|
||||
return focused = true;
|
||||
});
|
||||
this.shortcut.replyWithSelectedText();
|
||||
return expect(focused).toBe(true);
|
||||
});
|
||||
});
|
||||
describe('with any selection', function() {
|
||||
beforeEach(function() {
|
||||
|
|
Loading…
Reference in a new issue