diff --git a/src/mode/JavaScript.js b/src/mode/JavaScript.js index 017570aa..ce12eada 100644 --- a/src/mode/JavaScript.js +++ b/src/mode/JavaScript.js @@ -16,12 +16,23 @@ ace.mode.JavaScript.prototype.toggleCommentLines = function(doc, range, state) { ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) { var indent = this.$getIndent(line); + var tokenizedLine = this.$tokenizer.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-comment") { + if (endState == "start") { + return ""; + } var match = line.match(/^\s*(\/?)\*/); if (match) { if (match[1]) { diff --git a/test/MockRenderer.js b/test/MockRenderer.js index dfe202ee..f72bae3b 100644 --- a/test/MockRenderer.js +++ b/test/MockRenderer.js @@ -26,6 +26,10 @@ MockRenderer.prototype.getContainerElement = function() { return this.container; }; +MockRenderer.prototype.getMouseEventTarget = function() { + return this.container; +}; + MockRenderer.prototype.setDocument = function(doc) { this.lines = doc.lines; }; @@ -54,6 +58,9 @@ MockRenderer.prototype.scrollToRow = function(row) { this.layerConfig.lastVisibleRow = row + this.visibleRowCount; }; +MockRenderer.prototype.getScrollTopRow = function() { + return this.layerConfig.firstVisibleRow; +}; MockRenderer.prototype.draw = function() { }; diff --git a/test/mode/CssTest.js b/test/mode/CssTest.js index f31f01b4..56eec460 100644 --- a/test/mode/CssTest.js +++ b/test/mode/CssTest.js @@ -29,5 +29,6 @@ var CssTest = new TestCase("mode.CssTest", { "test: no indent increase after { in a comment" : function() { assertEquals(" ", this.mode.getNextLineIndent(" /*{", "start", " ")); + assertEquals(" ", this.mode.getNextLineIndent(" /*{ ", "start", " ")); } }); \ No newline at end of file diff --git a/test/mode/JavaScriptTest.js b/test/mode/JavaScriptTest.js index 436d3703..d617ebd8 100644 --- a/test/mode/JavaScriptTest.js +++ b/test/mode/JavaScriptTest.js @@ -54,7 +54,13 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", { }, "test: no auto indent after opening brace in multi line comment" : function() { - assertEquals("", this.mode.getNextLineIndent("/*if () {", " ")); + assertEquals("", this.mode.getNextLineIndent("/*if () {", "start", " ")); + assertEquals(" ", this.mode.getNextLineIndent(" abcd", "comment", " ")); + }, + + "test: no auto indent after opening brace in single line comment" : function() { + assertEquals("", this.mode.getNextLineIndent("//if () {", "start", " ")); + assertEquals(" ", this.mode.getNextLineIndent(" //if () {", "start", " ")); }, "test: no auto indent should add to existing indent" : function() { @@ -68,5 +74,14 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", { assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " ")); assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " ")); assertEquals(" ", this.mode.getNextLineIndent(" abc", "doc-comment", " ")); + }, + + "test: no indent after doc comments" : function() { + assertEquals("", this.mode.getNextLineIndent(" */", "doc-comment", " ")); } + +// "test: outdent if first non WS character in line is a closing brace" : function() { +// assertEquals("", this.mode.getNextLineIndent(")", "start", " ")); +// assertEquals(" ", this.mode.getNextLineIndent(" )", "start", " ")); +// } }); \ No newline at end of file