|
122 | 122 | var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
123 | 123 |
|
124 | 124 | fileHtml.left +=
|
125 |
| - that.generateSingleLineHtml(deleteType, oldLine.oldNumber, |
| 125 | + that.generateSingleLineHtml(file.isCombined, deleteType, oldLine.oldNumber, |
126 | 126 | diff.first.line, diff.first.prefix);
|
127 | 127 | fileHtml.right +=
|
128 |
| - that.generateSingleLineHtml(insertType, newLine.newNumber, |
| 128 | + that.generateSingleLineHtml(file.isCombined, insertType, newLine.newNumber, |
129 | 129 | diff.second.line, diff.second.prefix);
|
130 | 130 | }
|
131 | 131 |
|
132 | 132 | if (max > common) {
|
133 | 133 | var oldSlice = oldLines.slice(common);
|
134
F987
| 134 | var newSlice = newLines.slice(common);
|
135 | 135 |
|
136 |
| - var tmpHtml = that.processLines(oldSlice, newSlice); |
| 136 | + var tmpHtml = that.processLines(file.isCombined, oldSlice, newSlice); |
137 | 137 | fileHtml.left += tmpHtml.left;
|
138 | 138 | fileHtml.right += tmpHtml.right;
|
139 | 139 | }
|
|
154 | 154 | }
|
155 | 155 |
|
156 | 156 | if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
157 |
| - fileHtml.left += that.generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix); |
158 |
| - fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix); |
| 157 | + fileHtml.left += that.generateSingleLineHtml(file.isCombined, line.type, line.oldNumber, escapedLine, prefix); |
| 158 | + fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix); |
159 | 159 | } else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
160 |
| - fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); |
161 |
| - fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix); |
| 160 | + fileHtml.left += that.generateSingleLineHtml(file.isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', ''); |
| 161 | + fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix); |
162 | 162 | } else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
163 | 163 | oldLines.push(line);
|
164 | 164 | } else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
|
175 | 175 | return fileHtml;
|
176 | 176 | };
|
177 | 177 |
|
178 |
| - SideBySidePrinter.prototype.processLines = function(oldLines, newLines) { |
| 178 | + SideBySidePrinter.prototype.processLines = function(isCombined, oldLines, newLines) { |
179 | 179 | var that = this;
|
180 | 180 | var fileHtml = {};
|
181 | 181 | fileHtml.left = '';
|
|
201 | 201 | }
|
202 | 202 |
|
203 | 203 | if (oldLine && newLine) {
|
204 |
| - fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); |
205 |
| - fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix); |
| 204 | + fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); |
| 205 | + fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix); |
206 | 206 | } else if (oldLine) {
|
207 |
| - fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); |
208 |
| - fileHtml.right += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); |
| 207 | + fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); |
| 208 | + fileHtml.right += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', ''); |
209 | 209 | } else if (newLine) {
|
210 |
| - fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); |
211 |
| - fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix); |
| 210 | + fileHtml.left += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', ''); |
| 211 | + fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix); |
212 | 212 | } else {
|
213 | 213 | console.error('How did it get here?');
|
214 | 214 | }
|
|
217 | 217 | return fileHtml;
|
218 | 218 | };
|
219 | 219 |
|
220 |
| - SideBySidePrinter.prototype.generateSingleLineHtml = function(type, number, content, prefix) { |
| 220 | + SideBySidePrinter.prototype.generateSingleLineHtml = function(isCombined, type, number, content, possiblePrefix) { |
| 221 | + var lineWithoutPrefix = content; |
| 222 | + var prefix = possiblePrefix; |
| 223 | + |
| 224 | + if (!prefix) { |
| 225 | + var lineWithPrefix = printerUtils.separatePrefix(isCombined, content); |
| 226 | + prefix = lineWithPrefix.prefix; |
| 227 | + lineWithoutPrefix = lineWithPrefix.line; |
| 228 | + } |
| 229 | + |
221 | 230 | return hoganUtils.render(genericTemplatesPath, 'line',
|
222 | 231 | {
|
223 | 232 | type: type,
|
224 | 233 | lineClass: 'd2h-code-side-linenumber',
|
225 | 234 | contentClass: 'd2h-code-side-line',
|
226 |
| - prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix), |
227 |
| - content: content && utils.convertWhiteSpaceToNonBreakingSpace(content), |
| 235 | + prefix: prefix, |
| 236 | + content: lineWithoutPrefix, |
228 | 237 | lineNumber: number
|
229 | 238 | });
|
230 | 239 | };
|
|
0 commit comments