[Svn] r2461 - trunk/roundcubemail/program/js

trac at roundcube.net trac at roundcube.net
Sat May 9 09:52:29 CEST 2009


Author: alec
Date: 2009-05-09 02:52:29 -0500 (Sat, 09 May 2009)
New Revision: 2461

Modified:
   trunk/roundcubemail/program/js/app.js
Log:
- Correct caret position in message form with signature (#1485833)


Modified: trunk/roundcubemail/program/js/app.js
===================================================================
--- trunk/roundcubemail/program/js/app.js	2009-05-08 21:36:37 UTC (rev 2460)
+++ trunk/roundcubemail/program/js/app.js	2009-05-09 07:52:29 UTC (rev 2461)
@@ -472,7 +472,7 @@
     else if (input_subject.val() == '')
       input_subject.focus();
     else if (input_message)
-      this.set_caret2start(input_message);
+      input_message.focus();
 
     // get summary of all field values
     this.compose_field_hash(true);
@@ -2188,7 +2188,7 @@
     var input_message = $("[name='_message']");
     var message = input_message.val();
     var is_html = ($("input[name='_is_html']").val() == '1');
-    var sig, p;
+    var sig, p, len;
 
     if (!this.env.identity)
       this.env.identity = id
@@ -2212,7 +2212,8 @@
         }
 
       message = message.replace(/[\r\n]+$/, '');
-      
+      len = message.length;
+
       // add the new signature string
       if (this.env.signatures && this.env.signatures[id])
         {
@@ -2224,6 +2225,7 @@
         if (sig.indexOf('-- ')!=0)
           sig = '-- \n'+sig;
         message += '\n\n'+sig;
+	if (len) len += 1;
         }
       }
     else
@@ -2270,6 +2272,10 @@
 
     input_message.val(message);
 
+    // move cursor before the signature
+    if (!is_html)
+      this.set_caret_pos(input_message.get(0), len);
+
     this.env.identity = id;
     return true;
     };
@@ -4011,20 +4017,20 @@
       return obj.value.length;
     };
 
-  this.set_caret2start = function(obj)
+  this.set_caret_pos = function(obj, pos)
     {
-    if (obj.createTextRange)
+    if (obj.setSelectionRange)
+      obj.setSelectionRange(pos, pos);
+    else if (obj.createTextRange)
       {
       var range = obj.createTextRange();
       range.collapse(true);
+      range.moveEnd('character', pos);
+      range.moveStart('character', pos);
       range.select();
       }
-    else if (obj.setSelectionRange)
-      obj.setSelectionRange(0,0);
+    }
 
-    obj.focus();
-    };
-
   // set all fields of a form disabled
   this.lock_form = function(form, lock)
     {

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list