Merge pull request #1046 from ajaxorg/feature/sorLines
Add sortLines functionality in all modes
This commit is contained in:
commit
b95ece2cc4
2 changed files with 45 additions and 15 deletions
|
|
@ -321,6 +321,11 @@ exports.commands = [{
|
||||||
bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
|
bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
|
||||||
exec: function(editor) { editor.duplicateSelection(); },
|
exec: function(editor) { editor.duplicateSelection(); },
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach"
|
||||||
|
}, {
|
||||||
|
name: "sortlines",
|
||||||
|
bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
|
||||||
|
exec: function(editor) { editor.sortLines(); },
|
||||||
|
multiSelectAction: "forEach"
|
||||||
}, {
|
}, {
|
||||||
name: "togglecomment",
|
name: "togglecomment",
|
||||||
bindKey: bindKey("Ctrl-/", "Command-/"),
|
bindKey: bindKey("Ctrl-/", "Command-/"),
|
||||||
|
|
|
||||||
|
|
@ -1276,6 +1276,31 @@ var Editor = function(renderer, session) {
|
||||||
this.session.outdentRows(selection.getRange());
|
this.session.outdentRows(selection.getRange());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: move out of core when we have good mechanism for managing extensions
|
||||||
|
this.sortLines = function() {
|
||||||
|
var rows = this.$getSelectedRows();
|
||||||
|
var session = this.session;
|
||||||
|
|
||||||
|
var lines = [];
|
||||||
|
for (i = rows.first; i <= rows.last; i++)
|
||||||
|
lines.push(session.getLine(i));
|
||||||
|
|
||||||
|
lines.sort(function(a, b) {
|
||||||
|
if (a.toLowerCase() < b.toLowerCase()) return -1;
|
||||||
|
if (a.toLowerCase() > b.toLowerCase()) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
var deleteRange = new Range(0, 0, 0, 0);
|
||||||
|
for (var i = rows.first; i <= rows.last; i++) {
|
||||||
|
var line = session.getLine(i);
|
||||||
|
deleteRange.start.row = i;
|
||||||
|
deleteRange.end.row = i;
|
||||||
|
deleteRange.end.column = line.length;
|
||||||
|
session.replace(deleteRange, lines[i-rows.first]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editor.toggleCommentLines()
|
* Editor.toggleCommentLines()
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue