@@ -100,34 +100,41 @@ export default class SideBySideRenderer {
100
100
left : this . makeHeaderHtml ( block . header , file ) ,
101
101
right : this . makeHeaderHtml ( '' ) ,
102
102
} ;
103
-
103
+ let contextStash : ( DiffLineContent & DiffLineContext ) [ ] = [ ] ; // if white space are ignored, context should be relevant
104
+ let processContext = false ;
104
105
this . applyLineGroupping ( block ) . forEach ( ( [ contextLines , oldLines , newLines ] ) => {
105
106
if ( oldLines . length && newLines . length && ! contextLines . length ) {
106
107
this . applyRematchMatching ( oldLines , newLines , matcher ) . map ( ( [ oldLines , newLines ] ) => {
107
108
const { left, right } = this . processChangedLines ( file . isCombined , oldLines , newLines ) ;
108
109
fileHtml . left += left ;
109
110
fileHtml . right += right ;
111
+ if ( ! left && ! right ) {
112
+ contextStash = [ ] ;
113
+ processContext = false ;
114
+ } else processContext = true ;
110
115
} ) ;
111
- } else if ( contextLines . length ) {
112
- contextLines . forEach ( line => {
113
- const { prefix, content } = renderUtils . deconstructLine ( line . content , file . isCombined ) ;
114
- const { left, right } = this . generateLineHtml (
115
- {
116
- type : renderUtils . CSSLineClass . CONTEXT ,
117
- prefix : prefix ,
118
- content : content ,
119
- number : line . oldNumber ,
120
- } ,
121
- {
122
- type : renderUtils . CSSLineClass . CONTEXT ,
123
- prefix : prefix ,
124
- content : content ,
125
- number : line . newNumber ,
126
- } ,
127
- ) ;
128
- fileHtml . left += left ;
129
- fileHtml . right += right ;
130
- } ) ;
116
+ } else if ( contextLines . length || contextStash . length ) {
117
+ if ( ! processContext ) contextStash = contextStash . concat ( contextLines ) ;
118
+ else
119
+ contextLines . concat ( processContext ? contextStash : [ ] ) . forEach ( line => {
120
+ const { prefix, content } = renderUtils . deconstructLine ( line . content , file . isCombined ) ;
121
+ const { left, right } = this . generateLineHtml (
122
+ {
123
+ type : renderUtils . CSSLineClass . CONTEXT ,
124
+ prefix : prefix ,
125
+ content : content ,
126
+ number : line . oldNumber ,
127
+ } ,
128
+ {
129
+ type : renderUtils . CSSLineClass . CONTEXT ,
130
+ prefix : prefix ,
131
+ content : content ,
132
+ number : line . newNumber ,
133
+ } ,
134
+ ) ;
135
+ fileHtml . left += left ;
136
+ fileHtml . right += right ;
137
+ } ) ;
131
138
} else if ( oldLines . length || newLines . length ) {
132
139
const { left, right } = this . processChangedLines ( file . isCombined , oldLines , newLines ) ;
133
140
fileHtml . left += left ;
0 commit comments