Fix restoring draft messages from localStorage if editor mode differs (#1490016)

pull/223/head
Thomas Bruederli 10 years ago
parent 2e713d00f5
commit 7d3be1f3c8

@ -5,6 +5,7 @@ CHANGELOG Roundcube Webmail
- Support contacts import in GMail CSV format - Support contacts import in GMail CSV format
- Added namespace filter in Folder Manager - Added namespace filter in Folder Manager
- Added folder searching in Folder Manager - Added folder searching in Folder Manager
- Added 'sig_max_lines' config option to default config file (#1490071)
- Added config option/user preference to disable saving messages in localStorage (#1489979) - Added config option/user preference to disable saving messages in localStorage (#1489979)
- Added config option 'imap_log_session' to enable Roundcube <-> IMAP session ID logging - Added config option 'imap_log_session' to enable Roundcube <-> IMAP session ID logging
- Added config option 'log_session_id' to control the lengh of the session identifer in logs - Added config option 'log_session_id' to control the lengh of the session identifer in logs

@ -3617,11 +3617,15 @@ function rcube_webmail()
this.toggle_editor = function(props, obj, e) this.toggle_editor = function(props, obj, e)
{ {
// @todo: this should work also with many editors on page // @todo: this should work also with many editors on page
var result = this.editor.toggle(props.html); var result = this.editor.toggle(props.html, props.noconvert || false);
// satisfy the expectations of aftertoggle-editor event subscribers
props.mode = props.html ? 'html' : 'plain';
if (!result && e) { if (!result && e) {
// fix selector value if operation failed // fix selector value if operation failed
$(e.target).filter('select').val(props.html ? 'plain' : 'html'); props.mode = props.html ? 'plain' : 'html';
$(e.target).filter('select').val(props.mode);
} }
if (result) { if (result) {
@ -3924,7 +3928,7 @@ function rcube_webmail()
// initialize HTML editor // initialize HTML editor
if ((formdata._is_html == '1' && !html_mode) || (formdata._is_html != '1' && html_mode)) { if ((formdata._is_html == '1' && !html_mode) || (formdata._is_html != '1' && html_mode)) {
this.command('toggle-editor', {id: this.env.composebody, html: !html_mode}); this.command('toggle-editor', {id: this.env.composebody, html: !html_mode, noconvert: true});
} }
} }
}; };

@ -194,7 +194,7 @@ function rcube_text_editor(config, id)
}; };
// switch html/plain mode // switch html/plain mode
this.toggle = function(ishtml) this.toggle = function(ishtml, noconvert)
{ {
var curr, content, result, var curr, content, result,
// these non-printable chars are not removed on text2html and html2text // these non-printable chars are not removed on text2html and html2text
@ -214,8 +214,7 @@ function rcube_text_editor(config, id)
if (is_sig) if (is_sig)
content = content.replace(signature.text, sig_mark); content = content.replace(signature.text, sig_mark);
// convert to html var init_editor = function(data) {
result = rcmail.plain2html(content, function(data) {
// replace signature mark with html version of the signature // replace signature mark with html version of the signature
if (is_sig) if (is_sig)
data = data.replace(sig_mark, '<div id="_rc_sig">' + signature.html + '</div>'); data = data.replace(sig_mark, '<div id="_rc_sig">' + signature.html + '</div>');
@ -231,7 +230,16 @@ function rcube_text_editor(config, id)
ref.tabindex(true); ref.tabindex(true);
} }
}, 500); }, 500);
}); };
// convert to html
if (!noconvert) {
result = rcmail.plain2html(content, init_editor);
}
else {
init_editor(content);
result = true;
}
} }
else if (this.editor) { else if (this.editor) {
if (is_sig) { if (is_sig) {
@ -250,8 +258,7 @@ function rcube_text_editor(config, id)
// get html content // get html content
content = this.editor.getContent(); content = this.editor.getContent();
// convert html to text var init_plaintext = function(data) {
result = rcmail.html2plain(content, function(data) {
tinymce.execCommand('mceRemoveEditor', false, ref.id); tinymce.execCommand('mceRemoveEditor', false, ref.id);
ref.editor = null; ref.editor = null;
@ -260,7 +267,16 @@ function rcube_text_editor(config, id)
data = data.replace(sig_mark, "\n" + signature.text); data = data.replace(sig_mark, "\n" + signature.text);
input.val(data).focus(); input.val(data).focus();
}); };
// convert html to text
if (!noconvert) {
result = rcmail.html2plain(content, init_plaintext);
}
else {
init_plaintext(input.val());
result = true;
}
// bring back current signature // bring back current signature
if (!result && curr) if (!result && curr)

Loading…
Cancel
Save