add support for inline mode in php worker

This commit is contained in:
nightwing 2013-12-17 00:04:21 +04:00
commit 3a864c6056
2 changed files with 11 additions and 3 deletions

View file

@ -44,8 +44,8 @@ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var unicode = require("../unicode"); var unicode = require("../unicode");
var Mode = function(opts) { var Mode = function(opts) {
var inline = opts && opts.inline; this.inlinePhp = opts && opts.inline;
var HighlightRules = inline ? PhpLangHighlightRules : PhpHighlightRules; var HighlightRules = this.inlinePhp ? PhpLangHighlightRules : PhpHighlightRules;
this.HighlightRules = HighlightRules; this.HighlightRules = HighlightRules;
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour(); this.$behaviour = new CstyleBehaviour();
@ -117,6 +117,9 @@ oop.inherits(Mode, TextMode);
this.createWorker = function(session) { this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker"); var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker");
worker.attachToDocument(session.getDocument()); worker.attachToDocument(session.getDocument());
if (this.inlinePhp)
worker.call("setOptions", [{inline: true}]);
worker.on("error", function(e) { worker.on("error", function(e) {
session.setAnnotations(e.data); session.setAnnotations(e.data);

View file

@ -43,12 +43,17 @@ var PhpWorker = exports.PhpWorker = function(sender) {
oop.inherits(PhpWorker, Mirror); oop.inherits(PhpWorker, Mirror);
(function() { (function() {
this.setOptions = function(opts) {
this.inlinePhp = opts && opts.inline;
};
this.onUpdate = function() { this.onUpdate = function() {
var value = this.doc.getValue(); var value = this.doc.getValue();
var errors = []; var errors = [];
// var start = new Date(); // var start = new Date();
if (this.inlinePhp)
value = "<?" + value + "?>";
var tokens = PHP.Lexer(value, {short_open_tag: 1}); var tokens = PHP.Lexer(value, {short_open_tag: 1});
try { try {