Struct TextSelectionPosition
Represents a position within a text buffer, defined by a logical line index and a character index within that line. Used by TextSelectionRange to define the anchor and active endpoints of a text selection.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public readonly struct TextSelectionPosition : IEquatable<TextSelectionPosition>, IComparable<TextSelectionPosition>
Remarks
LogicalLineIndex corresponds to an entry in a LineScrollTextBuffer or ScrollTextBuffer; index 0 is the oldest line currently in the buffer.
The Invalid sentinel uses negative indices (-1, -1). Check IsValid before using any index values.
Constructors
TextSelectionPosition(int, int)
Creates a new text selection position.
Declaration
public TextSelectionPosition(int logicalLineIndex, int characterIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | logicalLineIndex | The logical line index (0 = oldest surviving line). A negative value produces a
position for which IsValid returns |
| int | characterIndex | The character index within the line (0 = first character). A negative value produces
a position for which IsValid returns |
Fields
CharacterIndex
The character index within the logical line string. Index 0 is the first character.
This index refers to characters in the raw logical line string and does not account
for TMP rich text tag characters (e.g., the characters in <color=#FF0000>
are counted, not the resulting color effect).
Declaration
public readonly int CharacterIndex
Field Value
| Type | Description |
|---|---|
| int |
Invalid
An invalid position sentinel value with both indices set to -1. Use IsValid to test whether a position is valid before reading LogicalLineIndex or CharacterIndex.
Declaration
public static readonly TextSelectionPosition Invalid
Field Value
| Type | Description |
|---|---|
| TextSelectionPosition |
Remarks
Invalid.IsValid returns false. This sentinel is returned by
operations that cannot produce a meaningful position, such as a failed hit-test.
LogicalLineIndex
The index of the logical line in the buffer. Index 0 is the oldest surviving line. For ring buffers that have wrapped around, index 0 is the oldest line still in the buffer, not necessarily the first line ever added.
Declaration
public readonly int LogicalLineIndex
Field Value
| Type | Description |
|---|---|
| int |
Properties
IsValid
Gets whether this position represents a valid location.
Requires both LogicalLineIndex and CharacterIndex to be
non-negative. Invalid.IsValid always returns false.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
CompareTo(TextSelectionPosition)
Compares this position to another in document order. Comparison is first by LogicalLineIndex (earlier line = smaller), then by CharacterIndex within the same line (earlier character = smaller).
Declaration
public int CompareTo(TextSelectionPosition other)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | other | The other position to compare against. |
Returns
| Type | Description |
|---|---|
| int | A negative integer if this position comes before |
Equals(TextSelectionPosition)
Determines whether this position equals another using exact integer equality. No floating-point approximation is involved.
Declaration
public bool Equals(TextSelectionPosition other)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | other | The other position. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Operators
operator ==(TextSelectionPosition, TextSelectionPosition)
Returns true if both positions have identical line and character indices.
Declaration
public static bool operator ==(TextSelectionPosition left, TextSelectionPosition right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | left | The left operand. |
| TextSelectionPosition | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator >(TextSelectionPosition, TextSelectionPosition)
Returns true if left comes after right in document order.
Declaration
public static bool operator >(TextSelectionPosition left, TextSelectionPosition right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | left | The left operand. |
| TextSelectionPosition | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator >=(TextSelectionPosition, TextSelectionPosition)
Returns true if left comes after or is at the same position
as right in document order.
Declaration
public static bool operator >=(TextSelectionPosition left, TextSelectionPosition right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | left | The left operand. |
| TextSelectionPosition | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(TextSelectionPosition, TextSelectionPosition)
Returns true if the positions differ in line index or character index.
Declaration
public static bool operator !=(TextSelectionPosition left, TextSelectionPosition right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | left | The left operand. |
| TextSelectionPosition | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator <(TextSelectionPosition, TextSelectionPosition)
Returns true if left comes before right in document order.
Declaration
public static bool operator <(TextSelectionPosition left, TextSelectionPosition right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | left | The left operand. |
| TextSelectionPosition | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator <=(TextSelectionPosition, TextSelectionPosition)
Returns true if left comes before or is at the same position
as right in document order.
Declaration
public static bool operator <=(TextSelectionPosition left, TextSelectionPosition right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | left | The left operand. |
| TextSelectionPosition | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|