fix comment toggling on lines with wrong indentation

This commit is contained in:
nightwing 2013-05-20 19:38:42 +04:00
commit a5e7d5d1f1
2 changed files with 13 additions and 7 deletions

View file

@ -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() {

View file

@ -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);
};