multiselect paste
This commit is contained in:
parent
1a0cabba1e
commit
defae049f4
4 changed files with 41 additions and 10 deletions
|
|
@ -424,6 +424,11 @@ var Editor = function(renderer, session, listenElement) {
|
|||
this.onCut = function() {
|
||||
this.commands.exec("cut", this);
|
||||
};
|
||||
|
||||
this.onPaste = function(text) {
|
||||
this._emit("paste", text);
|
||||
this.insert(text);
|
||||
};
|
||||
|
||||
this.insert = function(text) {
|
||||
var session = this.session;
|
||||
|
|
@ -517,11 +522,8 @@ var Editor = function(renderer, session, listenElement) {
|
|||
mode.autoOutdent(lineState, session, cursor.row);
|
||||
};
|
||||
|
||||
this.onTextInput = function(text, pasted) {
|
||||
if (pasted)
|
||||
this._emit("paste", text);
|
||||
|
||||
this.keyBinding.onTextInput(text, pasted);
|
||||
this.onTextInput = function(text) {
|
||||
this.keyBinding.onTextInput(text);
|
||||
};
|
||||
|
||||
this.onCommandKey = function(e, hashId, keyCode) {
|
||||
|
|
|
|||
|
|
@ -114,9 +114,9 @@ var KeyBinding = function(editor) {
|
|||
this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
|
||||
};
|
||||
|
||||
this.onTextInput = function(text, pasted) {
|
||||
this.onTextInput = function(text) {
|
||||
var success = false;
|
||||
if (!pasted && text.length == 1)
|
||||
if (text.length == 1)
|
||||
success = this.$callKeyboardHandlers(0, text);
|
||||
if (!success)
|
||||
this.$editor.commands.exec("insertstring", this.$editor, text);
|
||||
|
|
|
|||
|
|
@ -74,11 +74,18 @@ var TextInput = function(parentNode, host, listenElement) {
|
|||
if (value) {
|
||||
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
|
||||
value = value.slice(0, -1);
|
||||
if (value)
|
||||
host.onTextInput(value, pasted);
|
||||
if (value) {
|
||||
if (pasted)
|
||||
host.onPaste(value);
|
||||
else
|
||||
host.onTextInput(value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
host.onTextInput(value, pasted);
|
||||
if (pasted)
|
||||
host.onPaste(value);
|
||||
else
|
||||
host.onTextInput(value);
|
||||
}
|
||||
|
||||
// If editor is no longer focused we quit immediately, since
|
||||
|
|
|
|||
|
|
@ -461,6 +461,28 @@ var Editor = require("./editor").Editor;
|
|||
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
|
||||
* - needle: text to find
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue