Struct TextSelectionRange
Represents a range of selected text defined by an anchor (start) and an active (end) position. Used by LineScrollWindow to render selection highlights via WriteToWithSelection(StringBuilder, TextSelectionRange, string).
Implements
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public readonly struct TextSelectionRange : IEquatable<TextSelectionRange>
Remarks
Start is the selection anchor - the position where the user began the selection - and does not change as the selection is extended. End is the active position, updated as the user drags or shift-clicks.
Because selections can be made in reverse (dragging upward), Start may be after End in document order. Use Normalized, NormalizedStart, and NormalizedEnd to always get document-order positions regardless of selection direction.
Constructors
TextSelectionRange(TextSelectionPosition, TextSelectionPosition)
Creates a new text selection range.
Declaration
public TextSelectionRange(TextSelectionPosition start, TextSelectionPosition end)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | start | The starting position. |
| TextSelectionPosition | end | The ending position. |
Fields
Empty
An empty/invalid selection range.
Both Start and End are set to Invalid.
Calling IsValid on this value returns false.
Declaration
public static readonly TextSelectionRange Empty
Field Value
| Type | Description |
|---|---|
| TextSelectionRange |
End
The active end of the selection: the position where the cursor currently is. This position changes as the user extends the selection by dragging or shift-clicking.
Declaration
public readonly TextSelectionPosition End
Field Value
| Type | Description |
|---|---|
| TextSelectionPosition |
Start
The selection anchor: the position where the user clicked or began the selection. This position does not change as the selection is extended by dragging or shift-clicking.
Declaration
public readonly TextSelectionPosition Start
Field Value
| Type | Description |
|---|---|
| TextSelectionPosition |
Properties
IsEmpty
Gets whether this selection range is empty.
Returns true when the range is invalid OR when Start equals
End (a zero-width selection representing a caret position).
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsValid
Gets whether this selection range represents valid positions.
Requires both Start and End to have
LogicalLineIndex >= 0 and CharacterIndex >= 0.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Normalized
Gets a normalized version of this range where Start is always at or before End in document order. Useful when iterating through selected text from top to bottom.
Declaration
public TextSelectionRange Normalized { get; }
Property Value
| Type | Description |
|---|---|
| TextSelectionRange |
Remarks
For a reversed selection (where the user dragged upward so that the anchor is below the cursor), returns a new TextSelectionRange with Start and End swapped so the earlier position is always Start. The original range is not modified.
NormalizedEnd
Gets the later of Start and End in document order. Uses the same comparison as Normalized but returns only the position, avoiding construction of a new range.
Declaration
public TextSelectionPosition NormalizedEnd { get; }
Property Value
| Type | Description |
|---|---|
| TextSelectionPosition |
NormalizedStart
Gets the earlier of Start and End in document order. Uses the same comparison as Normalized but returns only the position, avoiding construction of a new range.
Declaration
public TextSelectionPosition NormalizedStart { get; }
Property Value
| Type | Description |
|---|---|
| TextSelectionPosition |
Methods
Contains(TextSelectionPosition)
Checks whether the specified position falls within this selection range. The check is half-open: a position at exactly NormalizedEnd is NOT considered contained. This matches standard text selection convention where the end position is the first character after the selection.
Declaration
public bool Contains(TextSelectionPosition position)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionPosition | position | The position to test. |
Returns
| Type | Description |
|---|---|
| bool |
|
ContainsLine(int)
Checks whether the specified logical line index falls within the selection range. A line is considered in the selection even if only part of it is selected (i.e., the selection starts or ends mid-line).
Declaration
public bool ContainsLine(int logicalLineIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | logicalLineIndex | The logical line index to test. The check is inclusive:
|
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(TextSelectionRange)
Determines whether this range equals another using raw (un-normalized) position comparison. Two selections that cover the same text extent but were made in opposite directions (different anchor/active order) are NOT considered equal.
Declaration
public bool Equals(TextSelectionRange other)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionRange | other | The other range. |
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
GetLineSelectionRange(int, int, out int, out int)
Gets the selected character range for a specific logical line.
Declaration
public bool GetLineSelectionRange(int logicalLineIndex, int lineLength, out int startChar, out int endChar)
Parameters
| Type | Name | Description |
|---|---|---|
| int | logicalLineIndex | The logical line index to query. |
| int | lineLength | The total number of characters in the line. |
| int | startChar | The first selected character index on this line (inclusive).
For the first line of the selection, this is |
| int | endChar | One past the last selected character index on this line (exclusive).
For the last line of the selection, this is |
Returns
| Type | Description |
|---|---|
| bool |
|
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Operators
operator ==(TextSelectionRange, TextSelectionRange)
Declaration
public static bool operator ==(TextSelectionRange left, TextSelectionRange right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionRange | left | The left operand. |
| TextSelectionRange | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(TextSelectionRange, TextSelectionRange)
Declaration
public static bool operator !=(TextSelectionRange left, TextSelectionRange right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSelectionRange | left | The left operand. |
| TextSelectionRange | right | The right operand. |
Returns
| Type | Description |
|---|---|
| bool |
|