From 8b271aea7946a8ae4e705259964a4d7c88e07916 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Fri, 28 Feb 2014 16:18:15 -0800 Subject: [PATCH 1/4] Skip all embedded php code when parsing the style blocks in php documents. --- src/language/HTMLUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index fd10be9b849..eec03e5c3f9 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -493,8 +493,10 @@ define(function (require, exports, module) { // Handle empty blocks currentBlock.end = currentBlock.start; } - // Check for end of this block - if (tokenModeName !== modeName) { + // Check for end of this block which normally is the tag + // with tokenModeName in "xml". If we encounter embedded php code, we + // will get "clike" tokenModeName and we need to skip all of them. + if (tokenModeName != "clike" && tokenModeName !== modeName) { // currentBlock.end is already set to pos of the last token by now currentBlock.text = editor.document.getRange(currentBlock.start, currentBlock.end); inBlock = false; From a647ee65c39ff42f38238f922bded2f5fea63f5e Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Fri, 28 Feb 2014 16:26:16 -0800 Subject: [PATCH 2/4] Oops. missing one '=' sign. --- src/language/HTMLUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index eec03e5c3f9..7bb0f58a51a 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -496,7 +496,7 @@ define(function (require, exports, module) { // Check for end of this block which normally is the tag // with tokenModeName in "xml". If we encounter embedded php code, we // will get "clike" tokenModeName and we need to skip all of them. - if (tokenModeName != "clike" && tokenModeName !== modeName) { + if (tokenModeName !== "clike" && tokenModeName !== modeName) { // currentBlock.end is already set to pos of the last token by now currentBlock.text = editor.document.getRange(currentBlock.start, currentBlock.end); inBlock = false; From ceec9158a0e44fae5b903a30906258b201907d20 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Fri, 28 Feb 2014 23:36:07 -0800 Subject: [PATCH 3/4] Add a new unit test for this issue. --- .../InlineEditorProviders-test-files/test1.php | 14 ++++++++++++++ test/spec/InlineEditorProviders-test.js | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/spec/InlineEditorProviders-test-files/test1.php diff --git a/test/spec/InlineEditorProviders-test-files/test1.php b/test/spec/InlineEditorProviders-test-files/test1.php new file mode 100644 index 00000000000..f0d07e12d2b --- /dev/null +++ b/test/spec/InlineEditorProviders-test-files/test1.php @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/test/spec/InlineEditorProviders-test.js b/test/spec/InlineEditorProviders-test.js index ecb7a2fcff9..43bb87e84d8 100644 --- a/test/spec/InlineEditorProviders-test.js +++ b/test/spec/InlineEditorProviders-test.js @@ -257,6 +257,21 @@ define(function (require, exports, module) { }); + it("should open a type selector and show correct range including the embedded php", function () { + initInlineTest("test1.php", 1); + + runs(function () { + var inlineWidget = EditorManager.getCurrentFullEditor().getInlineWidgets()[0]; + var inlinePos = inlineWidget.editor.getCursorPos(); + + // verify cursor position and displayed range in inline editor + expect(inlinePos).toEqual(infos["test1.php"].offsets[0]); + expect(inlineWidget.editor).toHaveInlineEditorRange(toRange(4, 8)); + + inlineWidget = null; + }); + }); + it("should open a type selector on opening tag", function () { initInlineTest("test1.html", 0); From fbccf8889c0df9aa214810d00ccbbeb85818c013 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Sun, 23 Mar 2014 13:43:46 -0700 Subject: [PATCH 4/4] Use a more generic solution by tracking previous mode and exit only if we're back to previous mode. --- src/language/HTMLUtils.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 7bb0f58a51a..d8ecce3ae95 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -484,7 +484,8 @@ define(function (require, exports, module) { currentBlock = null, inBlock = false, outerMode = editor._codeMirror.getMode(), - tokenModeName; + tokenModeName, + previousMode; while (TokenUtils.moveNextToken(ctx, false)) { tokenModeName = CodeMirror.innerMode(outerMode, ctx.token.state).mode.name; @@ -493,10 +494,8 @@ define(function (require, exports, module) { // Handle empty blocks currentBlock.end = currentBlock.start; } - // Check for end of this block which normally is the tag - // with tokenModeName in "xml". If we encounter embedded php code, we - // will get "clike" tokenModeName and we need to skip all of them. - if (tokenModeName !== "clike" && tokenModeName !== modeName) { + // Check for end of this block + if (tokenModeName === previousMode) { // currentBlock.end is already set to pos of the last token by now currentBlock.text = editor.document.getRange(currentBlock.start, currentBlock.end); inBlock = false; @@ -511,6 +510,8 @@ define(function (require, exports, module) { }; blocks.push(currentBlock); inBlock = true; + } else { + previousMode = tokenModeName; } // else, random token: ignore }