# TextRange

Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/TextRange.kt+class:androidx.compose.ui.text.TextRange) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  value class TextRange
  ```

*** ** * ** ***

An immutable text range class, represents a text range from `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` (inclusive) to `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` (exclusive). `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` can be smaller than `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` and in those cases `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#min()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#max()` can be used in order to fetch the values.

## Summary

| ### Public companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#Zero()` | Cmn |

| ### Public functions |
|---|---|---|
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#contains(kotlin.Int)(offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns true if the given offset is a part of this range. | Cmn |
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#contains(androidx.compose.ui.text.TextRange)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange)` Returns true if this range covers including equals with the given range. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#intersects(androidx.compose.ui.text.TextRange)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange)` Returns true if the given range has intersection with this range | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#collapsed()` Returns true if the range is collapsed | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#length()` Returns the length of the range. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#max()` The maximum offset of the range. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#min()` The minimum offset of the range. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#reversed()` Returns true if the start offset is larger than the end offset. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange.https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)(minimumValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, maximumValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Ensures that `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` values lies in the specified range `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)`. | Cmn |

## Public companion properties

### Zero

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val Zero: TextRange
```

## Public functions

### contains

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
operator fun contains(offset: Int): Boolean
```

Returns true if the given offset is a part of this range.

### contains

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
operator fun contains(other: TextRange): Boolean
```

Returns true if this range covers including equals with the given range.

### intersects

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun intersects(other: TextRange): Boolean
```

Returns true if the given range has intersection with this range

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### collapsed

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val collapsed: Boolean
```

Returns true if the range is collapsed

### end

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val end: Int
```

### length

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val length: Int
```

Returns the length of the range.

### max

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val max: Int
```

The maximum offset of the range.

### min

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val min: Int
```

The minimum offset of the range.

### reversed

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val reversed: Boolean
```

Returns true if the start offset is larger than the end offset.

### start

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val start: Int
```

## Extension functions

### TextRange.coerceIn

Cmn Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/TextRange.kt+function:coerceIn)

```
fun TextRange.coerceIn(minimumValue: Int, maximumValue: Int): TextRange
```

Ensures that `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` values lies in the specified range `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)`. For each `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` values:

- if value is smaller than `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)`, value is replaced by `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)`

- if value is greater than `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)`, value is replaced by `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/package-summary#(androidx.compose.ui.text.TextRange).coerceIn(kotlin.Int,kotlin.Int)`

| Parameters |
|---|---|
| `minimumValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the minimum value that `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` can be. |
| `maximumValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the exclusive maximum value that `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#start()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextRange#end()` can be. |