diff --git a/lib/ace/mode/javascript_test.js b/lib/ace/mode/javascript_test.js index 7de4aec2..b413765a 100644 --- a/lib/ace/mode/javascript_test.js +++ b/lib/ace/mode/javascript_test.js @@ -127,9 +127,13 @@ module.exports = { assert.equal([" abc", " cde", " fg"].join("\n"), session.toString()); session.setTabSize(4); this.mode.toggleCommentLines("start", session, 0, 2); - assert.equal(["// abc", "// cde", "// fg"].join("\n"), session.toString()); + assert.equal(["// abc", "// cde", "// fg"].join("\n"), session.toString()); this.mode.toggleCommentLines("start", session, 0, 2); assert.equal([" abc", " cde", " fg"].join("\n"), session.toString()); + + session.insert({row: 0, column: 0}, " "); + this.mode.toggleCommentLines("start", session, 0, 2); + assert.equal(["// abc", "// cde", "// fg"].join("\n"), session.toString()); }, //there doesn't seem to be any way to make this work "!test: togglecomment on line with one space" : function() { diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index d90cd4a4..e243ddbd 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -143,17 +143,19 @@ var Mode = function() { return regexpStart.test(line); }; - var shouldInsertSpace = function(line, pos1, pos2) { + var shouldInsertSpace = function(line, before, after) { var spaces = 0; - while (pos1-- && line.charAt(pos1) == " ") + while (before-- && line.charAt(before) == " ") spaces++; if (spaces % tabSize != 0) return false; var spaces = 0; - while (line.charAt(pos2++) == " ") + while (line.charAt(after++) == " ") spaces++; - if (spaces % tabSize != 0) - return false; + if (tabSize > 2) + return spaces % tabSize != tabSize - 1; + else + return spaces % tabSize == 0; return true; }; } @@ -184,7 +186,7 @@ var Mode = function() { } if (insertAtTabStop && minIndent % tabSize != 0) - minIndent = Math.floor(minIndent / tabSize); + minIndent = Math.floor(minIndent / tabSize) * tabSize; iter(shouldRemove ? uncomment : comment); };