Merge pull request #507 from defunkt/upper-and-lower
Add editor.toUpperCase() and editor.toLowerCase()
This commit is contained in:
commit
1fb9e0aea4
3 changed files with 78 additions and 0 deletions
|
|
@ -301,6 +301,14 @@ exports.commands = [{
|
|||
name: "transposeletters",
|
||||
bindKey: bindKey("Ctrl-T", "Ctrl-T"),
|
||||
exec: function(editor) { editor.transposeLetters(); }
|
||||
}, {
|
||||
name: "touppercase",
|
||||
bindKey: bindKey("Ctrl-U", "Ctrl-U"),
|
||||
exec: function(editor) { editor.toUpperCase(); }
|
||||
}, {
|
||||
name: "tolowercase",
|
||||
bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
|
||||
exec: function(editor) { editor.toLowerCase(); }
|
||||
}, {
|
||||
name: "fold",
|
||||
bindKey: bindKey("Alt-L", "Alt-L"),
|
||||
|
|
|
|||
|
|
@ -773,6 +773,36 @@ var Editor = function(renderer, session) {
|
|||
this.session.replace(range, swap);
|
||||
};
|
||||
|
||||
this.toLowerCase = function() {
|
||||
if (this.$readOnly)
|
||||
return;
|
||||
|
||||
var originalRange = this.getSelectionRange();
|
||||
if (this.selection.isEmpty()) {
|
||||
this.selection.selectWord();
|
||||
}
|
||||
|
||||
var range = this.getSelectionRange();
|
||||
var text = this.session.getTextRange(range);
|
||||
this.session.replace(range, text.toLowerCase());
|
||||
this.selection.setSelectionRange(originalRange);
|
||||
};
|
||||
|
||||
this.toUpperCase = function() {
|
||||
if (this.$readOnly)
|
||||
return;
|
||||
|
||||
var originalRange = this.getSelectionRange();
|
||||
if (this.selection.isEmpty()) {
|
||||
this.selection.selectWord();
|
||||
}
|
||||
|
||||
var range = this.getSelectionRange();
|
||||
var text = this.session.getTextRange(range);
|
||||
this.session.replace(range, text.toUpperCase());
|
||||
this.selection.setSelectionRange(originalRange);
|
||||
};
|
||||
|
||||
this.indent = function() {
|
||||
if (this.$readOnly)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -511,6 +511,46 @@ module.exports = {
|
|||
editor.removeToLineEnd();
|
||||
assert.position(editor.getCursorPosition(), 1, 4);
|
||||
assert.equal(session.getValue(), ["123", "456789"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform selection to uppercase": function() {
|
||||
var session = new EditSession(["ajax", "dot", "org"]);
|
||||
|
||||
var editor = new Editor(new MockRenderer(), session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform word to uppercase": function() {
|
||||
var session = new EditSession(["ajax", "dot", "org"]);
|
||||
|
||||
var editor = new Editor(new MockRenderer(), session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test: transform selection to lowercase": function() {
|
||||
var session = new EditSession(["AJAX", "DOT", "ORG"]);
|
||||
|
||||
var editor = new Editor(new MockRenderer(), session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform word to lowercase": function() {
|
||||
var session = new EditSession(["AJAX", "DOT", "ORG"]);
|
||||
|
||||
var editor = new Editor(new MockRenderer(), session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue