From e90a249520c875eb28fb9f196b5b35ca6c6ac63b Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 19 Oct 2018 12:33:35 +0200 Subject: [PATCH] avoid crashing at Undo issues, report the error and do not continue --- .../notes/fragments/NoteFragment.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 8ecc3d82..ac9cb8ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -16,10 +16,7 @@ import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo import androidx.annotation.RequiresApi -import com.simplemobiletools.commons.extensions.beGone -import com.simplemobiletools.commons.extensions.beVisible -import com.simplemobiletools.commons.extensions.onGlobalLayout -import com.simplemobiletools.commons.extensions.removeBit +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.notes.R import com.simplemobiletools.notes.activities.MainActivity import com.simplemobiletools.notes.extensions.config @@ -214,7 +211,13 @@ class NoteFragment : androidx.fragment.app.Fragment() { val end = start + if (edit.after != null) edit.after.length else 0 isUndoOrRedo = true - text.replace(start, end, edit.before) + try { + text.replace(start, end, edit.before) + } catch (e: Exception) { + activity?.showErrorToast(e) + return + } + isUndoOrRedo = false for (span in text.getSpans(0, text.length, UnderlineSpan::class.java)) {