@@ -67,9 +67,15 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
6767 * is attached so CodeMirror get proper size.
6868 */
6969 onAfterAttach ( ) : void {
70- this . createDiffView ( ) . catch ( reason => {
71- this . showError ( reason ) ;
72- } ) ;
70+ this . ready
71+ . then ( ( ) => {
72+ if ( this . _challenger !== null && this . _reference !== null ) {
73+ this . createDiffView ( this . _challenger , this . _reference ) ;
74+ }
75+ } )
76+ . catch ( reason => {
77+ this . showError ( reason ) ;
78+ } ) ;
7379 }
7480
7581 /**
@@ -90,8 +96,18 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
9096 // Clear all
9197 this . _container . innerHTML = '' ;
9298 this . _mergeView = null ;
99+
93100 // ENH request content only if it changed
94- this . createDiffView ( ) ;
101+ if ( this . _reference !== null ) {
102+ this . _reference = await this . _model . reference . content ( ) ;
103+ }
104+ if ( this . _challenger !== null ) {
105+ this . _challenger = await this . _model . challenger . content ( ) ;
106+ }
107+
108+ this . createDiffView ( this . _challenger , this . _reference ) ;
109+ this . _challenger = null ;
110+ this . _reference = null ;
95111 } catch ( reason ) {
96112 this . showError ( reason ) ;
97113 }
@@ -119,31 +135,24 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
119135 /**
120136 * Create the Plain Text Diff view
121137 */
122- protected async createDiffView ( ) : Promise < void > {
138+ protected async createDiffView (
139+ challengerContent : string ,
140+ referenceContent : string
141+ ) : Promise < void > {
123142 if ( ! this . _mergeView ) {
124143 const mode =
125144 Mode . findByFileName ( this . _model . filename ) ||
126145 Mode . findBest ( this . _model . filename ) ;
127146
128- await this . ready ;
129-
130- if ( ! this . _reference ) {
131- this . _reference = await this . _model . reference . content ( ) ;
132- }
133- if ( ! this . _challenger ) {
134- this . _challenger = await this . _model . challenger . content ( ) ;
135- }
136-
137147 this . _mergeView = mergeView ( this . _container , {
138- value : this . _challenger ,
139- orig : this . _reference ,
148+ value : challengerContent ,
149+ orig : referenceContent ,
140150 mode : mode . mime ,
141- ...PlainTextDiff . getDefaultOptions ( )
151+ ...this . getDefaultOptions ( )
142152 } ) as MergeView . MergeViewEditor ;
143-
144- this . _reference = null ;
145- this . _challenger = null ;
146153 }
154+
155+ return Promise . resolve ( ) ;
147156 }
148157
149158 /**
@@ -164,7 +173,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
164173 </p>` ;
165174 }
166175
167- protected static getDefaultOptions ( ) : Partial < MergeView . MergeViewEditorConfiguration > {
176+ protected getDefaultOptions ( ) : Partial < MergeView . MergeViewEditorConfiguration > {
168177 // FIXME add options from settings and connect settings to update options
169178 return {
170179 lineNumbers : true ,
0 commit comments