summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Hall <brian@hack.design>2017-01-30 22:12:31 -0600
committerBrian Hall <brian@hack.design>2017-01-31 12:28:49 -0600
commit7bf6df8463c4f8871682f385e9368d169b4ffecf (patch)
tree5848818ea63a6f69b19b5d4b5b49433b6229d137
parentb78d06b78143b16dccc5d5afaa8796473b68bea1 (diff)
downloadgitlab-ce-7bf6df8463c4f8871682f385e9368d169b4ffecf.tar.gz
Change the reply shortcut to focus the field even without a selection.
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js.es61
-rw-r--r--app/assets/javascripts/shortcuts_issuable.js9
-rw-r--r--changelogs/unreleased/empty-selection-reply-shortcut.yml4
-rw-r--r--spec/javascripts/shortcuts_issuable_spec.js12
4 files changed, 21 insertions, 5 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js.es6 b/app/assets/javascripts/lib/utils/common_utils.js.es6
index 51993bb3420..e3bff2559fd 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js.es6
+++ b/app/assets/javascripts/lib/utils/common_utils.js.es6
@@ -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;
diff --git a/app/assets/javascripts/shortcuts_issuable.js b/app/assets/javascripts/shortcuts_issuable.js
index 4ef516af8c8..4dcc5ebe28f 100644
--- a/app/assets/javascripts/shortcuts_issuable.js
+++ b/app/assets/javascripts/shortcuts_issuable.js
@@ -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;
}
diff --git a/changelogs/unreleased/empty-selection-reply-shortcut.yml b/changelogs/unreleased/empty-selection-reply-shortcut.yml
new file mode 100644
index 00000000000..5a42c98a800
--- /dev/null
+++ b/changelogs/unreleased/empty-selection-reply-shortcut.yml
@@ -0,0 +1,4 @@
+---
+title: Change the reply shortcut to focus the field even without a selection.
+merge_request: 8873
+author: Brian Hall
diff --git a/spec/javascripts/shortcuts_issuable_spec.js b/spec/javascripts/shortcuts_issuable_spec.js
index 386fc8f514e..db2302c4fb0 100644
--- a/spec/javascripts/shortcuts_issuable_spec.js
+++ b/spec/javascripts/shortcuts_issuable_spec.js
@@ -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() {