Option Strict On
Option Explicit On

Imports System

Namespace Nexamas.UI.TextInput

    ' CONTRACT:
    ' MASTextMultilineSelectionSpan represents the intersection between
    ' a logical selection range and one visual wrapped line.
    '
    ' It is immutable data used by renderers and tests.
    Friend NotInheritable Class MASTextMultilineSelectionSpan

        Friend Sub New(line As MASTextWrappedLine,
                       selectionStart As Integer,
                       selectionEndExclusive As Integer)
            If line Is Nothing Then Throw New ArgumentNullException(NameOf(line))
            If selectionStart < 0 Then Throw New ArgumentOutOfRangeException(NameOf(selectionStart))
            If selectionEndExclusive < selectionStart Then Throw New ArgumentOutOfRangeException(NameOf(selectionEndExclusive))

            Me.Line = line
            Me.SelectionStart = selectionStart
            Me.SelectionEndExclusive = selectionEndExclusive
        End Sub

        Friend ReadOnly Property Line As MASTextWrappedLine
        Friend ReadOnly Property SelectionStart As Integer
        Friend ReadOnly Property SelectionEndExclusive As Integer

        Friend ReadOnly Property Length As Integer
            Get
                Return SelectionEndExclusive - SelectionStart
            End Get
        End Property

        Friend ReadOnly Property LocalStart As Integer
            Get
                Return Line.ToLocalIndex(SelectionStart)
            End Get
        End Property

        Friend ReadOnly Property LocalEndExclusive As Integer
            Get
                Return Line.ToLocalIndex(SelectionEndExclusive)
            End Get
        End Property

    End Class

End Namespace
