summaryrefslogtreecommitdiff
path: root/lib/scripts/textselection.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/textselection.js')
-rw-r--r--lib/scripts/textselection.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/scripts/textselection.js b/lib/scripts/textselection.js
index 76cc6bcbb..742338785 100644
--- a/lib/scripts/textselection.js
+++ b/lib/scripts/textselection.js
@@ -24,7 +24,7 @@ function selection_class(){
this.getText = function(){
if(!this.obj) return '';
return this.obj.value.substring(this.start,this.end);
- }
+ };
}
/**
@@ -41,7 +41,6 @@ function getSelection(textArea) {
sel.obj = textArea;
sel.start = textArea.value.length;
sel.end = textArea.value.length;
-
textArea.focus();
if(document.getSelection) { // Mozilla et al.
sel.start = textArea.selectionStart;
@@ -57,9 +56,13 @@ function getSelection(textArea) {
// The current selection
sel.rangeCopy = document.selection.createRange().duplicate();
-
- var before_range = document.body.createTextRange();
- before_range.moveToElementText(textArea); // Selects all the text
+ if (textArea.tagName === 'INPUT') {
+ var before_range = textArea.createTextRange();
+ before_range.expand('textedit'); // Selects all the text
+ } else {
+ var before_range = document.body.createTextRange();
+ before_range.moveToElementText(textArea); // Selects all the text
+ }
before_range.setEndPoint("EndToStart", sel.rangeCopy); // Moves the end where we need it
var before_finished = false, selection_finished = false;
@@ -158,7 +161,12 @@ function pasteText(selection,text,opts){
selection.obj.value.substring(selection.end, selection.obj.value.length);
// set new selection
- selection.end = selection.start + text.length;
+ if (is_opera) {
+ // Opera replaces \n by \r\n when inserting text.
+ selection.end = selection.start + text.replace(/\r?\n/g, '\r\n').length;
+ } else {
+ selection.end = selection.start + text.length;
+ }
// modify the new selection if wanted
if(opts.startofs) selection.start += opts.startofs;