Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/source_frame/SourceCodeDiff.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/source_frame/SourceCodeDiff.js b/third_party/WebKit/Source/devtools/front_end/source_frame/SourceCodeDiff.js |
| index 788436890176a1c6587d40ed79f693fe001a13ea..b48342650a18d46ebab19ad8ff74cf5890cbddd6 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/source_frame/SourceCodeDiff.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/source_frame/SourceCodeDiff.js |
| @@ -6,30 +6,19 @@ |
| */ |
| SourceFrame.SourceCodeDiff = class { |
| /** |
| - * @param {!Promise<?string>} diffBaseline |
| + * @param {!Workspace.UISourceCode} uiSourceCode |
| * @param {!TextEditor.CodeMirrorTextEditor} textEditor |
| */ |
| - constructor(diffBaseline, textEditor) { |
| + constructor(uiSourceCode, textEditor) { |
| this._textEditor = textEditor; |
| this._decorations = []; |
| this._textEditor.installGutter(SourceFrame.SourceCodeDiff.DiffGutterType, true); |
| - this._diffBaseline = diffBaseline; |
| + this._uiSourceCode = uiSourceCode; |
| + WorkspaceDiff.workspaceDiff().subscribeToDiffChange(this._uiSourceCode, this._update, this); |
| /** @type {!Array<!TextEditor.TextEditorPositionHandle>}*/ |
| this._animatedLines = []; |
| - } |
| - |
| - updateDiffMarkersWhenPossible() { |
| - if (this._updateTimeout) |
| - clearTimeout(this._updateTimeout); |
| - this._updateTimeout = |
| - setTimeout(this.updateDiffMarkersImmediately.bind(this), SourceFrame.SourceCodeDiff.UpdateTimeout); |
| - } |
| - updateDiffMarkersImmediately() { |
| - if (this._updateTimeout) |
| - clearTimeout(this._updateTimeout); |
| - this._updateTimeout = null; |
| - this._diffBaseline.then(this._innerUpdate.bind(this)); |
| + this._update(); |
| } |
| /** |
| @@ -40,7 +29,7 @@ SourceFrame.SourceCodeDiff = class { |
| if (typeof oldContent !== 'string' || typeof newContent !== 'string') |
| return; |
| - var diff = this._computeDiff(oldContent, newContent); |
| + var diff = this._computeDiff(Diff.Diff.lineDiff(oldContent.split('\n'), newContent.split('\n'))); |
| var changedLines = []; |
| for (var i = 0; i < diff.length; ++i) { |
| var diffEntry = diff[i]; |
| @@ -104,12 +93,10 @@ SourceFrame.SourceCodeDiff = class { |
| } |
| /** |
| - * @param {string} baseline |
| - * @param {string} current |
| + * @param {!Diff.Diff.DiffArray} diff |
| * @return {!Array<!{type: !SourceFrame.SourceCodeDiff.GutterDecorationType, from: number, to: number}>} |
| */ |
| - _computeDiff(baseline, current) { |
| - var diff = Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n')); |
| + _computeDiff(diff) { |
| var result = []; |
| var hasAdded = false; |
| var hasRemoved = false; |
| @@ -165,19 +152,14 @@ SourceFrame.SourceCodeDiff = class { |
| } |
| } |
| + _update() { |
| + WorkspaceDiff.workspaceDiff().requestDiff(this._uiSourceCode).then(this._innerUpdate.bind(this)); |
|
lushnikov
2017/03/10 01:17:04
let's pass this from the outside
|
| + } |
| + |
| /** |
| - * @param {?string} baseline |
| + * @param {!Diff.Diff.DiffArray} lineDiff |
| */ |
| - _innerUpdate(baseline) { |
| - var current = this._textEditor.text(); |
| - if (typeof baseline !== 'string') { |
| - this._updateDecorations(this._decorations, [] /* added */); |
| - this._decorations = []; |
| - return; |
| - } |
| - |
| - var diff = this._computeDiff(baseline, current); |
| - |
| + _innerUpdate(lineDiff) { |
| /** @type {!Map<number, !SourceFrame.SourceCodeDiff.GutterDecoration>} */ |
| var oldDecorations = new Map(); |
| for (var i = 0; i < this._decorations.length; ++i) { |
| @@ -188,6 +170,8 @@ SourceFrame.SourceCodeDiff = class { |
| oldDecorations.set(lineNumber, decoration); |
| } |
| + var diff = this._computeDiff(lineDiff); |
| + |
| /** @type {!Map<number, !{lineNumber: number, type: !SourceFrame.SourceCodeDiff.GutterDecorationType}>} */ |
| var newDecorations = new Map(); |
| for (var i = 0; i < diff.length; ++i) { |
| @@ -210,10 +194,11 @@ SourceFrame.SourceCodeDiff = class { |
| */ |
| _decorationsSetForTest(decorations) { |
| } |
| -}; |
| -/** @type {number} */ |
| -SourceFrame.SourceCodeDiff.UpdateTimeout = 200; |
| + dispose() { |
| + WorkspaceDiff.workspaceDiff().unsubscribeToDiffChange(this._uiSourceCode, this._update, this); |
| + } |
| +}; |
| /** @type {string} */ |
| SourceFrame.SourceCodeDiff.DiffGutterType = 'CodeMirror-gutter-diff'; |