1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

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.

This commit is contained in:
Andrew Chen 2011-05-10 15:23:25 -07:00
parent 3255b403fc
commit e5d952bff4

View File

@ -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) {
/**