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 1bf24458ab9f3e865ceb7755df6ee1458ebf5222..27fa0fbf3a6f5989abdde2e8df592fae26ff9190 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 |
| @@ -7,19 +7,28 @@ |
| SourceFrame.SourceCodeDiff = class { |
| /** |
| * @param {!WorkspaceDiff.WorkspaceDiff} workspaceDiff |
| - * @param {!Workspace.UISourceCode} uiSourceCode |
| * @param {!TextEditor.CodeMirrorTextEditor} textEditor |
| */ |
| - constructor(workspaceDiff, uiSourceCode, textEditor) { |
| + constructor(workspaceDiff, textEditor) { |
| this._textEditor = textEditor; |
| this._decorations = []; |
| this._textEditor.installGutter(SourceFrame.SourceCodeDiff.DiffGutterType, true); |
| - this._uiSourceCode = uiSourceCode; |
| + this._uiSourceCode = null; |
| this._workspaceDiff = workspaceDiff; |
| /** @type {!Array<!TextEditor.TextEditorPositionHandle>}*/ |
| this._animatedLines = []; |
| - this._workspaceDiff.subscribeToDiffChange(this._uiSourceCode, this._update, this); |
| + this._update(); |
| + } |
| + |
| + setUISourceCode(uiSourceCode) { |
|
lushnikov
2017/03/20 16:49:11
let's add jsdoc
einbinder
2017/03/20 22:38:22
Done.
|
| + if (uiSourceCode === this._uiSourceCode) |
| + return; |
| + if (this._uiSourceCode) |
| + this._workspaceDiff.unsubscribeFromDiffChange(this._uiSourceCode, this._update, this); |
| + if (uiSourceCode) |
| + this._workspaceDiff.subscribeToDiffChange(uiSourceCode, this._update, this); |
| + this._uiSourceCode = uiSourceCode; |
| this._update(); |
| } |
| @@ -155,15 +164,21 @@ SourceFrame.SourceCodeDiff = class { |
| } |
| _update() { |
| - this._workspaceDiff.requestDiff(this._uiSourceCode).then(this._innerUpdate.bind(this)); |
| + if (this._uiSourceCode) |
| + this._workspaceDiff.requestDiff(this._uiSourceCode).then(this._innerUpdate.bind(this)); |
| + else |
| + this._innerUpdate(null); |
| } |
| /** |
| * @param {?Diff.Diff.DiffArray} lineDiff |
| */ |
| _innerUpdate(lineDiff) { |
| - if (!lineDiff) |
| + if (!lineDiff) { |
| + this._updateDecorations(this._decorations, []); |
| + this._decorations = []; |
| return; |
| + } |
| /** @type {!Map<number, !SourceFrame.SourceCodeDiff.GutterDecoration>} */ |
| var oldDecorations = new Map(); |
| @@ -201,7 +216,8 @@ SourceFrame.SourceCodeDiff = class { |
| } |
| dispose() { |
| - WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this._uiSourceCode, this._update, this); |
| + if (this._uiSourceCode) |
| + WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this._uiSourceCode, this._update, this); |
| } |
| }; |