From b7d56765de3827db533cc82a3a4ebb7df7b0f156 Mon Sep 17 00:00:00 2001 From: quthla Date: Tue, 23 Jul 2024 00:56:55 +0200 Subject: [PATCH 1/2] Restore selection --- .../owncloud/notes/edit/NoteEditFragment.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java index c4adc066..d0617ed7 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java @@ -68,6 +68,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment { }; private TextWatcher textWatcher; private boolean keyboardShown = false; + private int lastSelection = -1; @Override 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.editContent != null && binding.editContent.hasFocus()) { + outState.putInt("lastSelection", binding.editContent.getSelectionStart()); + } } @Override @@ -178,6 +192,10 @@ public class NoteEditFragment extends SearchableBaseNoteFragment { 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() { From 77c785a5ec048244fec10fc71f4e468d81cda1aa Mon Sep 17 00:00:00 2001 From: Tobias Kaminsky Date: Wed, 6 Nov 2024 08:10:15 +0100 Subject: [PATCH 2/2] Update app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alper Öztürk <67455295+alperozturk96@users.noreply.github.com> Signed-off-by: Tobias Kaminsky --- .../it/niedermann/owncloud/notes/edit/NoteEditFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java index d0617ed7..168fcb2d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java @@ -162,7 +162,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment { public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - if (binding.editContent != null && binding.editContent.hasFocus()) { + if (binding != null && binding.editContent.hasFocus()) { outState.putInt("lastSelection", binding.editContent.getSelectionStart()); } }