@@ -43,6 +43,10 @@ class Merged extends MainRenderer implements SubRendererInterface
4343 * @var string last block of lines which where removed from version 2.
4444 */
4545 private $ lastDeleted ;
46+ /**
47+ * @var string
48+ */
49+ private $ headerClass = '' ;
4650
4751 /**
4852 * Merged constructor.
@@ -101,21 +105,17 @@ public function generateBlockHeader(array $changes): string
101105 */
102106 public function generateSkippedLines (): string
103107 {
104- $ marker = '… ' ;
105- $ headerClass = '' ;
106-
107- if ($ this ->lastDeleted !== null ) {
108- $ headerClass = 'ChangeDelete ' ;
109- }
110-
111- $ this ->lastDeleted = null ;
112-
113- return <<<HTML
108+ $ html = <<<HTML
114109<tr>
115- <th class=" $ headerClass" title=" {$ this ->lastDeleted }"> $ marker </th>
110+ <th class=" { $ this -> headerClass } " title=" {$ this ->lastDeleted }">… </th>
116111 <td class="Skipped">…</td>
117112</tr>
118113HTML ;
114+
115+ $ this ->headerClass = '' ;
116+ $ this ->lastDeleted = null ;
117+
118+ return $ html ;
119119 }
120120
121121 /**
@@ -125,22 +125,20 @@ public function generateSkippedLines(): string
125125 */
126126 public function generateLinesEqual (array $ changes ): string
127127 {
128- $ html = '' ;
129- $ headerClass = '' ;
128+ $ html = '' ;
130129
131130 foreach ($ changes ['base ' ]['lines ' ] as $ lineNo => $ line ) {
132131 $ fromLine = $ changes ['base ' ]['offset ' ] + $ lineNo + 1 + $ this ->lineOffset ;
133- if (!$ lineNo && $ this ->lastDeleted !== null ) {
134- $ headerClass = 'ChangeDelete ' ;
135- }
136132
137- $ html .= <<<HTML
133+ $ html .= <<<HTML
138134<tr>
139- <th class=" $ headerClass" title=" {$ this ->lastDeleted }"> $ fromLine</th>
135+ <th class=" { $ this -> headerClass } " title=" {$ this ->lastDeleted }"> $ fromLine</th>
140136 <td> $ line</td>
141137</tr>
142138HTML ;
139+
143140 $ this ->lastDeleted = null ;
141+ $ this ->headerClass = '' ;
144142 }
145143
146144 return $ html ;
@@ -153,22 +151,20 @@ public function generateLinesEqual(array $changes): string
153151 */
154152 public function generateLinesInsert (array $ changes ): string
155153 {
156- $ html = '' ;
157- $ headerClass = '' ;
154+ $ html = '' ;
158155
159- foreach ($ changes ['changed ' ]['lines ' ] as $ lineNo => $ line ) {
156+ foreach ($ changes ['changed ' ]['lines ' ] as $ line ) {
160157 $ this ->lineOffset ++;
161158 $ toLine = $ changes ['base ' ]['offset ' ] + $ this ->lineOffset ;
162- if (!$ lineNo && $ this ->lastDeleted !== null ) {
163- $ headerClass = 'ChangeDelete ' ;
164- }
165159
166160 $ html .= <<<HTML
167161<tr>
168- <th class=" $ headerClass" title=" {$ this ->lastDeleted }"> $ toLine</th>
162+ <th class=" { $ this -> headerClass } " title=" {$ this ->lastDeleted }"> $ toLine</th>
169163 <td><ins> $ line</ins></td>
170164</tr>
171165HTML ;
166+
167+ $ this ->headerClass = '' ;
172168 $ this ->lastDeleted = null ;
173169 }
174170
@@ -197,6 +193,7 @@ public function generateLinesDelete(array $changes): string
197193 }
198194
199195 $ this ->lastDeleted = $ title ;
196+ $ this ->headerClass = 'ChangeDelete ' ;
200197
201198 return '' ;
202199 }
@@ -208,14 +205,10 @@ public function generateLinesDelete(array $changes): string
208205 */
209206 public function generateLinesReplace (array $ changes ): string
210207 {
211- $ html = '' ;
212- $ headerClass = '' ;
208+ $ html = '' ;
213209
214210 foreach ($ changes ['base ' ]['lines ' ] as $ lineNo => $ line ) {
215211 $ fromLine = $ changes ['base ' ]['offset ' ] + $ lineNo + 1 + $ this ->lineOffset ;
216- if (!$ lineNo && $ this ->lastDeleted !== null ) {
217- $ headerClass = 'ChangeDelete ' ;
218- }
219212
220213 // Capture added parts.
221214 $ addedParts = [];
@@ -236,10 +229,11 @@ function ($removedParts) use ($addedParts) {
236229
237230 $ html .= <<<HTML
238231<tr>
239- <th class=" $ headerClass" title=" {$ this ->lastDeleted }"> $ fromLine</th>
232+ <th class=" { $ this -> headerClass } " title=" {$ this ->lastDeleted }"> $ fromLine</th>
240233 <td> $ line</td>
241234</tr>
242235HTML ;
236+ $ this ->headerClass = '' ;
243237 $ this ->lastDeleted = null ;
244238 }
245239
@@ -265,4 +259,30 @@ public function generateDiffFooter(): string
265259 {
266260 return '</table> ' ;
267261 }
262+
263+ /**
264+ * @inheritDoc
265+ *
266+ * @return string Modified text.
267+ */
268+ public function generateLinesIgnore (array $ changes ): string
269+ {
270+ $ baseLineCount = count ($ changes ['base ' ]['lines ' ]);
271+ $ changedLineCount = count ($ changes ['changed ' ]['lines ' ]);
272+
273+ $ this ->lineOffset -= $ baseLineCount ;
274+
275+ $ title = "Lines ignored at {$ this ->options ['title2 ' ]}: " ;
276+ $ title .= $ changes ['changed ' ]['offset ' ] + 1 . '- ' . ($ changes ['changed ' ]['offset ' ] + $ changedLineCount );
277+
278+ if ($ baseLineCount > $ changedLineCount ) {
279+ $ title = "Lines ignored at {$ this ->options ['title1 ' ]}: " ;
280+ $ title .= $ changes ['base ' ]['offset ' ] + 1 . '- ' . ($ changes ['base ' ]['offset ' ] + $ baseLineCount );
281+ }
282+
283+ $ this ->lastDeleted = $ title ;
284+ $ this ->headerClass = 'ChangeIgnore ' ;
285+
286+ return '' ;
287+ }
268288}
0 commit comments