mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Fix Issue #3511
when inserting a hint which is not a valid property name, such as 'my-key', insert the hint as ["my-key"] instead of .my-key. insertHint now runs the hint through the acorn tokenizer to see if it looks like a valid property name. If it's invalid, it replaces the '.' with brackets. Refactored some code in Session.getType() - pulled out a method to find the leading '.' in a property lookup, and use that method from the insertHint logic as well. Added 3 new unittests to test this new behavior.
This commit is contained in:
1 parent
d496a0c2e2
commit
a4c87a6bba
4 files changed
+114
-13
No files matched your search
@@ -665,6 +665,53 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
|
||||
it("should insert hint as [\"my-key\"] since 'my-key' is not a valid property name", function () {
|
||||
var start = { line: 49, ch: 0 },
|
||||
middle = { line: 49, ch: 5 },
|
||||
end = { line: 49, ch: 13 };
|
||||
|
||||
testDoc.replaceRange("arr.m", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, end)).toEqual("arr[\"my-key\"]");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(13);
|
||||
});
|
||||
});
|
||||
|
||||
it("should insert hint as [\"my-key\"] make sure this works if nothing is typed after the '.'", function () {
|
||||
var start = { line: 49, ch: 0 },
|
||||
middle = { line: 49, ch: 4 },
|
||||
end = { line: 49, ch: 13 };
|
||||
|
||||
testDoc.replaceRange("arr.", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, end)).toEqual("arr[\"my-key\"]");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(13);
|
||||
});
|
||||
});
|
||||
|
||||
it("should insert hint as '.for' since keywords can be used as property names", function () {
|
||||
var start = { line: 49, ch: 0 },
|
||||
middle = { line: 49, ch: 5 },
|
||||
end = { line: 49, ch: 7 };
|
||||
|
||||
testDoc.replaceRange("arr.f", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "for");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, end)).toEqual("arr.for");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(7);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user