diff --git a/app/build.gradle b/app/build.gradle index 82dbfff4..f75da490 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.bijoysingh.quicknote" minSdkVersion 17 targetSdkVersion 27 - versionCode 56 - versionName "4.4.0" + versionCode 57 + versionName "4.4.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { diff --git a/app/src/main/java/com/bijoysingh/quicknote/recyclerview/FormatTextViewHolder.kt b/app/src/main/java/com/bijoysingh/quicknote/recyclerview/FormatTextViewHolder.kt index af781d81..d5552d51 100644 --- a/app/src/main/java/com/bijoysingh/quicknote/recyclerview/FormatTextViewHolder.kt +++ b/app/src/main/java/com/bijoysingh/quicknote/recyclerview/FormatTextViewHolder.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.support.v4.content.ContextCompat import android.text.Editable import android.text.InputType -import android.text.Selection import android.text.TextWatcher import android.util.TypedValue import android.view.View @@ -19,7 +18,7 @@ import com.bijoysingh.quicknote.activities.sheets.TextSizeBottomSheet import com.bijoysingh.quicknote.activities.sheets.TextSizeBottomSheet.Companion.KEY_TEXT_SIZE import com.bijoysingh.quicknote.activities.sheets.TextSizeBottomSheet.Companion.TEXT_SIZE_DEFAULT import com.bijoysingh.quicknote.formats.Format -import com.bijoysingh.quicknote.formats.FormatType.* +import com.bijoysingh.quicknote.formats.FormatType.CODE import com.bijoysingh.quicknote.formats.MarkdownType import com.bijoysingh.quicknote.utils.ThemeColorType import com.bijoysingh.quicknote.utils.ThemeManager @@ -147,8 +146,12 @@ open class FormatTextViewHolder(context: Context, view: View) : RecyclerViewHold edit.setText(stringBuilder.toString()) - val additionTokenLength = (if (markdownType.requiresNewLine) 1 else 0) + markdownType.startToken.length - edit.setSelection(startString.length + additionTokenLength) + try { + val additionTokenLength = (if (markdownType.requiresNewLine) 1 else 0) + markdownType.startToken.length + edit.setSelection(Math.min(startString.length + additionTokenLength, edit.text.length)) + } catch (_: Exception) { + // Ignore the exception + } } companion object {