| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {!WebInspector.UISourceCode} uiSourceCode | 7 * @param {!Promise<?string>} diffBaseline |
| 8 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 8 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| 9 */ | 9 */ |
| 10 WebInspector.SourceCodeDiff = function(uiSourceCode, textEditor) | 10 WebInspector.SourceCodeDiff = function(diffBaseline, textEditor) |
| 11 { | 11 { |
| 12 this._uiSourceCode = uiSourceCode; | |
| 13 this._textEditor = textEditor; | 12 this._textEditor = textEditor; |
| 14 this._decorations = []; | 13 this._decorations = []; |
| 15 this._textEditor.installGutter(WebInspector.SourceCodeDiff.DiffGutterType, t
rue); | 14 this._textEditor.installGutter(WebInspector.SourceCodeDiff.DiffGutterType, t
rue); |
| 16 this._diffBaseline = this._uiSourceCode.requestOriginalContent(); | 15 this._diffBaseline = diffBaseline; |
| 17 /** @type {!Array<!WebInspector.TextEditorPositionHandle>}*/ | 16 /** @type {!Array<!WebInspector.TextEditorPositionHandle>}*/ |
| 18 this._animatedLines = []; | 17 this._animatedLines = []; |
| 19 } | 18 } |
| 20 | 19 |
| 21 /** @type {number} */ | 20 /** @type {number} */ |
| 22 WebInspector.SourceCodeDiff.UpdateTimeout = 200; | 21 WebInspector.SourceCodeDiff.UpdateTimeout = 200; |
| 23 | 22 |
| 24 /** @type {string} */ | 23 /** @type {string} */ |
| 25 WebInspector.SourceCodeDiff.DiffGutterType = "CodeMirror-gutter-diff"; | 24 WebInspector.SourceCodeDiff.DiffGutterType = "CodeMirror-gutter-diff"; |
| 26 | 25 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 hasAdded = false; | 185 hasAdded = false; |
| 187 hasRemoved = false; | 186 hasRemoved = false; |
| 188 } | 187 } |
| 189 }, | 188 }, |
| 190 | 189 |
| 191 /** | 190 /** |
| 192 * @param {?string} baseline | 191 * @param {?string} baseline |
| 193 */ | 192 */ |
| 194 _innerUpdate: function(baseline) | 193 _innerUpdate: function(baseline) |
| 195 { | 194 { |
| 196 var current = this._uiSourceCode.workingCopy(); | 195 var current = this._textEditor.text(); |
| 197 if (typeof current !== "string" || typeof baseline !== "string") { | 196 if (typeof baseline !== "string") { |
| 198 this._updateDecorations(this._decorations, [] /* added */); | 197 this._updateDecorations(this._decorations, [] /* added */); |
| 199 this._decorations = []; | 198 this._decorations = []; |
| 200 return; | 199 return; |
| 201 } | 200 } |
| 202 | 201 |
| 203 var diff = this._computeDiff(baseline, current); | 202 var diff = this._computeDiff(baseline, current); |
| 204 | 203 |
| 205 /** @type {!Map<number, !WebInspector.SourceCodeDiff.GutterDecoration>}
*/ | 204 /** @type {!Map<number, !WebInspector.SourceCodeDiff.GutterDecoration>}
*/ |
| 206 var oldDecorations = new Map(); | 205 var oldDecorations = new Map(); |
| 207 for (var i = 0; i < this._decorations.length; ++i) { | 206 for (var i = 0; i < this._decorations.length; ++i) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 279 |
| 281 remove: function() | 280 remove: function() |
| 282 { | 281 { |
| 283 var location = this._position.resolve(); | 282 var location = this._position.resolve(); |
| 284 if (!location) | 283 if (!location) |
| 285 return; | 284 return; |
| 286 this._textEditor.setGutterDecoration(location.lineNumber, WebInspector.S
ourceCodeDiff.DiffGutterType, null); | 285 this._textEditor.setGutterDecoration(location.lineNumber, WebInspector.S
ourceCodeDiff.DiffGutterType, null); |
| 287 this._textEditor.toggleLineClass(location.lineNumber, this._className, f
alse); | 286 this._textEditor.toggleLineClass(location.lineNumber, this._className, f
alse); |
| 288 } | 287 } |
| 289 } | 288 } |
| OLD | NEW |