From b204cd72366c343435616445b7aa6e5c66b529c1 Mon Sep 17 00:00:00 2001 From: Adam Jimenez Date: Wed, 29 Oct 2014 17:01:41 +0000 Subject: [PATCH] use mode delegates in PHP fixes #2197 --- lib/ace/mode/php.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index beeefda7..3bb2e6a5 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -41,8 +41,11 @@ var WorkerClient = require("../worker/worker_client").WorkerClient; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var CStyleFoldMode = require("./folding/cstyle").FoldMode; var unicode = require("../unicode"); +var HtmlMode = require("./html").Mode; +var JavaScriptMode = require("./javascript").Mode; +var CssMode = require("./css").Mode; -var Mode = function(opts) { +var PhpMode = function(opts) { this.inlinePhp = opts && opts.inline; var HighlightRules = this.inlinePhp ? PhpLangHighlightRules : PhpHighlightRules; this.HighlightRules = HighlightRules; @@ -50,7 +53,18 @@ var Mode = function(opts) { this.$behaviour = new CstyleBehaviour(); this.foldingRules = new CStyleFoldMode(); }; -oop.inherits(Mode, TextMode); +oop.inherits(PhpMode, TextMode); + +var Mode = function() { + HtmlMode.call(this); + this.HighlightRules = PhpHighlightRules; + this.createModeDelegates({ + "js-": JavaScriptMode, + "css-": CssMode, + "php-": PhpMode + }); +}; +oop.inherits(Mode, HtmlMode); (function() { @@ -60,7 +74,7 @@ oop.inherits(Mode, TextMode); + unicode.packages.Nd + unicode.packages.Pc + "\_]+", "g" ); - + this.nonTokenRe = new RegExp("^(?:[^" + unicode.packages.L + unicode.packages.Mn + unicode.packages.Mc @@ -68,7 +82,7 @@ oop.inherits(Mode, TextMode); + unicode.packages.Pc + "\_]|\s])+", "g" ); - + this.lineCommentStart = ["//", "#"]; this.blockComment = {start: "/*", end: "*/"}; @@ -106,17 +120,19 @@ oop.inherits(Mode, TextMode); }; this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); + if (this.$outdent) + return this.$outdent.checkOutdent(line, input); }; this.autoOutdent = function(state, doc, row) { - this.$outdent.autoOutdent(doc, row); + if (this.$outdent) + this.$outdent.autoOutdent(doc, row); }; this.createWorker = function(session) { var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker"); worker.attachToDocument(session.getDocument()); - + if (this.inlinePhp) worker.call("setOptions", [{inline: true}]);