mirror of https://github.com/M66B/FairEmail.git
Auto position on double new line in drafts
This commit is contained in:
parent
3fbacf9ea8
commit
deb8f14767
|
@ -1831,6 +1831,10 @@ public class FragmentCompose extends FragmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
etBody.getText().insert(start, spanned);
|
etBody.getText().insert(start, spanned);
|
||||||
|
|
||||||
|
int pos = getAutoPos(start, spanned.length());
|
||||||
|
if (pos >= 0)
|
||||||
|
etBody.setSelection(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -5546,8 +5550,12 @@ public class FragmentCompose extends FragmentBase {
|
||||||
@Override
|
@Override
|
||||||
protected void onExecuted(Bundle args, Spanned[] text) {
|
protected void onExecuted(Bundle args, Spanned[] text) {
|
||||||
etBody.setText(text[0]);
|
etBody.setText(text[0]);
|
||||||
if (state != State.LOADED)
|
if (state != State.LOADED) {
|
||||||
etBody.setSelection(0);
|
int pos = getAutoPos(0, etBody.length());
|
||||||
|
if (pos < 0)
|
||||||
|
pos = 0;
|
||||||
|
etBody.setSelection(pos);
|
||||||
|
}
|
||||||
grpBody.setVisibility(View.VISIBLE);
|
grpBody.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
cbSignature.setChecked(draft.signature);
|
cbSignature.setChecked(draft.signature);
|
||||||
|
@ -5628,6 +5636,27 @@ public class FragmentCompose extends FragmentBase {
|
||||||
etBody.setPadding(0, 0, 0, pad ? Helper.dp2pixels(getContext(), 36) : 0);
|
etBody.setPadding(0, 0, 0, pad ? Helper.dp2pixels(getContext(), 36) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getAutoPos(int start, int end) {
|
||||||
|
if (start > end || end == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
CharSequence text = etBody.getText();
|
||||||
|
if (text == null)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int nl = 0;
|
||||||
|
int pos = 0;
|
||||||
|
String[] lines = text.subSequence(start, end).toString().split("\n");
|
||||||
|
for (int i = 0; i < Math.min(5, lines.length); i++) {
|
||||||
|
if (TextUtils.isEmpty(lines[i]))
|
||||||
|
nl++;
|
||||||
|
if (nl == 2)
|
||||||
|
return start + pos;
|
||||||
|
pos += lines[i].length() + 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() {
|
private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
|
Loading…
Reference in New Issue