Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/extensions/default/CSSCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ define(function (require, exports, module) {
HTMLUtils = brackets.getModule("language/HTMLUtils"),
LanguageManager = brackets.getModule("language/LanguageManager"),
TokenUtils = brackets.getModule("utils/TokenUtils"),
StringMatch = brackets.getModule("utils/StringMatch"),
CSSProperties = require("text!CSSProperties.json"),
properties = JSON.parse(CSSProperties);

// Context of the last request for hints: either CSSUtils.PROP_NAME,
// CSSUtils.PROP_VALUE or null.
var lastContext;
var lastContext,
stringMatcherOptions = { preferPrefixMatches: true };

/**
* @constructor
Expand Down Expand Up @@ -249,10 +251,17 @@ define(function (require, exports, module) {
}

result = $.map(valueArray, function (pvalue, pindex) {
if (pvalue.indexOf(valueNeedle) === 0) {
return pvalue;
var result = StringMatch.stringMatch(pvalue, valueNeedle, stringMatcherOptions);
if (result) {
return result;
}
}).sort();
});

StringMatch.basicMatchSort(result);

result = $.map(result, function (entry) {
return entry.label;
});

return {
hints: result,
Expand All @@ -268,11 +277,19 @@ define(function (require, exports, module) {

lastContext = CSSUtils.PROP_NAME;
needle = needle.substr(0, this.info.offset);

result = $.map(properties, function (pvalues, pname) {
if (pname.indexOf(needle) === 0) {
return pname;
var result = StringMatch.stringMatch(pname, needle, stringMatcherOptions);
if (result) {
return result;
}
}).sort();
});

StringMatch.basicMatchSort(result);

result = $.map(result, function (entry) {
return entry.label;
});

return {
hints: result,
Expand Down
34 changes: 29 additions & 5 deletions src/extensions/default/CSSCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,17 @@ define(function (require, exports, module) {
expect(hintList.indexOf("div")).toBe(-1);
expect(hintList[0]).toBe(expectedFirstHint);
}


// compares lists to ensure they are the same
function verifyListsAreIdentical(hintList, values) {
var i;
expect(hintList.length).toBe(values.length);
for (i = 0; i < values.length; i++) {
expect(hintList[i]).toBe(values[i]);
}
}


function selectHint(provider, expectedHint, implicitChar) {
var hintList = expectHints(provider, implicitChar);
expect(hintList.indexOf(expectedHint)).not.toBe(-1);
Expand Down Expand Up @@ -175,7 +185,11 @@ define(function (require, exports, module) {
testEditor.setCursorPos({ line: 9, ch: 12 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "border-color"); // filtered on "border-color"
expect(hintList.length).toBe(1);
verifyListsAreIdentical(hintList, ["border-color",
"border-left-color",
"border-top-color",
"border-bottom-color",
"border-right-color"]);
});

it("should list prop-name hints at end of property-value finished by ;", function () {
Expand Down Expand Up @@ -383,8 +397,18 @@ define(function (require, exports, module) {
it("should list prop-name hints inside multi-line styletags with cursor in last line", function () {
testEditor.setCursorPos({ line: 10, ch: 5 }); // inside style, after colo
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "color"); // filtered on "colo"
expect(hintList.length).toBe(1);
verifyListsAreIdentical(hintList, ["color",
"border-color",
"background-color",
"border-left-color",
"border-top-color",
"outline-color",
"border-bottom-color",
"border-right-color",
"text-decoration-color",
"text-emphasis-color",
"column-count",
"column-rule-color"]);
});

it("should NOT list prop-name hints between closed styletag and new opening styletag", function () {
Expand Down Expand Up @@ -588,7 +612,7 @@ define(function (require, exports, module) {

testEditor.setCursorPos({ line: 66, ch: 16 }); // after flow-from: m
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAllValues(hintList, ["main"]);
verifyListsAreIdentical(hintList, ["main", "lim"]);
});

});
Expand Down