Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1541 from adobe/rlim/code-hint-issues
Browse files Browse the repository at this point in the history
Fix code hints issues #1515 and #1519
  • Loading branch information
redmunds committed Sep 1, 2012
2 parents 6ef5c58 + 7b0466f commit 6168ae9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
57 changes: 54 additions & 3 deletions src/extensions/default/HTMLCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ define(function (require, exports, module) {
expect(hintList.indexOf("div")).toBe(-1);
expect(hintList.indexOf("span")).not.toBe(-1);
});

it("should list hints between '<' and some trailing spaces", function () { // (bug #1515)
// Replace line 9 with a complete div tag and insert a blank line and the closing div tag.
testDocument.replaceRange("<div>\n \n</div>", { line: 9, ch: 2 });
expect(testDocument.getLine(10)).toBe(" ");

// Insert a < on line 10
testDocument.replaceRange("<", { line: 10, ch: 0 });
testEditor.setCursorPos({ line: 10, ch: 1 }); // cursor between < and some trailing whitespaces
var hintList = expectHints(HTMLCodeHints.tagHintProvider);
verifyTagHints(hintList);

// Replace '< ' on line 10 with '<\t'
testDocument.replaceRange("<\t", { line: 10, ch: 0 }, { line: 10, ch: 2 });
testEditor.setCursorPos({ line: 10, ch: 1 }); // cursor between < and some trailing whitespaces
hintList = expectHints(HTMLCodeHints.tagHintProvider);
verifyTagHints(hintList);
});
});

describe("Attribute name hint provider", function () {
Expand Down Expand Up @@ -259,12 +277,45 @@ define(function (require, exports, module) {
expectNoHints(HTMLCodeHints.attrHintProvider);
});

it("should NOT list hints between two tags", function () { // (bug #1510)
it("should NOT list hints between begin 'div' and end 'div' tag", function () { // (bug #1510)
// replace line 9 with a complete div tag and insert a blank line and the closing div tag.
testDocument.replaceRange("<div>\n \n</div>", { line: 9, ch: 2 });
testDocument.replaceRange("<div>\n \n </div>", { line: 9, ch: 2 });

testEditor.setCursorPos({ line: 10, ch: 2 }); // cursor between whitespaces on the newly inserted blank line
expectNoHints(HTMLCodeHints.attrHintProvider);

testEditor.setCursorPos({ line: 9, ch: 7 }); // cursor to the right of <div>
expectNoHints(HTMLCodeHints.attrHintProvider);

testEditor.setCursorPos({ line: 11, ch: 2 }); // cursor to the left of </div>
expectNoHints(HTMLCodeHints.attrHintProvider);
});

it("should NOT list hints between an empty tag and 'body' end tag", function () { // (bug #1519)
// replace line 9 with an input tag and insert two extra blank lines with some whitespaces.
testDocument.replaceRange("<input type='button' />\n \n ", { line: 9, ch: 2 }, { line: 9, ch: 7 });

// Set cursor between whitespaces on one of the newly inserted blank lines.
testEditor.setCursorPos({ line: 11, ch: 2 });
expectNoHints(HTMLCodeHints.attrHintProvider);
});

it("should NOT list hints between the 'body' begin tag and 'h1' begin tag", function () { // (bug #1519)
// Insert two blank lines with some whitespaces before line 5.
testDocument.replaceRange("\n \n ", { line: 5, ch: 0 });

// Set cursor between whitespaces on one of the newly inserted blank lines.
testEditor.setCursorPos({ line: 7, ch: 2 });
expectNoHints(HTMLCodeHints.attrHintProvider);
});

it("should NOT list hints between the 'h1' end tag and 'h3' begin tag", function () { // (bug #1519)
// Insert two blank lines with some whitespaces before line 5.
testDocument.replaceRange("\n \n ", { line: 6, ch: 0 });

// Set cursor between whitespaces on one of the newly inserted blank lines.
testEditor.setCursorPos({ line: 8, ch: 2 });
expectNoHints(HTMLCodeHints.attrHintProvider);
});

it("should NOT list hints after an HTML comment", function () { // (bug #1440)
Expand Down Expand Up @@ -497,7 +548,7 @@ define(function (require, exports, module) {
expectCursorAt({ line: 9, ch: 16 }); // cursor after the closing quote
});

it("should insert the selected attribute value with the closing quote", function () {
it("should insert the selected attribute value WITHOUT begin or end quote", function () {
testDocument.replaceRange("dir=", { line: 9, ch: 7 }); // insert dir= after <div tag
testEditor.setCursorPos({ line: 9, ch: 11 });
selectHint(HTMLCodeHints.attrHintProvider, "rtl");
Expand Down
11 changes: 9 additions & 2 deletions src/language/HTMLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ define(function (require, exports, module) {
// Also we don't handle the "=" here.
tagInfo = _getTagInfoStartingFromAttrValue(ctx);

// Check to see if this is the closing of a tag (either the start or end)
if (ctx.token.className === "tag" &&
(ctx.token.string === ">" || ctx.token.string === "/>" ||
(ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/"))) {
return createTagInfo();
}

// If it wasn't an attr value, assume it was an empty attr (ie. attr with no value)
if (!tagInfo.tagName) {
tagInfo = _getTagInfoStartingFromAttrName(ctx, true);
Expand All @@ -406,12 +413,12 @@ define(function (require, exports, module) {

if (ctx.token.className === "tag") {
// Check if the user just typed a white space after "<" that made an existing tag invalid.
if (ctx.token.string.indexOf("< ") === 0) {
if (ctx.token.string.match(/^<\s+/) && offset !== 1) {
return createTagInfo();
}

// Check to see if this is the closing of a tag (either the start or end)
if (ctx.token.string === ">" ||
if (ctx.token.string === ">" || ctx.token.string === "/>" ||
(ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/")) {
return createTagInfo();
}
Expand Down

0 comments on commit 6168ae9

Please sign in to comment.