From 28f6aae1adeef509aa7be8895088cc9f47018054 Mon Sep 17 00:00:00 2001
From: Adrian Lang <lang@cosmocode.de>
Date: Thu, 29 Apr 2010 13:08:15 +0200
Subject: [PATCH] Support getSelection in input fields in IE

---
 lib/scripts/textselection.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/scripts/textselection.js b/lib/scripts/textselection.js
index 5e4602f85..0378b544d 100644
--- a/lib/scripts/textselection.js
+++ b/lib/scripts/textselection.js
@@ -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;
-- 
GitLab