kopia lustrzana https://github.com/c9/core
Merge pull request +12484 from c9/fix-trim-trailing-space
keep cursor position when removing trailing space on savepull/263/head
commit
d7cc31ef8b
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Ładowanie…
Reference in New Issue