Use Ace search to trim lines. Fixes #205 (for real this time).
This commit is contained in:
parent
e2c1ed826a
commit
0437e6b30f
2 changed files with 16 additions and 15 deletions
|
@ -131,22 +131,23 @@ define([
|
|||
|
||||
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);
|
||||
if (userConfig.trimEmptyLines) {
|
||||
line = line.replace(/\s+$/, "");
|
||||
} else {
|
||||
line = line.replace(/(\S)\s+$/, "$1");
|
||||
}
|
||||
doc.replace(range, line + doc.getNewLineCharacter());
|
||||
var doc = session.doc;
|
||||
var trimEmpty = userConfig.trimEmptyLines;
|
||||
var Search = ace.require("./search").Search;
|
||||
var re = trimEmpty ? /\s+$/ : /(\S)\s+$/;
|
||||
var search = new Search().set({
|
||||
wrap: true,
|
||||
needle: re
|
||||
});
|
||||
//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);
|
||||
var ranges = search.findAll(session);
|
||||
ranges.forEach(function(range) {
|
||||
var original = session.getTextRange(range);
|
||||
var replaced = original.replace(re, trimEmpty ? "" : "$1");
|
||||
doc.replace(range, replaced);
|
||||
});
|
||||
session.unfold();
|
||||
session.addFolds(folds);
|
||||
if (c) c();
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Caret",
|
||||
"description": "Professional text editing for Chrome and Chrome OS",
|
||||
"version": "1.4.7",
|
||||
"version": "1.4.8",
|
||||
"manifest_version": 2,
|
||||
"icons": {
|
||||
"128": "icon-128.png"
|
||||
|
|
Loading…
Reference in a new issue