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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 { | 202 { |
203 TreeElement.call(this, revision.timestamp.toLocaleTimeString(), true); | 203 TreeElement.call(this, revision.timestamp.toLocaleTimeString(), true); |
204 this.selectable = false; | 204 this.selectable = false; |
205 | 205 |
206 this._revision = revision; | 206 this._revision = revision; |
207 this._baseRevision = baseRevision; | 207 this._baseRevision = baseRevision; |
208 | 208 |
209 this._revertElement = createElement("span"); | 209 this._revertElement = createElement("span"); |
210 this._revertElement.className = "revision-history-link"; | 210 this._revertElement.className = "revision-history-link"; |
211 this._revertElement.textContent = WebInspector.UIString("apply revision cont ent"); | 211 this._revertElement.textContent = WebInspector.UIString("apply revision cont ent"); |
212 this._revertElement.addEventListener("click", this._revision.revertToThis.bi nd(this._revision), false); | 212 this._revertElement.addEventListener("click", event => {this._revision.rever tToThis();}, false); |
213 if (!allowRevert) | 213 if (!allowRevert) |
214 this._revertElement.classList.add("hidden"); | 214 this._revertElement.classList.add("hidden"); |
215 } | 215 } |
216 | 216 |
217 WebInspector.RevisionHistoryTreeElement.prototype = { | 217 WebInspector.RevisionHistoryTreeElement.prototype = { |
218 onattach: function() | 218 onattach: function() |
219 { | 219 { |
220 this.listItemElement.classList.add("revision-history-revision"); | 220 this.listItemElement.classList.add("revision-history-revision"); |
221 }, | 221 }, |
222 | 222 |
223 onpopulate: function() | 223 onpopulate: function() |
224 { | 224 { |
225 this.listItemElement.appendChild(this._revertElement); | 225 this.listItemElement.appendChild(this._revertElement); |
226 | 226 |
227 this.childrenListElement.classList.add("source-code"); | 227 this.childrenListElement.classList.add("source-code"); |
228 if (this._baseRevision) | 228 var promises = []; |
229 this._baseRevision.requestContent(step1.bind(this)); | 229 if (this._baseRevision) { |
230 else | 230 promises = [ |
231 this._revision.uiSourceCode.requestOriginalContent(step1.bind(this)) ; | 231 this._baseRevision.requestContent(), |
232 | 232 this._revision.requestContent() |
pfeldman
2016/01/20 19:23:51
merge this below via push, use ternary operator fo
lushnikov
2016/01/20 23:35:58
Done.
| |
233 /** | 233 ] |
234 * @param {?string} baseContent | 234 } else { |
235 * @this {WebInspector.RevisionHistoryTreeElement} | 235 promises = [ |
236 */ | 236 this._revision.uiSourceCode.requestOriginalContent(), |
237 function step1(baseContent) | 237 this._revision.requestContent() |
238 { | 238 ] |
239 this._revision.requestContent(step2.bind(this, baseContent)); | |
240 } | 239 } |
240 Promise.all(promises).spread(diff.bind(this)); | |
241 | 241 |
242 /** | 242 /** |
243 * @param {?string} baseContent | 243 * @param {?string} baseContent |
244 * @param {?string} newContent | 244 * @param {?string} newContent |
245 * @this {WebInspector.RevisionHistoryTreeElement} | 245 * @this {WebInspector.RevisionHistoryTreeElement} |
246 */ | 246 */ |
247 function step2(baseContent, newContent) | 247 function diff(baseContent, newContent) |
248 { | 248 { |
249 var baseLines = baseContent.split("\n"); | 249 var baseLines = baseContent.split("\n"); |
250 var newLines = newContent.split("\n"); | 250 var newLines = newContent.split("\n"); |
251 var opcodes = WebInspector.Diff.lineDiff(baseLines, newLines); | 251 var opcodes = WebInspector.Diff.lineDiff(baseLines, newLines); |
252 var lastWasSeparator = false; | 252 var lastWasSeparator = false; |
253 | 253 |
254 var baseLineNumber = 0; | 254 var baseLineNumber = 0; |
255 var newLineNumber = 0; | 255 var newLineNumber = 0; |
256 for (var idx = 0; idx < opcodes.length; idx++) { | 256 for (var idx = 0; idx < opcodes.length; idx++) { |
257 var code = opcodes[idx][0]; | 257 var code = opcodes[idx][0]; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 contentSpan.classList.add("revision-history-line-" + changeType); | 313 contentSpan.classList.add("revision-history-line-" + changeType); |
314 }, | 314 }, |
315 | 315 |
316 allowRevert: function() | 316 allowRevert: function() |
317 { | 317 { |
318 this._revertElement.classList.remove("hidden"); | 318 this._revertElement.classList.remove("hidden"); |
319 }, | 319 }, |
320 | 320 |
321 __proto__: TreeElement.prototype | 321 __proto__: TreeElement.prototype |
322 } | 322 } |
OLD | NEW |