Commit 995d4df1 authored by Bryce Johnson's avatar Bryce Johnson

Ensure cursor is applied to end of issues search input.

parent e0a79ab4
...@@ -53,8 +53,22 @@ ...@@ -53,8 +53,22 @@
} }
}, },
maybeFocusOnSearch: function() { maybeFocusOnSearch: function() {
if (Issuable.searchState.current !== '') { const currentSearchVal = Issuable.searchState.current;
Issuable.searchState.elem.focus(); 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) { executeSearch: function(e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment