@@ -159,10 +159,17 @@ export class DiffEditorViewZones extends Disposable {
159159
160160 const deletedCodeLineBreaksComputer = ! renderSideBySide ? this . _editors . modified . _getViewModel ( ) ?. createLineBreaksComputer ( ) : undefined ;
161161 if ( deletedCodeLineBreaksComputer ) {
162+ const originalModel = this . _editors . original . getModel ( ) ! ;
162163 for ( const a of alignmentsVal ) {
163164 if ( a . diff ) {
164165 for ( let i = a . originalRange . startLineNumber ; i < a . originalRange . endLineNumberExclusive ; i ++ ) {
165- deletedCodeLineBreaksComputer ?. addRequest ( this . _editors . original . getModel ( ) ! . getLineContent ( i ) , null , null ) ;
166+ // `i` can be out of bound when the diff has not been updated yet.
167+ // In this case, we do an early return.
168+ // TODO@hediet : Fix this by applying the edit directly to the diff model, so that the diff is always valid.
169+ if ( i > originalModel . getLineCount ( ) ) {
170+ return { orig : origViewZones , mod : modViewZones } ;
171+ }
172+ deletedCodeLineBreaksComputer ?. addRequest ( originalModel . getLineContent ( i ) , null , null ) ;
166173 }
167174 }
168175 }
@@ -186,8 +193,15 @@ export class DiffEditorViewZones extends Disposable {
186193
187194 const deletedCodeDomNode = document . createElement ( 'div' ) ;
188195 deletedCodeDomNode . classList . add ( 'view-lines' , 'line-delete' , 'monaco-mouse-cursor-text' ) ;
196+ const originalModel = this . _editors . original . getModel ( ) ! ;
197+ // `a.originalRange` can be out of bound when the diff has not been updated yet.
198+ // In this case, we do an early return.
199+ // TODO@hediet : Fix this by applying the edit directly to the diff model, so that the diff is always valid.
200+ if ( a . originalRange . endLineNumberExclusive - 1 > originalModel . getLineCount ( ) ) {
201+ return { orig : origViewZones , mod : modViewZones } ;
202+ }
189203 const source = new LineSource (
190- a . originalRange . mapToLineArray ( l => this . _editors . original . getModel ( ) ! . tokenization . getLineTokens ( l ) ) ,
204+ a . originalRange . mapToLineArray ( l => originalModel . tokenization . getLineTokens ( l ) ) ,
191205 a . originalRange . mapToLineArray ( _ => lineBreakData [ lineBreakDataIdx ++ ] ) ,
192206 mightContainNonBasicASCII ,
193207 mightContainRTL ,
@@ -551,7 +565,10 @@ function computeRangeAlignment(
551565 // There is some unmodified text on this line before the diff
552566 emitAlignment ( i . originalRange . startLineNumber , i . modifiedRange . startLineNumber ) ;
553567 }
554- if ( i . originalRange . endColumn < originalEditor . getModel ( ) ! . getLineMaxColumn ( i . originalRange . endLineNumber ) ) {
568+ const originalModel = originalEditor . getModel ( ) ! ;
569+ // When the diff is invalid, the ranges might be out of bounds (this should be fixed in the diff model by applying edits directly).
570+ const maxColumn = i . originalRange . endLineNumber <= originalModel . getLineCount ( ) ? originalModel . getLineMaxColumn ( i . originalRange . endLineNumber ) : Number . MAX_SAFE_INTEGER ;
571+ if ( i . originalRange . endColumn < maxColumn ) {
555572 // // There is some unmodified text on this line after the diff
556573 emitAlignment ( i . originalRange . endLineNumber , i . modifiedRange . endLineNumber ) ;
557574 }
0 commit comments