diff options
-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) { |