Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
c45dc802
Commit
c45dc802
authored
Jan 19, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly replaces string when selecting in dropdown
parent
ac080c63
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
24 deletions
+32
-24
app/assets/javascripts/filtered_search/dropdown_utils.js.es6
app/assets/javascripts/filtered_search/dropdown_utils.js.es6
+15
-3
app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
...s/filtered_search/filtered_search_dropdown_manager.js.es6
+15
-20
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
...avascripts/filtered_search/filtered_search_manager.js.es6
+2
-1
No files found.
app/assets/javascripts/filtered_search/dropdown_utils.js.es6
View file @
c45dc802
...
...
@@ -76,13 +76,25 @@
static getSearchInput(filteredSearchInput) {
const selectionStart = filteredSearchInput.selectionStart;
const inputValue = filteredSearchInput.value;
const
rightPos = inputValue.slice(selectionStart).search(/\s/
);
const
{ right } = gl.DropdownUtils.getInputSelectionPosition(filteredSearchInput
);
if (right
Pos
< 0) {
if (right < 0) {
return inputValue;
}
return inputValue.slice(0, rightPos + selectionStart + 1).trim();
return inputValue.slice(0, right + selectionStart + 1).trim();
}
static getInputSelectionPosition(input) {
const inputValue = input.value;
const selectionStart = input.selectionStart;
const left = inputValue.slice(0, selectionStart + 1).search(/\S+$/);
const right = inputValue.slice(selectionStart).search(/\s/);
return {
left,
right,
};
}
}
...
...
app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
View file @
c45dc802
...
...
@@ -57,30 +57,24 @@
static addWordToInput(tokenName, tokenValue = '') {
const input = document.querySelector('.filtered-search');
const inputValue = input.value;
const word = `${tokenName}:${tokenValue}`;
const inputValue = gl.DropdownUtils.getSearchInput(input).trim();
const { lastToken, searchToken } = gl.FilteredSearchTokenizer.processTokens(inputValue);
const lastSearchToken = searchToken.split(' ').last();
const lastInputCharacter = input.value[input.value.length - 1];
const lastInputTrimmedCharacter = input.value.trim()[input.value.trim().length - 1];
// Get the string to replace
const selectionStart = input.selectionStart;
const { left } = gl.DropdownUtils.getInputSelectionPosition(input);
let { right } = gl.DropdownUtils.getInputSelectionPosition(input);
// Remove the typed tokenName
if (word.indexOf(lastSearchToken) === 0 && searchToken !== '') {
// Remove spaces after the colon
if (lastInputCharacter === ' ' && lastInputTrimmedCharacter === ':') {
input.value = input.value.trim();
}
input.value = input.value.slice(0, -1 * lastSearchToken.length);
} else if (lastInputCharacter !== ' ' || (lastToken && lastToken.value[lastToken.value.length - 1] === ' ')) {
// Remove the existing tokenValue
const lastTokenString = `${lastToken.key}:${lastToken.symbol}${lastToken.value}`;
input.value = input.value.slice(0, -1 * lastTokenString.length);
if (right < 0) {
right = inputValue.length;
}
if (left !== -1) {
input.value = `${inputValue.substr(0, left)}${word}${inputValue.substr(right + selectionStart)}`;
} else {
input.value += word;
}
}
updateCurrentDropdownOffset() {
this.updateDropdownOffset(this.currentDropdown);
...
...
@@ -93,7 +87,8 @@
const filterIconPadding = 27;
const offset = gl.text
.getTextWidth(gl.DropdownUtils.getSearchInput(this.filteredSearchInput).trim(), this.font) + filterIconPadding;
.getTextWidth(gl.DropdownUtils.getSearchInput(this.filteredSearchInput).trim(), this.font)
+ filterIconPadding;
this.mapping[key].reference.setOffset(offset);
}
...
...
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
View file @
c45dc802
...
...
@@ -193,7 +193,8 @@
}
showOnClick() {
const currentDropdownRef = this.dropdownManager.mapping[this.dropdownManager.currentDropdown].reference;
const dropdown = this.dropdownManager.mapping[this.dropdownManager.currentDropdown];
const currentDropdownRef = dropdown.reference;
this.setDropdownWrapper();
currentDropdownRef.dispatchInputEvent();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment