Skip to content

Commit

Permalink
fix(autocomplete): correct filtering of colors
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
ewanharris committed Mar 20, 2019
1 parent 4514d57 commit ffb340e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/providers/styleAutoCompleteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default {
},

getPropertyValueCompletions(request) {
const { bufferPosition, editor, prefix, scopeDescriptor } = request;
let { bufferPosition, editor, prefix, scopeDescriptor } = request;
const property = this.getPreviousPropertyName(bufferPosition, editor);
// const parentPropertyName = this.getParentObjectName(bufferPosition, editor);

Expand All @@ -273,17 +273,19 @@ export default {

const completions = [];
if (this.isPropertyValuePrefix(prefix)) {
for (const value of values) {
if (Utils.firstCharsEqual(value.replace(/"/g, ''), prefix.replace(/"/g, ''))) {
if (Utils.firstCharsEqual(value, prefix)) {
completions.push(this.buildPropertyValueCompletion(value, property, scopes, request));
} else {
// completions.push(this.buildPropertyValueCompletionWidthQuotation(value, property, scopes, request));
}
for (let value of values) {
if (/["']/.test(value)) {
value = value.replace(/["']/g, '');
}
if (Utils.firstCharsEqual(value, prefix)) {
completions.push(this.buildPropertyValueCompletion(value, property, scopes, request));
}
}
} else {
for (const value of values) {
for (let value of values) {
if (/["']/.test(value)) {
value = value.replace(/["']/g, '');
}
completions.push(this.buildPropertyValueCompletion(value, property, scopes, request));
}
}
Expand Down
9 changes: 9 additions & 0 deletions spec/styleAutoCompleteProvider-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,13 @@ describe('Property suggestions', function () {

expect(suggestions.length).toBe(0);
});

it('should provide color values', function () {
Project.isTitaniumApp = true;
initTextEditor('"#id":{');
editor.insertNewline();
editor.insertText('color: "ma"');
const suggestions = getSuggestions('"ma"');
expect(suggestions.length).toBe(2);
});
});

0 comments on commit ffb340e

Please sign in to comment.