From c99479eece1d5189d190fea7ed963db285b04eae Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 21 Oct 2008 21:58:59 +0000 Subject: [PATCH] Fix for bug #3052 Monotone-Parent: 3d09360548125f704154cb51ed4a79758826cad0 Monotone-Revision: 5f7a29adfa72a5c2257226be59358d6ef7642557 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2008-10-21T21:58:59 Monotone-Branch: ca.inverse.sogo --- UI/WebServerResources/UIxMailEditor.js | 37 +++++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/UI/WebServerResources/UIxMailEditor.js b/UI/WebServerResources/UIxMailEditor.js index 8a8be1b7e..39eae55c3 100644 --- a/UI/WebServerResources/UIxMailEditor.js +++ b/UI/WebServerResources/UIxMailEditor.js @@ -1,15 +1,14 @@ /* -*- Mode: java; tab-width: 2; c-tab-always-indent: t; indent-tabs-mode: t; c-basic-offset: 2 -*- */ var contactSelectorAction = 'mailer-contacts'; -var signatureLength = 0; - var attachmentCount = 0; var MailEditor = { addressBook: null, currentField: null, selectedIndex: -1, delay: 750, - delayedSearch: false + delayedSearch: false, + signatureLength: 0 }; function onContactAdd() { @@ -327,7 +326,12 @@ function onTextFirstFocus() { this.setCaretTo(0); } else { - this.setCaretTo(this.getValue().length - signatureLength - 2); + var caretPosition = this.getValue().length - MailEditor.signatureLength; + if (Prototype.Browser.IE) + caretPosition -= lineBreakCount(this.getValue().substring(0, caretPosition)); + if (hasSignature()) + caretPosition -= 2; + this.setCaretTo(caretPosition); } Event.stopObserving(this, "focus", onTextFirstFocus); @@ -545,9 +549,11 @@ function initMailEditor() { var textarea = $("text"); var textContent = textarea.getValue(); - var sigLimit = textContent.lastIndexOf("--"); - if (sigLimit > -1) - signatureLength = (textContent.length - sigLimit); + if (hasSignature()) { + var sigLimit = textContent.lastIndexOf("--"); + if (sigLimit > -1) + MailEditor.signatureLength = (textContent.length - sigLimit); + } if ( userDefaults["ReplyPlacement"] != "above" ) { textarea.scrollTop = textarea.scrollHeight; } @@ -645,6 +651,23 @@ function attachmentDeleteCallback(http) { } } +function lineBreakCount(str){ + /* counts \n */ + try { + return((str.match(/[^\n]*\n[^\n]*/gi).length)); + } catch(e) { + return 0; + } +} + +function hasSignature() { + try { + return(userDefaults.MailAccounts[0].identities[0].signature.length > 0); + } catch(e) { + return false; + } +} + function onMenuSetPriority(event) { event.cancelBubble = true;