diff options
author | Phil Hughes <me@iamphill.com> | 2017-01-19 18:43:38 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-01-21 20:05:02 +0000 |
commit | a4789db98e6ad39e8b890ebe93ee91bb4531eec3 (patch) | |
tree | 3b8341595507a70e8b42af15d994e7db61cfd989 | |
parent | ab1b8d5035c75e0613dd3fe5f027cd3e73102247 (diff) | |
download | gitlab-ce-a4789db98e6ad39e8b890ebe93ee91bb4531eec3.tar.gz |
Fixed bug replacing full input value
-rw-r--r-- | app/assets/javascripts/filtered_search/dropdown_utils.js.es6 | 8 | ||||
-rw-r--r-- | app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 | 7 |
2 files changed, 9 insertions, 6 deletions
diff --git a/app/assets/javascripts/filtered_search/dropdown_utils.js.es6 b/app/assets/javascripts/filtered_search/dropdown_utils.js.es6 index dcab32fd38b..0027f79aecb 100644 --- a/app/assets/javascripts/filtered_search/dropdown_utils.js.es6 +++ b/app/assets/javascripts/filtered_search/dropdown_utils.js.es6 @@ -89,9 +89,15 @@ static getInputSelectionPosition(input) { const inputValue = input.value; const selectionStart = input.selectionStart; - const left = inputValue.slice(0, selectionStart + 1).search(/\S+$/); + let left = inputValue.slice(0, selectionStart + 1).search(/\S+$/); const right = inputValue.slice(selectionStart).search(/\s/); + if (selectionStart === 0) { + left = 0; + } else if (selectionStart === inputValue.length && left < 0) { + left = inputValue.length; + } + return { left, right, 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 031e4f9b127..9edb6ade4f2 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,16 +62,13 @@ // Get the string to replace const selectionStart = input.selectionStart; - let { left, right } = gl.DropdownUtils.getInputSelectionPosition(input); + const { left } = gl.DropdownUtils.getInputSelectionPosition(input); + let { right } = gl.DropdownUtils.getInputSelectionPosition(input); if (right < 0) { right = inputValue.length; } - if (left < 0) { - left += 1; - } - input.value = `${inputValue.substr(0, left)}${word}${inputValue.substr(right + selectionStart)}`; gl.FilteredSearchDropdownManager.updateInputCaretPosition(selectionStart, input); } |