Commit ac080c63 authored by Phil Hughes's avatar Phil Hughes

Opens dropdown correctly

parent 79659b30
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
} }
getSearchInput() { getSearchInput() {
const query = this.input.value.trim(); const query = gl.DropdownUtils.getSearchInput(this.input).trim();
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(query); const { lastToken } = gl.FilteredSearchTokenizer.processTokens(query);
return lastToken.value || ''; return lastToken.value || '';
......
...@@ -72,6 +72,18 @@ ...@@ -72,6 +72,18 @@
// Return boolean based on whether it was set // Return boolean based on whether it was set
return dataValue !== null; return dataValue !== null;
} }
static getSearchInput(filteredSearchInput) {
const selectionStart = filteredSearchInput.selectionStart;
const inputValue = filteredSearchInput.value;
const rightPos = inputValue.slice(selectionStart).search(/\s/);
if (rightPos < 0) {
return inputValue;
}
return inputValue.slice(0, rightPos + selectionStart + 1).trim();
}
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
......
...@@ -59,7 +59,8 @@ ...@@ -59,7 +59,8 @@
const input = document.querySelector('.filtered-search'); const input = document.querySelector('.filtered-search');
const word = `${tokenName}:${tokenValue}`; const word = `${tokenName}:${tokenValue}`;
const { lastToken, searchToken } = gl.FilteredSearchTokenizer.processTokens(input.value); const inputValue = gl.DropdownUtils.getSearchInput(input).trim();
const { lastToken, searchToken } = gl.FilteredSearchTokenizer.processTokens(inputValue);
const lastSearchToken = searchToken.split(' ').last(); const lastSearchToken = searchToken.split(' ').last();
const lastInputCharacter = input.value[input.value.length - 1]; const lastInputCharacter = input.value[input.value.length - 1];
const lastInputTrimmedCharacter = input.value.trim()[input.value.trim().length - 1]; const lastInputTrimmedCharacter = input.value.trim()[input.value.trim().length - 1];
...@@ -92,7 +93,7 @@ ...@@ -92,7 +93,7 @@
const filterIconPadding = 27; const filterIconPadding = 27;
const offset = gl.text const offset = gl.text
.getTextWidth(this.getSearchInput(), this.font) + filterIconPadding; .getTextWidth(gl.DropdownUtils.getSearchInput(this.filteredSearchInput).trim(), this.font) + filterIconPadding;
this.mapping[key].reference.setOffset(offset); this.mapping[key].reference.setOffset(offset);
} }
...@@ -148,7 +149,7 @@ ...@@ -148,7 +149,7 @@
setDropdown() { setDropdown() {
const { lastToken, searchToken } = this.tokenizer const { lastToken, searchToken } = this.tokenizer
.processTokens(this.getSearchInput()); .processTokens(gl.DropdownUtils.getSearchInput(this.filteredSearchInput));
if (this.filteredSearchInput.value.split('').last() === ' ') { if (this.filteredSearchInput.value.split('').last() === ' ') {
this.updateCurrentDropdownOffset(); this.updateCurrentDropdownOffset();
...@@ -169,18 +170,6 @@ ...@@ -169,18 +170,6 @@
} }
} }
getSearchInput() {
const selectionStart = this.filteredSearchInput.selectionStart;
const inputValue = this.filteredSearchInput.value;
const rightPos = inputValue.slice(selectionStart).search(/\s/);
if (rightPos < 0) {
return inputValue;
}
return inputValue.slice(0, rightPos + selectionStart + 1).trim();
}
resetDropdowns() { resetDropdowns() {
// Force current dropdown to hide // Force current dropdown to hide
this.mapping[this.currentDropdown].reference.hideDropdown(); this.mapping[this.currentDropdown].reference.hideDropdown();
......
...@@ -30,12 +30,13 @@ ...@@ -30,12 +30,13 @@
this.checkForEnterWrapper = this.checkForEnter.bind(this); this.checkForEnterWrapper = this.checkForEnter.bind(this);
this.clearSearchWrapper = this.clearSearch.bind(this); this.clearSearchWrapper = this.clearSearch.bind(this);
this.checkForBackspaceWrapper = this.checkForBackspace.bind(this); this.checkForBackspaceWrapper = this.checkForBackspace.bind(this);
this.showOnClick = this.showOnClick.bind(this);
this.filteredSearchInput.addEventListener('input', this.setDropdownWrapper); this.filteredSearchInput.addEventListener('input', this.setDropdownWrapper);
this.filteredSearchInput.addEventListener('input', this.toggleClearSearchButtonWrapper); this.filteredSearchInput.addEventListener('input', this.toggleClearSearchButtonWrapper);
this.filteredSearchInput.addEventListener('keydown', this.checkForEnterWrapper); this.filteredSearchInput.addEventListener('keydown', this.checkForEnterWrapper);
this.filteredSearchInput.addEventListener('keyup', this.checkForBackspaceWrapper); this.filteredSearchInput.addEventListener('keyup', this.checkForBackspaceWrapper);
this.filteredSearchInput.addEventListener('click', this.setDropdownWrapper); this.filteredSearchInput.addEventListener('click', this.showOnClick);
this.clearSearchButton.addEventListener('click', this.clearSearchWrapper); this.clearSearchButton.addEventListener('click', this.clearSearchWrapper);
} }
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
this.filteredSearchInput.removeEventListener('input', this.toggleClearSearchButtonWrapper); this.filteredSearchInput.removeEventListener('input', this.toggleClearSearchButtonWrapper);
this.filteredSearchInput.removeEventListener('keydown', this.checkForEnterWrapper); this.filteredSearchInput.removeEventListener('keydown', this.checkForEnterWrapper);
this.filteredSearchInput.removeEventListener('keyup', this.checkForBackspaceWrapper); this.filteredSearchInput.removeEventListener('keyup', this.checkForBackspaceWrapper);
this.filteredSearchInput.removeEventListener('click', this.showOnClick);
this.clearSearchButton.removeEventListener('click', this.clearSearchWrapper); this.clearSearchButton.removeEventListener('click', this.clearSearchWrapper);
} }
...@@ -189,6 +191,13 @@ ...@@ -189,6 +191,13 @@
} }
return usernamesById; return usernamesById;
} }
showOnClick() {
const currentDropdownRef = this.dropdownManager.mapping[this.dropdownManager.currentDropdown].reference;
this.setDropdownWrapper();
currentDropdownRef.dispatchInputEvent();
}
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
......
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