mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Merge pull request #3822 from adobe/dangoor/3589-underscore-names
Fix 3589 sort _ names to the bottom.
This commit is contained in:
commit
9b2e9c4611
5 files changed
+137
-24
No files matched your search
@@ -364,7 +364,28 @@ define(function (require, exports, module) {
|
||||
context: context
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Comparison function used for sorting that does a case-insensitive string
|
||||
// comparison on the "value" field of both objects. Unlike a normal string
|
||||
// comparison, however, this sorts leading "_" to the bottom, given that a
|
||||
// leading "_" usually denotes a private value.
|
||||
function penalizeUnderscoreValueCompare(a, b) {
|
||||
var aName = a.value.toLowerCase(), bName = b.value.toLowerCase();
|
||||
// this sort function will cause _ to sort lower than lower case
|
||||
// alphabetical letters
|
||||
if (aName[0] === "_" && bName[0] !== "_") {
|
||||
return 1;
|
||||
} else if (bName[0] === "_" && aName[0] !== "_") {
|
||||
return -1;
|
||||
}
|
||||
if (aName < bName) {
|
||||
return -1;
|
||||
} else if (aName > bName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of hints for the current session using the current scope
|
||||
* information.
|
||||
@@ -440,7 +461,7 @@ define(function (require, exports, module) {
|
||||
if (type.property) {
|
||||
hints = this.ternHints || [];
|
||||
hints = filterWithQueryAndMatcher(hints, matcher);
|
||||
StringMatch.multiFieldSort(hints, { matchGoodness: 0, value: 1 });
|
||||
StringMatch.multiFieldSort(hints, [ "matchGoodness", penalizeUnderscoreValueCompare ]);
|
||||
} else if (type.showFunctionType) {
|
||||
hints = this.getFunctionTypeHint();
|
||||
} else { // identifiers, literals, and keywords
|
||||
@@ -448,7 +469,7 @@ define(function (require, exports, module) {
|
||||
hints = hints.concat(HintUtils.LITERALS);
|
||||
hints = hints.concat(HintUtils.KEYWORDS);
|
||||
hints = filterWithQueryAndMatcher(hints, matcher);
|
||||
StringMatch.multiFieldSort(hints, { matchGoodness: 0, depth: 1, builtin: 2, value: 3 });
|
||||
StringMatch.multiFieldSort(hints, [ "matchGoodness", "depth", "builtin", penalizeUnderscoreValueCompare ]);
|
||||
}
|
||||
|
||||
if (hints.length > MAX_DISPLAYED_HINTS) {
|
||||
|
||||
@@ -143,3 +143,4 @@ var funArr = [];
|
||||
funArr.index1 = testRef1;
|
||||
funArr.index2 = testRef2;
|
||||
|
||||
var _A1 = A1;
|
||||
@@ -1055,6 +1055,12 @@ define(function (require, exports, module) {
|
||||
expectNoHints(JSCodeHints.jsHintProvider);
|
||||
});
|
||||
});
|
||||
|
||||
it("should sort underscore names to the bottom", function () {
|
||||
testEditor.setCursorPos({ line: 146, ch: 0 });
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
hintsPresentOrdered(hintObj, ["A1", "A2", "A3", "funB", "_A1"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript Code Hinting in a HTML file", function () {
|
||||
|
||||
Reference in new issue
Block a user