diff options
Diffstat (limited to 'app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6')
-rw-r--r-- | app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 index a64818497c1..031e4f9b127 100644 --- a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 +++ b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 @@ -62,18 +62,33 @@ // Get the string to replace const selectionStart = input.selectionStart; - const { left } = gl.DropdownUtils.getInputSelectionPosition(input); - let { right } = gl.DropdownUtils.getInputSelectionPosition(input); + let { left, right } = gl.DropdownUtils.getInputSelectionPosition(input); if (right < 0) { right = inputValue.length; } - if (left !== -1) { - input.value = `${inputValue.substr(0, left)}${word}${inputValue.substr(right + selectionStart)}`; - } else { - input.value += word; + if (left < 0) { + left += 1; } + + input.value = `${inputValue.substr(0, left)}${word}${inputValue.substr(right + selectionStart)}`; + gl.FilteredSearchDropdownManager.updateInputCaretPosition(selectionStart, input); + } + + static updateInputCaretPosition(selectionStart, input) { + // Reset the position + // Sometimes can end up at end of input + input.setSelectionRange(selectionStart, selectionStart); + + const inputValue = input.value; + let { right } = gl.DropdownUtils.getInputSelectionPosition(input); + + if (right < 0) { + right = inputValue.length; + } + + input.setSelectionRange(selectionStart + right, selectionStart + right); } updateCurrentDropdownOffset() { |