diff options
author | Bryce Johnson <bryce@gitlab.com> | 2016-10-25 11:49:18 +0300 |
---|---|---|
committer | Bryce Johnson <bryce@gitlab.com> | 2016-10-25 12:11:11 +0300 |
commit | 995d4df151621a79e1a45bfdf8917038511870ff (patch) | |
tree | 9d892377001abdf8ae4d84ec7637baa051326bb4 | |
parent | e0a79ab4e8ecf89db46b564a9ab7135c5a9081ec (diff) |
Ensure cursor is applied to end of issues search input.
-rw-r--r-- | app/assets/javascripts/issuable.js.es6 | 18 |
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) { |