Merge pull request #2299 from quthla/restore-selection

Restore selection
This commit is contained in:
Alper Öztürk 2024-11-06 09:14:03 +01:00 committed by GitHub
commit 121be3dee6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -68,6 +68,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
}; };
private TextWatcher textWatcher; private TextWatcher textWatcher;
private boolean keyboardShown = false; private boolean keyboardShown = false;
private int lastSelection = -1;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -151,6 +152,19 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
} }
} }
}; };
if (savedInstanceState != null) {
lastSelection = savedInstanceState.getInt("lastSelection", -1);
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (binding != null && binding.editContent.hasFocus()) {
outState.putInt("lastSelection", binding.editContent.getSelectionStart());
}
} }
@Override @Override
@ -178,6 +192,10 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
if (sp.getBoolean(getString(R.string.pref_key_font), false)) { if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
binding.editContent.setTypeface(Typeface.MONOSPACE); binding.editContent.setTypeface(Typeface.MONOSPACE);
} }
if (lastSelection > 0 && binding.editContent.length() >= lastSelection) {
binding.editContent.setSelection(lastSelection);
}
} }
private void openSoftKeyboard() { private void openSoftKeyboard() {