From 391342c496406b80e1fdcb43e374586360ca5d9b Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Fri, 12 Apr 2013 00:12:39 +0200 Subject: [PATCH 1/5] Added code to return tagName when in closing tag --- src/language/HTMLUtils.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index df7c779b167..1c4947fa975 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -32,6 +32,7 @@ define(function (require, exports, module) { //constants var TAG_NAME = "tagName", + CLOSING_TAG = "closingTag", ATTR_NAME = "attr.name", ATTR_VALUE = "attr.value"; @@ -399,10 +400,14 @@ define(function (require, exports, module) { return createTagInfo(); } - // Check to see if this is the closing of a tag (either the start or end) - if (ctx.token.string === ">" || ctx.token.string === "/>" || - (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/")) { - return createTagInfo(); + // Check to see if this is the closing of a tag (either the start or end) self closing tag + if (ctx.token.string === ">" || ctx.token.string === "/>") { + return createTagInfo(CLOSING_TAG, offset); + } + + // Check to see if this is the closing of a tag (either the start or end) closing tag + if (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/") { + return createTagInfo(CLOSING_TAG, offset, ctx.token.string.slice(2, ctx.token.string.indexOf(">"))); } // Make sure the cursor is not after an equal sign or a quote before we report the context as a tag. @@ -504,14 +509,15 @@ define(function (require, exports, module) { // Define public API - exports.TAG_NAME = TAG_NAME; - exports.ATTR_NAME = ATTR_NAME; - exports.ATTR_VALUE = ATTR_VALUE; + exports.TAG_NAME = TAG_NAME; + exports.CLOSING_TAG = CLOSING_TAG; + exports.ATTR_NAME = ATTR_NAME; + exports.ATTR_VALUE = ATTR_VALUE; - exports.getTagInfo = getTagInfo; + exports.getTagInfo = getTagInfo; exports.getTagAttributes = getTagAttributes; //The createTagInfo is really only for the unit tests so they can make the same structure to //compare results with - exports.createTagInfo = createTagInfo; + exports.createTagInfo = createTagInfo; exports.findStyleBlocks = findStyleBlocks; }); From a079da6515fa6d186cc9293c93c03bbe0bfb590c Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Fri, 12 Apr 2013 00:29:02 +0200 Subject: [PATCH 2/5] A few refactorings --- src/editor/CSSInlineEditor.js | 2 +- src/language/HTMLUtils.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/editor/CSSInlineEditor.js b/src/editor/CSSInlineEditor.js index 404c165a2ad..6ecceac2ffc 100644 --- a/src/editor/CSSInlineEditor.js +++ b/src/editor/CSSInlineEditor.js @@ -44,7 +44,7 @@ define(function (require, exports, module) { var tagInfo = HTMLUtils.getTagInfo(editor, pos), selectorName = ""; - if (tagInfo.position.tokenType === HTMLUtils.TAG_NAME) { + if (tagInfo.position.tokenType === HTMLUtils.TAG_NAME || tagInfo.position.tokenType === HTMLUtils.CLOSING_TAG) { // Type selector selectorName = tagInfo.tagName; } else if (tagInfo.position.tokenType === HTMLUtils.ATTR_NAME || diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 1c4947fa975..877a9a338c6 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -407,7 +407,11 @@ define(function (require, exports, module) { // Check to see if this is the closing of a tag (either the start or end) closing tag if (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/") { - return createTagInfo(CLOSING_TAG, offset, ctx.token.string.slice(2, ctx.token.string.indexOf(">"))); + if (ctx.token.string.indexOf(">") === -1) { + return createTagInfo(CLOSING_TAG, offset, ctx.token.string.slice(2)); + } else { + return createTagInfo(CLOSING_TAG, offset, ctx.token.string.slice(2, ctx.token.string.indexOf(">") + 1)); + } } // Make sure the cursor is not after an equal sign or a quote before we report the context as a tag. From b507ad0fb926cab4d6b617409657bdea16b2e00c Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Sat, 13 Apr 2013 10:27:03 +0200 Subject: [PATCH 3/5] Fixes after first review --- src/language/HTMLUtils.js | 8 ++------ test/spec/CodeHintUtils-test.js | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 877a9a338c6..7f167562dba 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -402,16 +402,12 @@ define(function (require, exports, module) { // Check to see if this is the closing of a tag (either the start or end) self closing tag if (ctx.token.string === ">" || ctx.token.string === "/>") { - return createTagInfo(CLOSING_TAG, offset); + return createTagInfo(); } // Check to see if this is the closing of a tag (either the start or end) closing tag if (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/") { - if (ctx.token.string.indexOf(">") === -1) { - return createTagInfo(CLOSING_TAG, offset, ctx.token.string.slice(2)); - } else { - return createTagInfo(CLOSING_TAG, offset, ctx.token.string.slice(2, ctx.token.string.indexOf(">") + 1)); - } + return createTagInfo(CLOSING_TAG, offset + 2, ctx.token.string.slice(2)); } // Make sure the cursor is not after an equal sign or a quote before we report the context as a tag. diff --git a/test/spec/CodeHintUtils-test.js b/test/spec/CodeHintUtils-test.js index 36851ab8706..02e33c8b2ac 100644 --- a/test/spec/CodeHintUtils-test.js +++ b/test/spec/CodeHintUtils-test.js @@ -186,6 +186,16 @@ define(function (require, exports, module) { expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.TAG_NAME)); }); + it("should hint tagname for a closing tag", function () { + var pos = {"ch": 0, "line": 0}; + setContentAndUpdatePos(pos, + ["", "", "
"], + ""); + + var tag = HTMLUtils.getTagInfo(myEditor, pos); + expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.CLOSING_TAG, 6, "html")); + }); + it("should find the tagname of the current tag if two tags are right next to each other", function () { var pos = {"ch": 0, "line": 0}; setContentAndUpdatePos(pos, @@ -237,16 +247,6 @@ define(function (require, exports, module) { expect(tag).toEqual(HTMLUtils.createTagInfo()); }); - it("should not hint anything inside a closing tag", function () { - var pos = {"ch": 0, "line": 0}; - setContentAndUpdatePos(pos, - ["", "", "
"], - ""); - - var tag = HTMLUtils.getTagInfo(myEditor, pos); - expect(tag).toEqual(HTMLUtils.createTagInfo()); - }); - it("should not find attributes in an empty editor", function () { var pos = {"ch": 0, "line": 0}; var attrs = HTMLUtils.getTagAttributes(myEditor, pos); From f50e376120537cd101b1809514588bfcc0dd082d Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Tue, 16 Apr 2013 19:17:52 +0200 Subject: [PATCH 4/5] Fixes after second review --- src/language/HTMLUtils.js | 2 +- test/spec/CodeHintUtils-test.js | 4 ++-- .../InlineEditorProviders-test-files/test1.html | 2 +- test/spec/InlineEditorProviders-test.js | 14 +++++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 7f167562dba..38478222694 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -407,7 +407,7 @@ define(function (require, exports, module) { // Check to see if this is the closing of a tag (either the start or end) closing tag if (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/") { - return createTagInfo(CLOSING_TAG, offset + 2, ctx.token.string.slice(2)); + return createTagInfo(CLOSING_TAG, offset - 2, ctx.token.string.slice(2)); } // Make sure the cursor is not after an equal sign or a quote before we report the context as a tag. diff --git a/test/spec/CodeHintUtils-test.js b/test/spec/CodeHintUtils-test.js index 02e33c8b2ac..34c92fb2ce0 100644 --- a/test/spec/CodeHintUtils-test.js +++ b/test/spec/CodeHintUtils-test.js @@ -186,14 +186,14 @@ define(function (require, exports, module) { expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.TAG_NAME)); }); - it("should hint tagname for a closing tag", function () { + it("should not hint anything inside a closing tag", function () { var pos = {"ch": 0, "line": 0}; setContentAndUpdatePos(pos, ["", "", "
"], ""); var tag = HTMLUtils.getTagInfo(myEditor, pos); - expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.CLOSING_TAG, 6, "html")); + expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.CLOSING_TAG, 2, "html")); }); it("should find the tagname of the current tag if two tags are right next to each other", function () { diff --git a/test/spec/InlineEditorProviders-test-files/test1.html b/test/spec/InlineEditorProviders-test-files/test1.html index b5bc8734841..8035194a733 100644 --- a/test/spec/InlineEditorProviders-test-files/test1.html +++ b/test/spec/InlineEditorProviders-test-files/test1.html @@ -8,6 +8,6 @@ {{3}}
- + \ No newline at end of file diff --git a/test/spec/InlineEditorProviders-test.js b/test/spec/InlineEditorProviders-test.js index 18ba6110962..21a54d5fd87 100644 --- a/test/spec/InlineEditorProviders-test.js +++ b/test/spec/InlineEditorProviders-test.js @@ -252,7 +252,7 @@ define(function (require, exports, module) { }); - it("should open a type selector", function () { + it("should open a type selector on opening tag", function () { initInlineTest("test1.html", 0); runs(function () { @@ -263,6 +263,18 @@ define(function (require, exports, module) { expect(inlinePos).toEqual(this.infos["test1.css"].offsets[0]); }); }); + + it("should open a type selector on closing tag", function () { + initInlineTest("test1.html", 9); + + runs(function () { + var inlineWidget = EditorManager.getCurrentFullEditor().getInlineWidgets()[0]; + var inlinePos = inlineWidget.editors[0].getCursorPos(); + + // verify cursor position in inline editor + expect(inlinePos).toEqual(this.infos["test1.css"].offsets[0]); + }); + }); it("should open a class selector", function () { initInlineTest("test1.html", 1); From 53cbe28bca553b0d9d5a7a62beeed0a9626a2fe5 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Sat, 20 Apr 2013 07:14:52 +0200 Subject: [PATCH 5/5] Minor fixes after review --- src/language/HTMLUtils.js | 4 ++-- test/spec/CodeHintUtils-test.js | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 38478222694..00b051c1824 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -400,12 +400,12 @@ define(function (require, exports, module) { return createTagInfo(); } - // Check to see if this is the closing of a tag (either the start or end) self closing tag + // Check to see if this is the closing of a start tag or a self closing tag if (ctx.token.string === ">" || ctx.token.string === "/>") { return createTagInfo(); } - // Check to see if this is the closing of a tag (either the start or end) closing tag + // Check to see if this is a closing tag if (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/") { return createTagInfo(CLOSING_TAG, offset - 2, ctx.token.string.slice(2)); } diff --git a/test/spec/CodeHintUtils-test.js b/test/spec/CodeHintUtils-test.js index 34c92fb2ce0..302f0d3637b 100644 --- a/test/spec/CodeHintUtils-test.js +++ b/test/spec/CodeHintUtils-test.js @@ -186,16 +186,6 @@ define(function (require, exports, module) { expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.TAG_NAME)); }); - it("should not hint anything inside a closing tag", function () { - var pos = {"ch": 0, "line": 0}; - setContentAndUpdatePos(pos, - ["", "", "
"], - ""); - - var tag = HTMLUtils.getTagInfo(myEditor, pos); - expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.CLOSING_TAG, 2, "html")); - }); - it("should find the tagname of the current tag if two tags are right next to each other", function () { var pos = {"ch": 0, "line": 0}; setContentAndUpdatePos(pos, @@ -247,6 +237,16 @@ define(function (require, exports, module) { expect(tag).toEqual(HTMLUtils.createTagInfo()); }); + it("should not hint anything inside a closing tag", function () { + var pos = {"ch": 0, "line": 0}; + setContentAndUpdatePos(pos, + ["", "", "
"], + ""); + + var tag = HTMLUtils.getTagInfo(myEditor, pos); + expect(tag).toEqual(HTMLUtils.createTagInfo(HTMLUtils.CLOSING_TAG, 2, "html")); + }); + it("should not find attributes in an empty editor", function () { var pos = {"ch": 0, "line": 0}; var attrs = HTMLUtils.getTagAttributes(myEditor, pos);