import { Selection } from './Selection' ; import { GenericLine } from './lines' ; export interface TextLine extends GenericLine { text : string ; } /**
 * Intermediary entity between pure text and  quill-delta .
 *
 *  remarks export class Text { public readonly raw : string ; public readonly beginningIndex : number = 0 ; public constructor ( rawText , beginningIndex ? ) { this . raw = rawText ; this . beginningIndex = beginningIndex || 0 ; } private documentToTextIndex ( documentIndex ) { return documentIndex - this . beginningIndex ; } private textToDocumentIndex ( textIndex ) { return textIndex + this . beginningIndex ; } public get length ( ) { return this . raw . length ; } param from param to public substring ( from , to ) { return this . raw . substring ( this . documentToTextIndex ( from ) , this . documentToTextIndex ( to ) ) ; } param documentIndex public charAt ( documentIndex ) { return this . raw . charAt ( this . documentToTextIndex ( documentIndex ) ) ; } param documentSelection returns A new  Text instance which is a substring of `this` instance with Document coordiantes.
      public select ( documentSelection ) { return new Text ( this . substring ( documentSelection . start , documentSelection . end ) , documentSelection . start ) ; } remarks param documentSelection public getSelectionEncompassingLines ( documentSelection ) { let textStart = documentSelection . start - this . beginningIndex ; let textEnd = documentSelection . end - this . beginningIndex ; while ( textStart > 0 && this . raw . charAt ( textStart - 1 ) !== '\n' ) { textStart -= 1 ; } while ( textEnd < this . raw . length && this . raw . charAt ( textEnd ) !== '\n' ) { textEnd += 1 ; } return Selection . fromBounds ( this . textToDocumentIndex ( textStart ) , this . textToDocumentIndex ( textEnd ) ) ; } returns A list of lines complying with the  GenericLine contract.
      public getLines ( ) { let charIndex = this . beginningIndex - 1 ; let lineIndex = - 1 ; const lines = this . raw . split ( '\n' ) ; return lines . map ( text => { const start = charIndex + 1 ; charIndex = start + text . length ; lineIndex += 1 ; const lineRange = Selection . fromBounds ( start , charIndex ) ; return { text , lineRange , index : lineIndex , } ; } ) ; } }