summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce Johnson <bryce@gitlab.com>2016-10-25 10:49:18 +0200
committerBryce Johnson <bryce@gitlab.com>2016-10-25 11:11:11 +0200
commit995d4df151621a79e1a45bfdf8917038511870ff (patch)
tree9d892377001abdf8ae4d84ec7637baa051326bb4
parente0a79ab4e8ecf89db46b564a9ab7135c5a9081ec (diff)
downloadgitlab-ce-995d4df151621a79e1a45bfdf8917038511870ff.tar.gz
Ensure cursor is applied to end of issues search input.
-rw-r--r--app/assets/javascripts/issuable.js.es618
1 files changed, 16 insertions, 2 deletions
diff --git a/app/assets/javascripts/issuable.js.es6 b/app/assets/javascripts/issuable.js.es6
index 25f98ef8689..8c3c2d54c1a 100644
--- a/app/assets/javascripts/issuable.js.es6
+++ b/app/assets/javascripts/issuable.js.es6
@@ -53,8 +53,22 @@
}
},
maybeFocusOnSearch: function() {
- if (Issuable.searchState.current !== '') {
- Issuable.searchState.elem.focus();
+ const currentSearchVal = Issuable.searchState.current;
+ if (currentSearchVal !== '') {
+ const queryLength = currentSearchVal.length;
+ const $searchInput = Issuable.searchState.elem;
+
+ /* The following ensures that the cursor is initially placed at
+ * the end of search input when focus is applied. It accounts
+ * for differences in browser implementations of `setSelectionRange`
+ * and cursor placement for elements in focus.
+ */
+ $searchInput.focus();
+ if ($searchInput.setSelectionRange) {
+ $searchInput.setSelectionRange(queryLength, queryLength);
+ } else {
+ $searchInput.val(currentSearchVal);
+ }
}
},
executeSearch: function(e) {