Merge pull request +12484 from c9/fix-trim-trailing-space

keep cursor position when removing trailing space on save
pull/263/head
Harutyun Amirjanyan 2016-02-29 15:51:35 +04:00
commit d7cc31ef8b
2 zmienionych plików z 20 dodań i 3 usunięć

Wyświetl plik

@ -117,16 +117,33 @@ exports.detectIndentation = function(session) {
return indent;
};
exports.trimTrailingSpace = function(session, trimEmpty) {
/**
* EditSession session
* options.trimEmpty trim empty lines too
* options.keepCursorPosition do not trim whitespace before the cursor
*/
exports.trimTrailingSpace = function(session, options) {
var doc = session.getDocument();
var lines = doc.getAllLines();
var min = trimEmpty ? -1 : 0;
var min = options && options.trimEmpty ? -1 : 0;
var cursors = session.selection.rangeCount
? session.selection.ranges.map(function(x) { return x.cursor; })
: [session.selection.getCursor()];
var ci = options && options.keepCursorPosition ? 0 : -1;
var cursorRow = cursors[ci] && cursors[ci].row;
for (var i = 0, l=lines.length; i < l; i++) {
var line = lines[i];
var index = line.search(/\s+$/);
if (i == cursorRow) {
if (index < cursors[ci].column)
index = min;
ci++;
cursorRow = cursors[ci] ? cursors[ci].row : -1;
}
if (index > min)
doc.removeInLine(i, index, line.length);
}

Wyświetl plik

@ -81,7 +81,7 @@
"c9.ide.ace.repl": "#4b88a85b7b",
"c9.ide.ace.split": "#0ae0151c78",
"c9.ide.ace.statusbar": "#3aab0b67e0",
"c9.ide.ace.stripws": "#cf0f42ac59",
"c9.ide.ace.stripws": "#8885016b9e",
"c9.ide.behaviors": "#db32109ebc",
"c9.ide.closeconfirmation": "#cee4674141",
"c9.ide.configuration": "#528234d97d",