fix comment toggling on lines with wrong indentation
This commit is contained in:
parent
c2a50de10e
commit
a5e7d5d1f1
2 changed files with 13 additions and 7 deletions
|
|
@ -130,6 +130,10 @@ module.exports = {
|
||||||
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);
|
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());
|
||||||
|
|
||||||
|
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
|
//there doesn't seem to be any way to make this work
|
||||||
"!test: togglecomment on line with one space" : function() {
|
"!test: togglecomment on line with one space" : function() {
|
||||||
|
|
|
||||||
|
|
@ -143,17 +143,19 @@ var Mode = function() {
|
||||||
return regexpStart.test(line);
|
return regexpStart.test(line);
|
||||||
};
|
};
|
||||||
|
|
||||||
var shouldInsertSpace = function(line, pos1, pos2) {
|
var shouldInsertSpace = function(line, before, after) {
|
||||||
var spaces = 0;
|
var spaces = 0;
|
||||||
while (pos1-- && line.charAt(pos1) == " ")
|
while (before-- && line.charAt(before) == " ")
|
||||||
spaces++;
|
spaces++;
|
||||||
if (spaces % tabSize != 0)
|
if (spaces % tabSize != 0)
|
||||||
return false;
|
return false;
|
||||||
var spaces = 0;
|
var spaces = 0;
|
||||||
while (line.charAt(pos2++) == " ")
|
while (line.charAt(after++) == " ")
|
||||||
spaces++;
|
spaces++;
|
||||||
if (spaces % tabSize != 0)
|
if (tabSize > 2)
|
||||||
return false;
|
return spaces % tabSize != tabSize - 1;
|
||||||
|
else
|
||||||
|
return spaces % tabSize == 0;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +186,7 @@ var Mode = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insertAtTabStop && minIndent % tabSize != 0)
|
if (insertAtTabStop && minIndent % tabSize != 0)
|
||||||
minIndent = Math.floor(minIndent / tabSize);
|
minIndent = Math.floor(minIndent / tabSize) * tabSize;
|
||||||
|
|
||||||
iter(shouldRemove ? uncomment : comment);
|
iter(shouldRemove ? uncomment : comment);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue