Fix bug that resulted from mucking with line ranges.

Partial fix for #205. Still needs a solution in order to restore folds
after we've trimmed all the lines.
This commit is contained in:
Thomas Wilburn 2014-05-12 16:26:42 -07:00
parent 84358e859b
commit e2c1ed826a

View file

@ -128,23 +128,25 @@ define([
editor.session.doc.setNewLineMode(type);
if (c) c();
});
command.on("ace:trim-whitespace", function(c) {
var session = editor.getSession();
var doc = session.doc;
var selection = editor.getSelection();
var lines = doc.getAllLines();
var folds = session.getAllFolds();
lines.forEach(function(line, i) {
var range = selection.getLineRange(i);
range.end.row = range.start.row;
range.end.column = line.length;
if (userConfig.trimEmptyLines) {
line = line.replace(/\s+$/, "");
} else {
line = line.replace(/(\S)\s+$/, "$1");
}
doc.replace(range, line);
doc.replace(range, line + doc.getNewLineCharacter());
});
//currently, restoring folds is hard because they depend on character positions that change after trimming
//if we can figure out how to update the indexes, we'll restore folds after saving
//session.addFolds(folds);
if (c) c();
});