Fix editing

This commit is contained in:
Grishka 2022-10-01 01:12:31 +03:00
parent 18633291e6
commit 3aa252f681
1 changed files with 9 additions and 0 deletions

View File

@ -180,6 +180,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
private Status editingStatus; private Status editingStatus;
private boolean pollChanged; private boolean pollChanged;
private boolean creatingView; private boolean creatingView;
private boolean ignoreSelectionChanges=false;
@Override @Override
public void onCreate(Bundle savedInstanceState){ public void onCreate(Bundle savedInstanceState){
@ -480,7 +481,9 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
initialText=mentions.isEmpty() ? "" : TextUtils.join(" ", mentions)+" "; initialText=mentions.isEmpty() ? "" : TextUtils.join(" ", mentions)+" ";
if(savedInstanceState==null){ if(savedInstanceState==null){
mainEditText.setText(initialText); mainEditText.setText(initialText);
ignoreSelectionChanges=true;
mainEditText.setSelection(mainEditText.length()); mainEditText.setSelection(mainEditText.length());
ignoreSelectionChanges=false;
if(!TextUtils.isEmpty(replyTo.spoilerText) && AccountSessionManager.getInstance().isSelf(accountID, replyTo.account)){ if(!TextUtils.isEmpty(replyTo.spoilerText) && AccountSessionManager.getInstance().isSelf(accountID, replyTo.account)){
hasSpoiler=true; hasSpoiler=true;
spoilerEdit.setVisibility(View.VISIBLE); spoilerEdit.setVisibility(View.VISIBLE);
@ -495,7 +498,9 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
if(editingStatus!=null){ if(editingStatus!=null){
initialText=getArguments().getString("sourceText", ""); initialText=getArguments().getString("sourceText", "");
mainEditText.setText(initialText); mainEditText.setText(initialText);
ignoreSelectionChanges=true;
mainEditText.setSelection(mainEditText.length()); mainEditText.setSelection(mainEditText.length());
ignoreSelectionChanges=false;
if(!editingStatus.mediaAttachments.isEmpty()){ if(!editingStatus.mediaAttachments.isEmpty()){
attachmentsView.setVisibility(View.VISIBLE); attachmentsView.setVisibility(View.VISIBLE);
for(Attachment att:editingStatus.mediaAttachments){ for(Attachment att:editingStatus.mediaAttachments){
@ -512,7 +517,9 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
String prefilledText=getArguments().getString("prefilledText"); String prefilledText=getArguments().getString("prefilledText");
if(!TextUtils.isEmpty(prefilledText)){ if(!TextUtils.isEmpty(prefilledText)){
mainEditText.setText(prefilledText); mainEditText.setText(prefilledText);
ignoreSelectionChanges=true;
mainEditText.setSelection(mainEditText.length()); mainEditText.setSelection(mainEditText.length());
ignoreSelectionChanges=false;
initialText=prefilledText; initialText=prefilledText;
} }
ArrayList<Uri> mediaUris=getArguments().getParcelableArrayList("mediaAttachments"); ArrayList<Uri> mediaUris=getArguments().getParcelableArrayList("mediaAttachments");
@ -1154,6 +1161,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
@Override @Override
public void onSelectionChanged(int start, int end){ public void onSelectionChanged(int start, int end){
if(ignoreSelectionChanges)
return;
if(start==end && mainEditText.length()>0){ if(start==end && mainEditText.length()>0){
ComposeAutocompleteSpan[] spans=mainEditText.getText().getSpans(start, end, ComposeAutocompleteSpan.class); ComposeAutocompleteSpan[] spans=mainEditText.getText().getSpans(start, end, ComposeAutocompleteSpan.class);
if(spans.length>0){ if(spans.length>0){