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:
parent
84358e859b
commit
e2c1ed826a
1 changed files with 6 additions and 4 deletions
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue