multiselect paste

This commit is contained in:
nightwing 2012-04-18 19:09:23 +04:00
commit defae049f4
4 changed files with 41 additions and 10 deletions

View file

@ -424,6 +424,11 @@ var Editor = function(renderer, session, listenElement) {
this.onCut = function() { this.onCut = function() {
this.commands.exec("cut", this); this.commands.exec("cut", this);
}; };
this.onPaste = function(text) {
this._emit("paste", text);
this.insert(text);
};
this.insert = function(text) { this.insert = function(text) {
var session = this.session; var session = this.session;
@ -517,11 +522,8 @@ var Editor = function(renderer, session, listenElement) {
mode.autoOutdent(lineState, session, cursor.row); mode.autoOutdent(lineState, session, cursor.row);
}; };
this.onTextInput = function(text, pasted) { this.onTextInput = function(text) {
if (pasted) this.keyBinding.onTextInput(text);
this._emit("paste", text);
this.keyBinding.onTextInput(text, pasted);
}; };
this.onCommandKey = function(e, hashId, keyCode) { this.onCommandKey = function(e, hashId, keyCode) {

View file

@ -114,9 +114,9 @@ var KeyBinding = function(editor) {
this.$callKeyboardHandlers(hashId, keyString, keyCode, e); this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
}; };
this.onTextInput = function(text, pasted) { this.onTextInput = function(text) {
var success = false; var success = false;
if (!pasted && text.length == 1) if (text.length == 1)
success = this.$callKeyboardHandlers(0, text); success = this.$callKeyboardHandlers(0, text);
if (!success) if (!success)
this.$editor.commands.exec("insertstring", this.$editor, text); this.$editor.commands.exec("insertstring", this.$editor, text);

View file

@ -74,11 +74,18 @@ var TextInput = function(parentNode, host, listenElement) {
if (value) { if (value) {
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) { if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
value = value.slice(0, -1); value = value.slice(0, -1);
if (value) if (value) {
host.onTextInput(value, pasted); if (pasted)
host.onPaste(value);
else
host.onTextInput(value);
}
} }
else { else {
host.onTextInput(value, pasted); if (pasted)
host.onPaste(value);
else
host.onTextInput(value);
} }
// If editor is no longer focused we quit immediately, since // If editor is no longer focused we quit immediately, since

View file

@ -461,6 +461,28 @@ var Editor = require("./editor").Editor;
return text; return text;
}; };
this.onPaste = function(text) {
this._emit("paste", text);
if (!this.inMultiSelectMode)
return this.insert(text);
var lines = text.split(this.session.getDocument().getNewLineCharacter());
var ranges = this.selection.rangeList.ranges;
if (lines.length > ranges.length) {
this.commands.exec("insertstring", this, text);
return;
}
for (var i = ranges.length; i--; ) {
var range = ranges[i];
if (!range.isEmpty())
this.session.remove(range);
this.session.insert(range.start, lines[i]);
}
};
/** /**
* Editor.findAll(dir, options) -> Number * Editor.findAll(dir, options) -> Number
* - needle: text to find * - needle: text to find