From b4cbed71b3d613b6fc471767b2e24a9a37d689a1 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 23 Jun 2014 09:13:15 -0400
Subject: [PATCH] Mail compose: Selecting contact inserts recipient to previously focused input - to/cc/bcc accordingly (#1489684)

---
 CHANGELOG         |    1 +
 program/js/app.js |   13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 43c2504..2239fcf 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Mail compose: Selecting contact inserts recipient to previously focused input - to/cc/bcc accordingly (#1489684)
 - Add option to set default message list mode - default_list_mode (#1487312)
 - Close "no subject" prompt with Enter key (#1489580)
 - Add config option to specify IMAP connection socket parameters - imap_conn_options (#1489948)
diff --git a/program/js/app.js b/program/js/app.js
index b4a2250..61698b8 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -346,10 +346,10 @@
           this.contact_list
             .addEventListener('initrow', function(o) { ref.triggerEvent('insertrow', { cid:o.uid, row:o }); })
             .addEventListener('select', function(o) { ref.compose_recipient_select(o); })
-            .addEventListener('dblclick', function(o) { ref.compose_add_recipient('to'); })
+            .addEventListener('dblclick', function(o) { ref.compose_add_recipient(); })
             .addEventListener('keypress', function(o) {
               if (o.key_pressed == o.ENTER_KEY) {
-                if (!ref.compose_add_recipient('to')) {
+                if (!ref.compose_add_recipient()) {
                   // execute link action on <enter> if not a recipient entry
                   if (o.last_selected && String(o.last_selected).charAt(0) == 'G') {
                     $(o.rows[o.last_selected].obj).find('a').first().click();
@@ -358,6 +358,9 @@
               }
             })
             .init();
+
+          // remember last focused address field
+          $('#_to,#_cc,#_bcc').focus(function() { ref.env.focused_field = this; });
         }
 
         if (this.gui_objects.addressbookslist) {
@@ -3485,6 +3488,12 @@
 
   this.compose_add_recipient = function(field)
   {
+    // find last focused field name
+    if (!field) {
+      field = $(this.env.focused_field).filter(':visible');
+      field = field.length ? field.attr('id').replace('_', '') : 'to';
+    }
+
     var recipients = [], input = $('#_'+field), delim = this.env.recipients_delimiter;
 
     if (this.contact_list && this.contact_list.selection.length) {

--
Gitblit v1.9.1