OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 this._revision.requestContent(step2.bind(this, baseContent)); | 233 this._revision.requestContent(step2.bind(this, baseContent)); |
234 } | 234 } |
235 | 235 |
236 /** | 236 /** |
237 * @param {?string} baseContent | 237 * @param {?string} baseContent |
238 * @param {?string} newContent | 238 * @param {?string} newContent |
239 * @this {WebInspector.RevisionHistoryTreeElement} | 239 * @this {WebInspector.RevisionHistoryTreeElement} |
240 */ | 240 */ |
241 function step2(baseContent, newContent) | 241 function step2(baseContent, newContent) |
242 { | 242 { |
243 var baseLines = difflib.stringAsLines(baseContent); | 243 var baseLines = baseContent.split("\n"); |
244 var newLines = difflib.stringAsLines(newContent); | 244 var newLines = newContent.split("\n"); |
245 var sm = new difflib.SequenceMatcher(baseLines, newLines); | 245 var opcodes = WebInspector.Diff.lineDiff(baseLines, newLines); |
246 var opcodes = sm.get_opcodes(); | |
247 var lastWasSeparator = false; | 246 var lastWasSeparator = false; |
248 | 247 |
| 248 var baseLineNumber = 0; |
| 249 var newLineNumber = 0; |
249 for (var idx = 0; idx < opcodes.length; idx++) { | 250 for (var idx = 0; idx < opcodes.length; idx++) { |
250 var code = opcodes[idx]; | 251 var code = opcodes[idx][0]; |
251 var change = code[0]; | 252 var rowCount = opcodes[idx][1].length; |
252 var b = code[1]; | 253 if (code === WebInspector.Diff.Operation.Equal) { |
253 var be = code[2]; | 254 baseLineNumber += rowCount; |
254 var n = code[3]; | 255 newLineNumber += rowCount; |
255 var ne = code[4]; | 256 if (!lastWasSeparator) |
256 var rowCount = Math.max(be - b, ne - n); | 257 this._createLine(null, null, " \u2026", "separator"); |
257 for (var i = 0; i < rowCount; i++) { | 258 lastWasSeparator = true; |
258 if (change === "delete" || (change === "replace" && b < be))
{ | 259 } else if (code === WebInspector.Diff.Operation.Delete) { |
259 var lineNumber = b++; | 260 lastWasSeparator = false; |
260 this._createLine(lineNumber, null, baseLines[lineNumber]
, "removed"); | 261 for (var i = 0; i < rowCount; ++i) |
261 lastWasSeparator = false; | 262 this._createLine(baseLineNumber + i, null, baseLines[bas
eLineNumber + i], "removed"); |
262 } | 263 baseLineNumber += rowCount; |
263 | 264 } else if (code === WebInspector.Diff.Operation.Insert) { |
264 if (change === "insert" || (change === "replace" && n < ne))
{ | 265 lastWasSeparator = false; |
265 var lineNumber = n++; | 266 for (var i = 0; i < rowCount; ++i) |
266 this._createLine(null, lineNumber, newLines[lineNumber],
"added"); | 267 this._createLine(null, newLineNumber + i, newLines[newLi
neNumber + i], "added"); |
267 lastWasSeparator = false; | 268 newLineNumber += rowCount; |
268 } | |
269 | |
270 if (change === "equal") { | |
271 b++; | |
272 n++; | |
273 if (!lastWasSeparator) | |
274 this._createLine(null, null, " \u2026", "separato
r"); | |
275 lastWasSeparator = true; | |
276 } | |
277 } | 269 } |
278 } | 270 } |
279 } | 271 } |
280 }, | 272 }, |
281 | 273 |
282 oncollapse: function() | 274 oncollapse: function() |
283 { | 275 { |
284 this._revertElement.remove(); | 276 this._revertElement.remove(); |
285 }, | 277 }, |
286 | 278 |
(...skipping 28 matching lines...) Expand all Loading... |
315 contentSpan.classList.add("revision-history-line-" + changeType); | 307 contentSpan.classList.add("revision-history-line-" + changeType); |
316 }, | 308 }, |
317 | 309 |
318 allowRevert: function() | 310 allowRevert: function() |
319 { | 311 { |
320 this._revertElement.classList.remove("hidden"); | 312 this._revertElement.classList.remove("hidden"); |
321 }, | 313 }, |
322 | 314 |
323 __proto__: TreeElement.prototype | 315 __proto__: TreeElement.prototype |
324 } | 316 } |
OLD | NEW |