From e5d952bff4e5494145914eb60b48eee081f0bb33 Mon Sep 17 00:00:00 2001 From: Andrew Chen Date: Tue, 10 May 2011 15:23:25 -0700 Subject: [PATCH] Save and restore the cursor position when saving or loading a draft. This is the first step in making "resume composition on context switch" a reality. --- src/com/fsck/k9/activity/MessageCompose.java | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 0b6b39374..4b985e719 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1139,7 +1139,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc NAME("n"), EMAIL("e"), // TODO - store a reference to the message being replied so we can mark it at the time of send. - ORIGINAL_MESSAGE("m"); + ORIGINAL_MESSAGE("m"), + CURSOR_POSITION("p"); // Where in the message your cursor was when you saved. private final String value; @@ -1202,6 +1203,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc uri.appendQueryParameter(IdentityField.ORIGINAL_MESSAGE.value(), mMessageReference.toIdentityString()); } + uri.appendQueryParameter(IdentityField.CURSOR_POSITION.value(), Integer.toString(mMessageContentView.getSelectionStart())); + String k9identity = IDENTITY_VERSION_1 + uri.build().getEncodedQuery(); if (K9.DEBUG) { @@ -2047,6 +2050,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } } + int cursorPosition = 0; + if(k9identity.containsKey(IdentityField.CURSOR_POSITION)) { + try { + cursorPosition = Integer.valueOf(k9identity.get(IdentityField.CURSOR_POSITION)).intValue(); + } catch(Exception e) { + Log.e(K9.LOG_TAG, "Could not parse cursor position for MessageCompose; continuing.", e); + } + } + mIdentity = newIdentity; updateSignature(); @@ -2151,6 +2163,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc Log.e(K9.LOG_TAG, "Unhandled message format."); } } + + // Set the cursor position if we have it. + try { + mMessageContentView.setSelection(cursorPosition); + } catch(Exception e) { + Log.e(K9.LOG_TAG, "Could not set cursor position in MessageCompose; ignoring.", e); + } } } catch (MessagingException me) { /**