Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/language/HTMLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 </style> 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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be too hard-coded of a solution. Other devs will want to do something similar for other server-side markup. Also, the mode for php could eventally change to something more specific.

A more generic solution may be this:

  • Once you hit tokenModeName === modeName case, scan until you return to tokenModeName === outerMode
  • I am not sure if using outerMode will work in all cases, you might need to keep track of previousMode (the mode of token before you enter modeName mode), and then scan until you return to previousMode mode.

What do you think of either of those solutions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previousMode tracking may be more reliable if we can safely assume that we always have well-formed style blocks. Anyway, I'll make a change with that assumption until someone can prove that to be wrong.

// currentBlock.end is already set to pos of the last token by now
currentBlock.text = editor.document.getRange(currentBlock.start, currentBlock.end);
inBlock = false;
Expand Down
14 changes: 14 additions & 0 deletions test/spec/InlineEditorProviders-test-files/test1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
{{0}} body {
background: url("<?php echo $img; ?>") no-repeat;
background-size: 100% 100%;
color: white;
}
</style>
</head>

<bo{{1}}dy onclick="goHome()"></body>
</html>
15 changes: 15 additions & 0 deletions test/spec/InlineEditorProviders-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down