From 2bd2e3736795387597f28cb7ba017663113e6889 Mon Sep 17 00:00:00 2001 From: Adam Jimenez Date: Thu, 30 Oct 2014 01:52:38 +0000 Subject: [PATCH] fix php indentation --- lib/ace/mode/php.js | 88 +++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/lib/ace/mode/php.js b/lib/ace/mode/php.js index 3bb2e6a5..101cc3c0 100644 --- a/lib/ace/mode/php.js +++ b/lib/ace/mode/php.js @@ -55,6 +55,51 @@ var PhpMode = function(opts) { }; oop.inherits(PhpMode, TextMode); +(function() { + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.getTokenizer().getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + var endState = tokenizedLine.state; + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[\:]\s*$/); + if (match) { + indent += tab; + } + } else if (state == "doc-start") { + if (endState != "doc-start") { + return ""; + } + var match = line.match(/^\s*(\/?)\*/); + if (match) { + if (match[1]) { + indent += " "; + } + indent += "* "; + } + } + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; + + this.$id = "ace/mode/php-inline"; +}).call(PhpMode.prototype); + var Mode = function() { HtmlMode.call(this); this.HighlightRules = PhpHighlightRules; @@ -86,49 +131,6 @@ oop.inherits(Mode, HtmlMode); this.lineCommentStart = ["//", "#"]; this.blockComment = {start: "/*", end: "*/"}; - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - - var tokenizedLine = this.getTokenizer().getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - var endState = tokenizedLine.state; - - - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "php-start") { - var match = line.match(/^.*[\{\(\[\:]\s*$/); - if (match) { - indent += tab; - } - } else if (state == "php-doc-start") { - if (endState != "php-doc-start") { - return ""; - } - var match = line.match(/^\s*(\/?)\*/); - if (match) { - if (match[1]) { - indent += " "; - } - indent += "* "; - } - } - - return indent; - }; - - this.checkOutdent = function(state, line, input) { - if (this.$outdent) - return this.$outdent.checkOutdent(line, input); - }; - - this.autoOutdent = function(state, 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());