From defae049f47c203ff94985f41c4f4a7ea942bf8f Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 18 Apr 2012 19:09:23 +0400 Subject: [PATCH] multiselect paste --- lib/ace/editor.js | 12 +++++++----- lib/ace/keyboard/keybinding.js | 4 ++-- lib/ace/keyboard/textinput.js | 13 ++++++++++--- lib/ace/multi_select.js | 22 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index b159640c..43f33e56 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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) { diff --git a/lib/ace/keyboard/keybinding.js b/lib/ace/keyboard/keybinding.js index 310a9b74..d3c9b5b3 100644 --- a/lib/ace/keyboard/keybinding.js +++ b/lib/ace/keyboard/keybinding.js @@ -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); diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index cc08a3e7..dbae5638 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -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 diff --git a/lib/ace/multi_select.js b/lib/ace/multi_select.js index 0b8850bc..2de80925 100644 --- a/lib/ace/multi_select.js +++ b/lib/ace/multi_select.js @@ -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