@@ -15,7 +15,7 @@ import { DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/com
1515import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer' ;
1616import { IndentRange , computeRanges } from 'vs/editor/common/model/indentRanges' ;
1717import { TextModelSearch , SearchParams } from 'vs/editor/common/model/textModelSearch' ;
18- import { ITextSource2 } from 'vs/editor/common/model/textSource' ;
18+ import { ITextSource , RawTextSource , IRawTextSource } from 'vs/editor/common/model/textSource' ;
1919
2020const LIMIT_FIND_COUNT = 999 ;
2121export const LONG_LINE_BOUNDARY = 1000 ;
@@ -286,7 +286,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
286286 }
287287 }
288288
289- protected _resetValue ( newValue : editorCommon . ITextSource ) : void {
289+ protected _resetValue ( newValue : ITextSource ) : void {
290290 this . _constructLines ( newValue ) ;
291291 this . _increaseVersionId ( ) ;
292292 }
@@ -304,7 +304,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
304304 } ;
305305 }
306306
307- public equals ( other : editorCommon . ITextSource ) : boolean {
307+ public equals ( other : ITextSource ) : boolean {
308308 this . _assertNotDisposed ( ) ;
309309 if ( this . _BOM !== other . BOM ) {
310310 return false ;
@@ -340,7 +340,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
340340 this . setValueFromRawText ( rawText ) ;
341341 }
342342
343- public setValueFromRawText ( newValue : editorCommon . ITextSource ) : void {
343+ public setValueFromRawText ( newValue : ITextSource ) : void {
344344 this . _assertNotDisposed ( ) ;
345345 if ( newValue === null ) {
346346 // There's nothing to do
@@ -750,43 +750,12 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
750750 }
751751 }
752752
753- public static toTextSource ( rawText : string ) : ITextSource2 {
754- // Count the number of lines that end with \r\n
755- let carriageReturnCnt = 0 ;
756- let lastCarriageReturnIndex = - 1 ;
757- while ( ( lastCarriageReturnIndex = rawText . indexOf ( '\r' , lastCarriageReturnIndex + 1 ) ) !== - 1 ) {
758- carriageReturnCnt ++ ;
759- }
760-
761- const containsRTL = strings . containsRTL ( rawText ) ;
762- const isBasicASCII = ( containsRTL ? false : strings . isBasicASCII ( rawText ) ) ;
763-
764- // Split the text into lines
765- const lines = rawText . split ( / \r \n | \r | \n / ) ;
766-
767- // Remove the BOM (if present)
768- let BOM = '' ;
769- if ( strings . startsWithUTF8BOM ( lines [ 0 ] ) ) {
770- BOM = strings . UTF8_BOM_CHARACTER ;
771- lines [ 0 ] = lines [ 0 ] . substr ( 1 ) ;
772- }
773-
774- return {
775- BOM : BOM ,
776- lines : lines ,
777- length : rawText . length ,
778- containsRTL : containsRTL ,
779- isBasicASCII : isBasicASCII ,
780- totalCRCount : carriageReturnCnt
781- } ;
782- }
783-
784753 /**
785754 * if text source is empty or with precisely one line, returns null. No end of line is detected.
786755 * if text source contains more lines ending with '\r\n', returns '\r\n'.
787756 * Otherwise returns '\n'. More lines end with '\n'.
788757 */
789- public static getEndOfLine ( textSource : ITextSource2 ) : string {
758+ public static getEndOfLine ( textSource : IRawTextSource ) : string {
790759 const lineFeedCnt = textSource . lines . length - 1 ;
791760 if ( lineFeedCnt === 0 ) {
792761 // This is an empty file or a file with precisely one line
@@ -801,11 +770,11 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
801770 }
802771
803772 public static toRawText ( rawText : string , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
804- const textSource = TextModel . toTextSource ( rawText ) ;
773+ const textSource = RawTextSource . fromString ( rawText ) ;
805774 return TextModel . toRawTextFromTextSource ( textSource , opts ) ;
806775 }
807776
808- public static toRawTextFromTextSource ( textSource : ITextSource2 , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
777+ public static toRawTextFromTextSource ( textSource : IRawTextSource , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
809778 let EOL = TextModel . getEndOfLine ( textSource ) ;
810779 if ( ! EOL ) {
811780 // This is an empty file or a file with precisely one line
@@ -841,7 +810,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
841810 } ;
842811 }
843812
844- private _constructLines ( rawText : editorCommon . ITextSource ) : void {
813+ private _constructLines ( rawText : ITextSource ) : void {
845814 const tabSize = this . _options . tabSize ;
846815 let rawLines = rawText . lines ;
847816 let modelLines : ModelLine [ ] = [ ] ;
@@ -898,15 +867,15 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
898867
899868export class RawText {
900869
901- public static toRawText ( textSourceOrString : ITextSource2 | string , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
870+ public static toRawText ( textSourceOrString : IRawTextSource | string , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
902871 if ( typeof textSourceOrString === 'string' ) {
903872 return RawText . fromString ( textSourceOrString , opts ) ;
904873 } else {
905874 return RawText . fromTextSource ( textSourceOrString , opts ) ;
906875 }
907876 }
908877
909- public static toRawTextWithModelOptions ( textSourceOrString : ITextSource2 | string , model : editorCommon . IModel ) : editorCommon . IRawText {
878+ public static toRawTextWithModelOptions ( textSourceOrString : IRawTextSource | string , model : editorCommon . IModel ) : editorCommon . IRawText {
910879 if ( typeof textSourceOrString === 'string' ) {
911880 return RawText . fromStringWithModelOptions ( textSourceOrString , model ) ;
912881 } else {
@@ -918,7 +887,7 @@ export class RawText {
918887 return TextModel . toRawText ( rawText , opts ) ;
919888 }
920889
921- public static fromTextSource ( textSource : ITextSource2 , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
890+ public static fromTextSource ( textSource : IRawTextSource , opts : editorCommon . ITextModelCreationOptions ) : editorCommon . IRawText {
922891 return TextModel . toRawTextFromTextSource ( textSource , opts ) ;
923892 }
924893
@@ -933,7 +902,7 @@ export class RawText {
933902 } ) ;
934903 }
935904
936- public static fromTextSourceWithModelOptions ( textSource : ITextSource2 , model : editorCommon . IModel ) : editorCommon . IRawText {
905+ public static fromTextSourceWithModelOptions ( textSource : IRawTextSource , model : editorCommon . IModel ) : editorCommon . IRawText {
937906 let opts = model . getOptions ( ) ;
938907 return TextModel . toRawTextFromTextSource ( textSource , {
939908 tabSize : opts . tabSize ,
0 commit comments