Remember cursor position, quote at cursor position

captchafix
Floens 11 years ago
parent 4f234d701d
commit 8be192aa61
  1. 11
      Clover/app/src/main/java/org/floens/chan/core/manager/ReplyManager.java
  2. 1
      Clover/app/src/main/java/org/floens/chan/core/model/Reply.java
  3. 6
      Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java

@ -105,15 +105,20 @@ public class ReplyManager {
* @param no the raw no to quote to.
*/
public void quote(int no) {
draft.comment += ">>" + no + "\n";
String textToInsert = ">>" + no + "\n";
draft.comment = new StringBuilder(draft.comment).insert(draft.cursorPosition, textToInsert).toString();
draft.cursorPosition += textToInsert.length();
}
public void quoteInline(int no, String text) {
draft.comment += ">>" + no + "\n";
String textToInsert = ">>" + no + "\n";
String[] lines = text.split("\n+");
for (String line : lines) {
draft.comment += ">" + line + "\n";
textToInsert += ">" + line + "\n";
}
draft.comment = new StringBuilder(draft.comment).insert(draft.cursorPosition, textToInsert).toString();
draft.cursorPosition += textToInsert.length();
}
/**

@ -37,4 +37,5 @@ public class Reply {
public boolean usePass = false;
public String passId = "";
public boolean spoilerImage = false;
public int cursorPosition;
}

@ -24,7 +24,6 @@ import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Editable;
import android.text.Selection;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
@ -174,8 +173,8 @@ public class ReplyFragment extends DialogFragment {
emailView.setText(draft.email);
subjectView.setText(draft.subject);
commentView.setText(draft.comment);
// To the end of the comment
Selection.setSelection(commentView.getText(), commentView.getText().length());
commentView.setSelection(draft.cursorPosition);
setFile(draft.fileName, draft.file);
spoilerImageView.setChecked(draft.spoilerImage);
@ -234,6 +233,7 @@ public class ReplyFragment extends DialogFragment {
draft.comment = commentView.getText().toString();
draft.fileName = fileNameView.getText().toString();
draft.spoilerImage = spoilerImageView.isChecked();
draft.cursorPosition = commentView.getSelectionStart();
replyManager.setReplyDraft(draft);
} else {

Loading…
Cancel
Save