Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore selection #2299

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void run() {
};
private TextWatcher textWatcher;
private boolean keyboardShown = false;
private int lastSelection = -1;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -151,6 +152,19 @@ public void afterTextChanged(final Editable s) {
}
}
};

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
Expand Down Expand Up @@ -178,6 +192,10 @@ protected void onNoteLoaded(Note note) {
if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
binding.editContent.setTypeface(Typeface.MONOSPACE);
}

if (lastSelection > 0 && binding.editContent.length() >= lastSelection) {
binding.editContent.setSelection(lastSelection);
}
}

private void openSoftKeyboard() {
Expand Down
Loading