Google is committed to advancing racial equity for Black communities. See how.

TextRange

@Immutable data class TextRange
kotlin.Any
   ↳ androidx.compose.ui.text.TextRange

An immutable text range class, represents a text range from start (inclusive) to end (exclusive). end can be smaller than start and in those cases min and max can be used in order to fetch the values.

Summary

Public constructors
<init>(@IntRange(0) start: Int, @IntRange(0) end: Int)

An immutable text range class, represents a text range from start (inclusive) to end (exclusive).

Public methods
operator Boolean

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

operator Boolean
contains(offset: Int)

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

Boolean

Returns true if the given range has intersection with this range

Properties
Boolean

Returns true if the range is collapsed

Int

the exclusive end offset of the range.

Int

Returns the length of the range.

Int

The maximum offset of the range.

Int

The minimum offset of the range.

Boolean

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

Int

the inclusive start offset of the range.

Companion properties
TextRange

Public constructors

<init>

TextRange(
    @IntRange(0) start: Int,
    @IntRange(0) end: Int)

An immutable text range class, represents a text range from start (inclusive) to end (exclusive). end can be smaller than start and in those cases min and max can be used in order to fetch the values.

Parameters
start: Int the inclusive start offset of the range. Must be non-negative, otherwise an exception will be thrown.
end: Int the exclusive end offset of the range. Must be non-negative, otherwise an exception will be thrown.

Public methods

contains

operator fun contains(other: TextRange): Boolean

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

contains

operator fun contains(offset: Int): Boolean

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

intersects

fun intersects(other: TextRange): Boolean

Returns true if the given range has intersection with this range

Properties

collapsed

val collapsed: Boolean

Returns true if the range is collapsed

end

val end: Int

the exclusive end offset of the range. Must be non-negative, otherwise an exception will be thrown.

length

val length: Int

Returns the length of the range.

max

val max: Int

The maximum offset of the range.

min

val min: Int

The minimum offset of the range.

reversed

val reversed: Boolean

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

start

val start: Int

the inclusive start offset of the range. Must be non-negative, otherwise an exception will be thrown.

Companion properties

Zero

val Zero: TextRange