From 5979067e17b8c74e4b3ae51e0073aa0b5eae0f49 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Wed, 3 Jun 2009 19:00:42 +0200
Subject: [PATCH] reset scroll position when setting selection FS#1707

Ignore-this: cb035f32eccc0fcb2c9163b8620abb91

darcs-hash:20090603170042-7ad00-07ee60074714d6d23d34e59269776ccb504d1f0a.gz
---
 lib/scripts/textselection.js | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/scripts/textselection.js b/lib/scripts/textselection.js
index 537e8d348..f005fa3da 100644
--- a/lib/scripts/textselection.js
+++ b/lib/scripts/textselection.js
@@ -14,6 +14,7 @@ function selection_class(){
     this.end       = 0;
     this.obj       = null;
     this.rangeCopy = null;
+    this.scroll    = 0;
 
     this.getLength = function(){
         return this.end - this.start;
@@ -41,8 +42,9 @@ function getSelection(textArea) {
 
     textArea.focus();
     if(document.getSelection) {          // Mozilla et al.
-        sel.start = textArea.selectionStart;
-        sel.end = textArea.selectionEnd;
+        sel.start  = textArea.selectionStart;
+        sel.end    = textArea.selectionEnd;
+        sel.scroll = textArea.scrollTop;
     } else if(document.selection) {      // MSIE
         // The current selection
         var range = document.selection.createRange();
@@ -72,6 +74,7 @@ function setSelection(selection){
     if(document.getSelection){ // FF
         // what a pleasure in FF ;)
         selection.obj.setSelectionRange(selection.start,selection.end);
+        if(selection.scroll) selection.obj.scrollTop = selection.scroll;
     } else if(document.selection) { // IE
         // count number of newlines in str to work around stupid IE selection bug
         var countNL = function(str) {
-- 
GitLab