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 {!Promise<?string>} diffBaseline | 7 * @param {!Promise<?string>} diffBaseline |
8 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 8 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
9 */ | 9 */ |
10 WebInspector.SourceCodeDiff = function(diffBaseline, textEditor) | 10 WebInspector.SourceCodeDiff = function(diffBaseline, textEditor) |
11 { | 11 { |
12 this._textEditor = textEditor; | 12 this._textEditor = textEditor; |
13 this._decorations = []; | 13 this._decorations = []; |
14 this._textEditor.installGutter(WebInspector.SourceCodeDiff.DiffGutterType, t
rue); | 14 this._textEditor.installGutter(WebInspector.SourceCodeDiff.DiffGutterType, t
rue); |
15 this._diffBaseline = diffBaseline; | 15 this._diffBaseline = diffBaseline; |
16 /** @type {!Array<!WebInspector.TextEditorPositionHandle>}*/ | 16 /** @type {!Array<!WebInspector.TextEditorPositionHandle>}*/ |
17 this._animatedLines = []; | 17 this._animatedLines = []; |
18 } | 18 }; |
19 | 19 |
20 /** @type {number} */ | 20 /** @type {number} */ |
21 WebInspector.SourceCodeDiff.UpdateTimeout = 200; | 21 WebInspector.SourceCodeDiff.UpdateTimeout = 200; |
22 | 22 |
23 /** @type {string} */ | 23 /** @type {string} */ |
24 WebInspector.SourceCodeDiff.DiffGutterType = "CodeMirror-gutter-diff"; | 24 WebInspector.SourceCodeDiff.DiffGutterType = "CodeMirror-gutter-diff"; |
25 | 25 |
26 WebInspector.SourceCodeDiff.prototype = { | 26 WebInspector.SourceCodeDiff.prototype = { |
27 updateDiffMarkersWhenPossible: function() | 27 updateDiffMarkersWhenPossible: function() |
28 { | 28 { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 this._decorations = decorationDiff.equal.concat(addedDecorations); | 225 this._decorations = decorationDiff.equal.concat(addedDecorations); |
226 this._updateDecorations(decorationDiff.removed, addedDecorations); | 226 this._updateDecorations(decorationDiff.removed, addedDecorations); |
227 this._decorationsSetForTest(newDecorations); | 227 this._decorationsSetForTest(newDecorations); |
228 }, | 228 }, |
229 | 229 |
230 /** | 230 /** |
231 * @param {!Map<number, !{lineNumber: number, type: !WebInspector.SourceCode
Diff.GutterDecorationType}>} decorations | 231 * @param {!Map<number, !{lineNumber: number, type: !WebInspector.SourceCode
Diff.GutterDecorationType}>} decorations |
232 */ | 232 */ |
233 _decorationsSetForTest: function(decorations) { } | 233 _decorationsSetForTest: function(decorations) { } |
234 } | 234 }; |
235 | 235 |
236 /** @enum {symbol} */ | 236 /** @enum {symbol} */ |
237 WebInspector.SourceCodeDiff.GutterDecorationType = { | 237 WebInspector.SourceCodeDiff.GutterDecorationType = { |
238 Insert: Symbol("Insert"), | 238 Insert: Symbol("Insert"), |
239 Delete: Symbol("Delete"), | 239 Delete: Symbol("Delete"), |
240 Modify: Symbol("Modify"), | 240 Modify: Symbol("Modify"), |
241 } | 241 }; |
242 | 242 |
243 /** | 243 /** |
244 * @constructor | 244 * @constructor |
245 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 245 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
246 * @param {number} lineNumber | 246 * @param {number} lineNumber |
247 * @param {!WebInspector.SourceCodeDiff.GutterDecorationType} type | 247 * @param {!WebInspector.SourceCodeDiff.GutterDecorationType} type |
248 */ | 248 */ |
249 WebInspector.SourceCodeDiff.GutterDecoration = function(textEditor, lineNumber,
type) | 249 WebInspector.SourceCodeDiff.GutterDecoration = function(textEditor, lineNumber,
type) |
250 { | 250 { |
251 this._textEditor = textEditor; | 251 this._textEditor = textEditor; |
252 this._position = this._textEditor.textEditorPositionHandle(lineNumber, 0); | 252 this._position = this._textEditor.textEditorPositionHandle(lineNumber, 0); |
253 this._className = ""; | 253 this._className = ""; |
254 if (type === WebInspector.SourceCodeDiff.GutterDecorationType.Insert) | 254 if (type === WebInspector.SourceCodeDiff.GutterDecorationType.Insert) |
255 this._className = "diff-entry-insert"; | 255 this._className = "diff-entry-insert"; |
256 else if (type === WebInspector.SourceCodeDiff.GutterDecorationType.Delete) | 256 else if (type === WebInspector.SourceCodeDiff.GutterDecorationType.Delete) |
257 this._className = "diff-entry-delete"; | 257 this._className = "diff-entry-delete"; |
258 else if (type === WebInspector.SourceCodeDiff.GutterDecorationType.Modify) | 258 else if (type === WebInspector.SourceCodeDiff.GutterDecorationType.Modify) |
259 this._className = "diff-entry-modify"; | 259 this._className = "diff-entry-modify"; |
260 this.type = type; | 260 this.type = type; |
261 } | 261 }; |
262 | 262 |
263 WebInspector.SourceCodeDiff.GutterDecoration.prototype = { | 263 WebInspector.SourceCodeDiff.GutterDecoration.prototype = { |
264 /** | 264 /** |
265 * @return {number} | 265 * @return {number} |
266 */ | 266 */ |
267 lineNumber: function() | 267 lineNumber: function() |
268 { | 268 { |
269 var location = this._position.resolve(); | 269 var location = this._position.resolve(); |
270 if (!location) | 270 if (!location) |
271 return -1; | 271 return -1; |
(...skipping 12 matching lines...) Expand all Loading... |
284 }, | 284 }, |
285 | 285 |
286 remove: function() | 286 remove: function() |
287 { | 287 { |
288 var location = this._position.resolve(); | 288 var location = this._position.resolve(); |
289 if (!location) | 289 if (!location) |
290 return; | 290 return; |
291 this._textEditor.setGutterDecoration(location.lineNumber, WebInspector.S
ourceCodeDiff.DiffGutterType, null); | 291 this._textEditor.setGutterDecoration(location.lineNumber, WebInspector.S
ourceCodeDiff.DiffGutterType, null); |
292 this._textEditor.toggleLineClass(location.lineNumber, this._className, f
alse); | 292 this._textEditor.toggleLineClass(location.lineNumber, this._className, f
alse); |
293 } | 293 } |
294 } | 294 }; |
OLD | NEW |