add trimEmpty options to trimTrailingSpace, cleanup

This commit is contained in:
nightwing 2013-08-26 21:58:31 +04:00
commit c62e0d3062

View file

@ -63,7 +63,7 @@ exports.$detectIndentation = function(lines, fallback) {
// ignore lines ending with backslash
while (line[line.length - 1] == "\\")
line = lines[i++];
};
}
function getScore(indent) {
var score = 0;
@ -113,15 +113,17 @@ exports.detectIndentation = function(session) {
return indent;
};
exports.trimTrailingSpace = function(session) {
exports.trimTrailingSpace = function(session, trimEmpty) {
var doc = session.getDocument();
var lines = doc.getAllLines();
var min = trimEmpty ? -1 : 0;
for (var i = 0, l=lines.length; i < l; i++) {
var line = lines[i];
var index = line.search(/\s+$/);
if (index !== -1)
if (index > min)
doc.removeInLine(i, index, line.length);
}
};
@ -160,14 +162,14 @@ exports.convertIndentation = function(session, ch, len) {
};
exports.$parseStringArg = function(text) {
var indent = {}
var indent = {};
if (/t/.test(text))
indent.ch = "\t";
else if (/s/.test(text))
indent.ch = " ";
var m = text.match(/\d+/);
if (m)
indent.length = parseInt(m[0]);
indent.length = parseInt(m[0], 10);
return indent;
};
@ -179,7 +181,7 @@ exports.$parseArg = function(arg) {
if (typeof arg.text == "string")
return exports.$parseStringArg(arg.text);
return arg;
}
};
exports.commands = [{
name: "detectIndentation",
@ -196,7 +198,7 @@ exports.commands = [{
name: "convertIndentation",
exec: function(editor, arg) {
var indent = exports.$parseArg(arg);
exports.convertIndentation(editor.session, arg.ch, arg.length);
exports.convertIndentation(editor.session, indent.ch, indent.length);
}
}, {
name: "setIndentation",
@ -205,6 +207,6 @@ exports.commands = [{
indent.length && editor.session.setTabSize(indent.length);
indent.ch && editor.session.setUseSoftTabs(indent.ch == " ");
}
}]
}];
});