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

Commit 45e9571

Browse files
committed
Merge pull request #3419 from WebsiteDeveloper/Issue-3407
Added Code to HtmlUtils to return info when in closing tag
2 parents 0f8410f + 53cbe28 commit 45e9571

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

src/editor/CSSInlineEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ define(function (require, exports, module) {
4444
var tagInfo = HTMLUtils.getTagInfo(editor, pos),
4545
selectorName = "";
4646

47-
if (tagInfo.position.tokenType === HTMLUtils.TAG_NAME) {
47+
if (tagInfo.position.tokenType === HTMLUtils.TAG_NAME || tagInfo.position.tokenType === HTMLUtils.CLOSING_TAG) {
4848
// Type selector
4949
selectorName = tagInfo.tagName;
5050
} else if (tagInfo.position.tokenType === HTMLUtils.ATTR_NAME ||

src/language/HTMLUtils.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ define(function (require, exports, module) {
3232

3333
//constants
3434
var TAG_NAME = "tagName",
35+
CLOSING_TAG = "closingTag",
3536
ATTR_NAME = "attr.name",
3637
ATTR_VALUE = "attr.value";
3738

@@ -399,12 +400,16 @@ define(function (require, exports, module) {
399400
return createTagInfo();
400401
}
401402

402-
// Check to see if this is the closing of a tag (either the start or end)
403-
if (ctx.token.string === ">" || ctx.token.string === "/>" ||
404-
(ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/")) {
403+
// Check to see if this is the closing of a start tag or a self closing tag
404+
if (ctx.token.string === ">" || ctx.token.string === "/>") {
405405
return createTagInfo();
406406
}
407407

408+
// Check to see if this is a closing tag
409+
if (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/") {
410+
return createTagInfo(CLOSING_TAG, offset - 2, ctx.token.string.slice(2));
411+
}
412+
408413
// Make sure the cursor is not after an equal sign or a quote before we report the context as a tag.
409414
if (ctx.token.string !== "=" && ctx.token.string.match(/^["']/) === null) {
410415
if (!tokenType) {
@@ -504,14 +509,15 @@ define(function (require, exports, module) {
504509

505510

506511
// Define public API
507-
exports.TAG_NAME = TAG_NAME;
508-
exports.ATTR_NAME = ATTR_NAME;
509-
exports.ATTR_VALUE = ATTR_VALUE;
512+
exports.TAG_NAME = TAG_NAME;
513+
exports.CLOSING_TAG = CLOSING_TAG;
514+
exports.ATTR_NAME = ATTR_NAME;
515+
exports.ATTR_VALUE = ATTR_VALUE;
510516

511-
exports.getTagInfo = getTagInfo;
517+
exports.getTagInfo = getTagInfo;
512518
exports.getTagAttributes = getTagAttributes;
513519
//The createTagInfo is really only for the unit tests so they can make the same structure to
514520
//compare results with
515-
exports.createTagInfo = createTagInfo;
521+
exports.createTagInfo = createTagInfo;
516522
exports.findStyleBlocks = findStyleBlocks;
517523
});

test/spec/CodeHintUtils-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ define(function (require, exports, module) {
244244
"</body></ht", "ml>");
245245

246246
var tag = HTMLUtils.getTagInfo(myEditor, pos);
247-
expect(tag).toEqual(HTMLUtils.createTagInfo());
247+
expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.CLOSING_TAG, 2, "html"));
248248
});
249249

250250
it("should not find attributes in an empty editor", function () {

test/spec/InlineEditorProviders-test-files/test1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<div{{0}} class="{{1}}foo" id="myDiv{{2}}">{{3}}</div>
99
<!--<div{{4}}>-->
1010
<div id="anotherDiv{{6}}"></div>
11-
<div{{8}} {{7}}class="foo"></div>
11+
<div{{8}} {{7}}class="foo"></{{9}}div>
1212
</body>
1313
</html>

test/spec/InlineEditorProviders-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ define(function (require, exports, module) {
252252
});
253253

254254

255-
it("should open a type selector", function () {
255+
it("should open a type selector on opening tag", function () {
256256
initInlineTest("test1.html", 0);
257257

258258
runs(function () {
@@ -263,6 +263,18 @@ define(function (require, exports, module) {
263263
expect(inlinePos).toEqual(this.infos["test1.css"].offsets[0]);
264264
});
265265
});
266+
267+
it("should open a type selector on closing tag", function () {
268+
initInlineTest("test1.html", 9);
269+
270+
runs(function () {
271+
var inlineWidget = EditorManager.getCurrentFullEditor().getInlineWidgets()[0];
272+
var inlinePos = inlineWidget.editors[0].getCursorPos();
273+
274+
// verify cursor position in inline editor
275+
expect(inlinePos).toEqual(this.infos["test1.css"].offsets[0]);
276+
});
277+
});
266278

267279
it("should open a class selector", function () {
268280
initInlineTest("test1.html", 1);

0 commit comments

Comments
 (0)