Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Nov 24, 2024
2 parents d50a3a6 + 35337de commit 2ea3a82
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.5.2"
kotlin = "2.0.21"
compose = "1.7.0"
compose = "1.7.1"
dokka = "1.9.10"

ksoup = "0.4.0"
Expand All @@ -14,7 +14,7 @@ nexus-publish = "2.0.0"
androidx-appcompat = "1.7.0"
activity-compose = "1.9.3"
voyager = "1.1.0-beta03"
richeditor = "1.0.0-rc05"
richeditor = "1.0.0-rc10"
coroutines = "1.9.0"
ktor = "3.0.1"
android-minSdk = "21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2770,22 +2770,31 @@ public class RichTextState internal constructor(
var pressY = pressPosition.y
val textLayoutResult = this.textLayoutResult ?: return
var index = 0
var lastIndex = 0

// Get the length of the text
val textLength = textLayoutResult.layoutInput.text.length

// Ensure pressY is within valid bounds
pressY = pressY.coerceIn(0f, textLayoutResult.size.height.toFloat())

for (i in 0 until textLayoutResult.lineCount) {
val start = textLayoutResult.getLineStart(i)
val top = textLayoutResult.getLineTop(i)

if (i == 0) {
if (start > 0f)
if (start > 0f) {
pressX += start
}

if (top > 0f)
if (top > 0f) {
pressY += top
}
}

if (i == 0 && top > pressY)
// Make sure pressY is within the current line's top position
if (i == 0 && top > pressY) {
break
}

if (top > pressY) {
index = lastIndex
Expand Down Expand Up @@ -2826,32 +2835,39 @@ public class RichTextState internal constructor(
(nextParagraph.getFirstNonEmptyChild() ?: nextParagraph.type.startRichSpan)
.textRange.min.minus(nextParagraph.type.startText.length)

// Handle selection adjustments
if (
selection.collapsed &&
selection.min == nextParagraphStart
)
) {
updateTextFieldValue(
textFieldValue.copy(
selection = TextRange(selection.min - 1, selection.min - 1)
selection = TextRange((selection.min - 1).coerceAtLeast(0), (selection.min - 1).coerceAtLeast(0))
)
)
else if (
} else if (
selection.collapsed &&
index == richParagraphList.lastIndex &&
selectedParagraph.isEmpty() &&
selection.min == selectedParagraph.getFirstNonEmptyChild()?.textRange?.min?.minus(1)
)
) {
updateTextFieldValue(
textFieldValue.copy(
selection = TextRange(selection.min + 1, selection.min + 1)
selection = TextRange((selection.min + 1).coerceAtMost(textLength - 1), (selection.min + 1).coerceAtMost(textLength - 1))
)
)
else if (newSelection != null)
} else if (newSelection != null) {
// Ensure newSelection is within valid bounds
val adjustedSelection = TextRange(
newSelection.start.coerceIn(0, textLength),
newSelection.end.coerceIn(0, textLength)
)
updateTextFieldValue(
textFieldValue.copy(
selection = newSelection
selection = adjustedSelection
)
)
}
}

private var registerLastPressPositionJob: Job? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.material.LocalTextStyle
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.*
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
Expand Down
2 changes: 2 additions & 0 deletions sample/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="false"
android:supportsRtl="true"
Expand Down

0 comments on commit 2ea3a82

Please sign in to comment.