Commit 80c0b877 authored by Phil Hughes's avatar Phil Hughes

Fixed issue when label or milestone had space

parent a4789db9
...@@ -83,14 +83,23 @@ ...@@ -83,14 +83,23 @@
return inputValue; return inputValue;
} }
return inputValue.slice(0, right + selectionStart + 1).trim(); return inputValue.slice(0, right + 1).trim();
} }
static getInputSelectionPosition(input) { static getInputSelectionPosition(input) {
const inputValue = input.value; let inputValue = input.value;
// Replace all spaces inside quote marks with underscores
// This helps with matching the beginning & end of a token:key
inputValue = inputValue.replace(/"(.*?)"/g, str => str.replace(/\s/g, '_') );
const selectionStart = input.selectionStart; const selectionStart = input.selectionStart;
let left = inputValue.slice(0, selectionStart + 1).search(/\S+$/); let right = inputValue.slice(selectionStart).search(/\s/);
const right = inputValue.slice(selectionStart).search(/\s/);
if (right >= 0) {
right += selectionStart;
}
let left = inputValue.slice(0, right).search(/\S+$/);
if (selectionStart === 0) { if (selectionStart === 0) {
left = 0; left = 0;
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
right = inputValue.length; right = inputValue.length;
} }
input.value = `${inputValue.substr(0, left)}${word}${inputValue.substr(right + selectionStart)}`; input.value = `${inputValue.substr(0, left)}${word}${inputValue.substr(right)}`;
gl.FilteredSearchDropdownManager.updateInputCaretPosition(selectionStart, input); gl.FilteredSearchDropdownManager.updateInputCaretPosition(selectionStart, input);
} }
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
right = inputValue.length; right = inputValue.length;
} }
input.setSelectionRange(selectionStart + right, selectionStart + right); input.setSelectionRange(selectionStart + right, selectionStart);
} }
updateCurrentDropdownOffset() { updateCurrentDropdownOffset() {
......
...@@ -553,6 +553,18 @@ describe 'Filter issues', js: true, feature: true do ...@@ -553,6 +553,18 @@ describe 'Filter issues', js: true, feature: true do
expect(filtered_search.value).to eq("author:@#{user.username} label:~#{label.name}") expect(filtered_search.value).to eq("author:@#{user.username} label:~#{label.name}")
end end
it 'changes label correctly space is in previous label' do
input_filtered_search("label:~\"#{multiple_words_label.title}\"", submit: false)
select_search_at_index(0)
page.within '#js-dropdown-label' do
click_button label.name
end
expect(filtered_search.value).to eq("label:~#{label.name}")
end
end end
describe 'filter issues by text' do describe 'filter issues by text' do
......
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