From 7afecc746b6d00b530a732bf80eceaa1840dfb86 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 14 Aug 2021 19:10:19 +0200 Subject: [PATCH] Keep original initial draft --- .../eu/faircode/email/FragmentCompose.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 999991d418..383a3e2468 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3707,6 +3707,7 @@ public class FragmentCompose extends FragmentBase { args.putString("cc", etCc.getText().toString().trim()); args.putString("bcc", etBcc.getText().toString().trim()); args.putString("subject", etSubject.getText().toString().trim()); + args.putCharSequence("loaded", (Spanned) etBody.getTag()); args.putCharSequence("spanned", etBody.getText()); args.putBoolean("signature", cbSignature.isChecked()); args.putBoolean("empty", isEmpty()); @@ -5029,6 +5030,7 @@ public class FragmentCompose extends FragmentBase { String cc = args.getString("cc"); String bcc = args.getString("bcc"); String subject = args.getString("subject"); + Spanned loaded = (Spanned) args.getCharSequence("loaded"); Spanned spanned = (Spanned) args.getCharSequence("spanned"); boolean signature = args.getBoolean("signature"); boolean empty = args.getBoolean("empty"); @@ -5202,12 +5204,22 @@ public class FragmentCompose extends FragmentBase { Elements ref = doc.select("div[fairemail=reference]"); ref.remove(); - Document b; - if (body == null) - b = Document.createShell(""); - else - b = HtmlHelper.sanitizeCompose(context, body, true); - HtmlHelper.clearAnnotations(b); + if (extras != null && extras.containsKey("html")) + dirty = true; + + if (!dirty) + if (loaded == null) { + Document b = HtmlHelper.sanitizeCompose(context, body, true); + HtmlHelper.clearAnnotations(b); + if (!Objects.equals(b.body().html(), doc.body().html())) + dirty = true; + } else { + // Was not dirty before + String hloaded = HtmlHelper.toHtml(loaded, context); + String hspanned = HtmlHelper.toHtml(spanned, context); + if (!Objects.equals(hloaded, hspanned)) + dirty = true; + } if (draft.revision == null) { draft.revision = 1; @@ -5215,10 +5227,7 @@ public class FragmentCompose extends FragmentBase { } int revision = draft.revision; // Save for undo/redo - if (dirty || - TextUtils.isEmpty(body) || - !b.body().html().equals(doc.body().html()) || - (extras != null && extras.containsKey("html"))) { + if (dirty) { dirty = true; // Get saved body @@ -5637,6 +5646,7 @@ public class FragmentCompose extends FragmentBase { db.endTransaction(); } + args.putBoolean("dirty", dirty); if (dirty) ServiceSynchronize.eval(context, "compose/action"); @@ -5676,6 +5686,10 @@ public class FragmentCompose extends FragmentBase { if (bccPos >= 0 && bccPos <= etBcc.getText().length()) etBcc.setSelection(bccPos); + boolean dirty = args.getBoolean("dirty"); + if (dirty) + etBody.setTag(null); + Bundle extras = args.getBundle("extras"); boolean show = extras.getBoolean("show"); if (show) @@ -5954,6 +5968,8 @@ public class FragmentCompose extends FragmentBase { @Override protected void onExecuted(Bundle args, Spanned[] text) { etBody.setText(text[0]); + etBody.setTag(text[0]); + if (state != State.LOADED) { int pos = getAutoPos(0, etBody.length()); if (pos < 0)