@@ -36,15 +36,17 @@ export class PieceTreeTextBuffer implements ITextBuffer, IDisposable {
3636 private readonly _pieceTree : PieceTreeBase ;
3737 private readonly _BOM : string ;
3838 private _mightContainRTL : boolean ;
39+ private _mightContainUnusualLineTerminators : boolean ;
3940 private _mightContainNonBasicASCII : boolean ;
4041
4142 private readonly _onDidChangeContent : Emitter < void > = new Emitter < void > ( ) ;
4243 public readonly onDidChangeContent : Event < void > = this . _onDidChangeContent . event ;
4344
44- constructor ( chunks : StringBuffer [ ] , BOM : string , eol : '\r\n' | '\n' , containsRTL : boolean , isBasicASCII : boolean , eolNormalized : boolean ) {
45+ constructor ( chunks : StringBuffer [ ] , BOM : string , eol : '\r\n' | '\n' , containsRTL : boolean , containsUnusualLineTerminators : boolean , isBasicASCII : boolean , eolNormalized : boolean ) {
4546 this . _BOM = BOM ;
4647 this . _mightContainNonBasicASCII = ! isBasicASCII ;
4748 this . _mightContainRTL = containsRTL ;
49+ this . _mightContainUnusualLineTerminators = containsUnusualLineTerminators ;
4850 this . _pieceTree = new PieceTreeBase ( chunks , eol , eolNormalized ) ;
4951 }
5052 dispose ( ) : void {
@@ -67,6 +69,12 @@ export class PieceTreeTextBuffer implements ITextBuffer, IDisposable {
6769 public mightContainRTL ( ) : boolean {
6870 return this . _mightContainRTL ;
6971 }
72+ public mightContainUnusualLineTerminators ( ) : boolean {
73+ return this . _mightContainUnusualLineTerminators ;
74+ }
75+ public resetMightContainUnusualLineTerminators ( ) : void {
76+ this . _mightContainUnusualLineTerminators = false ;
77+ }
7078 public mightContainNonBasicASCII ( ) : boolean {
7179 return this . _mightContainNonBasicASCII ;
7280 }
@@ -216,6 +224,7 @@ export class PieceTreeTextBuffer implements ITextBuffer, IDisposable {
216224
217225 public applyEdits ( rawOperations : ValidAnnotatedEditOperation [ ] , recordTrimAutoWhitespace : boolean , computeUndoEdits : boolean ) : ApplyEditsResult {
218226 let mightContainRTL = this . _mightContainRTL ;
227+ let mightContainUnusualLineTerminators = this . _mightContainUnusualLineTerminators ;
219228 let mightContainNonBasicASCII = this . _mightContainNonBasicASCII ;
220229 let canReduceOperations = true ;
221230
@@ -226,12 +235,20 @@ export class PieceTreeTextBuffer implements ITextBuffer, IDisposable {
226235 canReduceOperations = false ;
227236 }
228237 let validatedRange = op . range ;
229- if ( ! mightContainRTL && op . text ) {
230- // check if the new inserted text contains RTL
231- mightContainRTL = strings . containsRTL ( op . text ) ;
232- }
233- if ( ! mightContainNonBasicASCII && op . text ) {
234- mightContainNonBasicASCII = ! strings . isBasicASCII ( op . text ) ;
238+ if ( op . text ) {
239+ let textMightContainNonBasicASCII = true ;
240+ if ( ! mightContainNonBasicASCII ) {
241+ textMightContainNonBasicASCII = ! strings . isBasicASCII ( op . text ) ;
242+ mightContainNonBasicASCII = textMightContainNonBasicASCII ;
243+ }
244+ if ( ! mightContainRTL && textMightContainNonBasicASCII ) {
245+ // check if the new inserted text contains RTL
246+ mightContainRTL = strings . containsRTL ( op . text ) ;
247+ }
248+ if ( ! mightContainUnusualLineTerminators && textMightContainNonBasicASCII ) {
249+ // check if the new inserted text contains unusual line terminators
250+ mightContainUnusualLineTerminators = strings . containsUnusualLineTerminators ( op . text ) ;
251+ }
235252 }
236253
237254 let validText = '' ;
@@ -340,6 +357,7 @@ export class PieceTreeTextBuffer implements ITextBuffer, IDisposable {
340357
341358
342359 this . _mightContainRTL = mightContainRTL ;
360+ this . _mightContainUnusualLineTerminators = mightContainUnusualLineTerminators ;
343361 this . _mightContainNonBasicASCII = mightContainNonBasicASCII ;
344362
345363 const contentChanges = this . _doApplyEdits ( operations ) ;
0 commit comments