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 @@
}
},
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) {
......
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