Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/source_frame/SourceCodeDiff.js

Issue 2762443002: DevTools: Only show gutter diff for Network UISourceCodes (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/source_frame/UISourceCodeFrame.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 SourceFrame.SourceCodeDiff = class { 7 SourceFrame.SourceCodeDiff = class {
8 /** 8 /**
9 * @param {!WorkspaceDiff.WorkspaceDiff} workspaceDiff 9 * @param {!WorkspaceDiff.WorkspaceDiff} workspaceDiff
10 * @param {!Workspace.UISourceCode} uiSourceCode
11 * @param {!TextEditor.CodeMirrorTextEditor} textEditor 10 * @param {!TextEditor.CodeMirrorTextEditor} textEditor
12 */ 11 */
13 constructor(workspaceDiff, uiSourceCode, textEditor) { 12 constructor(workspaceDiff, textEditor) {
14 this._textEditor = textEditor; 13 this._textEditor = textEditor;
15 this._decorations = []; 14 this._decorations = [];
16 this._textEditor.installGutter(SourceFrame.SourceCodeDiff.DiffGutterType, tr ue); 15 this._textEditor.installGutter(SourceFrame.SourceCodeDiff.DiffGutterType, tr ue);
17 this._uiSourceCode = uiSourceCode; 16 this._uiSourceCode = null;
18 this._workspaceDiff = workspaceDiff; 17 this._workspaceDiff = workspaceDiff;
19 /** @type {!Array<!TextEditor.TextEditorPositionHandle>}*/ 18 /** @type {!Array<!TextEditor.TextEditorPositionHandle>}*/
20 this._animatedLines = []; 19 this._animatedLines = [];
21 20
22 this._workspaceDiff.subscribeToDiffChange(this._uiSourceCode, this._update, this);
23 this._update(); 21 this._update();
24 } 22 }
25 23
24 setUISourceCode(uiSourceCode) {
lushnikov 2017/03/20 16:49:11 let's add jsdoc
einbinder 2017/03/20 22:38:22 Done.
25 if (uiSourceCode === this._uiSourceCode)
26 return;
27 if (this._uiSourceCode)
28 this._workspaceDiff.unsubscribeFromDiffChange(this._uiSourceCode, this._up date, this);
29 if (uiSourceCode)
30 this._workspaceDiff.subscribeToDiffChange(uiSourceCode, this._update, this );
31 this._uiSourceCode = uiSourceCode;
32 this._update();
33 }
34
26 /** 35 /**
27 * @param {?string} oldContent 36 * @param {?string} oldContent
28 * @param {?string} newContent 37 * @param {?string} newContent
29 */ 38 */
30 highlightModifiedLines(oldContent, newContent) { 39 highlightModifiedLines(oldContent, newContent) {
31 if (typeof oldContent !== 'string' || typeof newContent !== 'string') 40 if (typeof oldContent !== 'string' || typeof newContent !== 'string')
32 return; 41 return;
33 42
34 var diff = this._computeDiff(Diff.Diff.lineDiff(oldContent.split('\n'), newC ontent.split('\n'))); 43 var diff = this._computeDiff(Diff.Diff.lineDiff(oldContent.split('\n'), newC ontent.split('\n')));
35 var changedLines = []; 44 var changedLines = [];
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 from -= 1; 157 from -= 1;
149 } 158 }
150 result.push({type: type, from: from, to: to}); 159 result.push({type: type, from: from, to: to});
151 isInsideBlock = false; 160 isInsideBlock = false;
152 hasAdded = false; 161 hasAdded = false;
153 hasRemoved = false; 162 hasRemoved = false;
154 } 163 }
155 } 164 }
156 165
157 _update() { 166 _update() {
158 this._workspaceDiff.requestDiff(this._uiSourceCode).then(this._innerUpdate.b ind(this)); 167 if (this._uiSourceCode)
168 this._workspaceDiff.requestDiff(this._uiSourceCode).then(this._innerUpdate .bind(this));
169 else
170 this._innerUpdate(null);
159 } 171 }
160 172
161 /** 173 /**
162 * @param {?Diff.Diff.DiffArray} lineDiff 174 * @param {?Diff.Diff.DiffArray} lineDiff
163 */ 175 */
164 _innerUpdate(lineDiff) { 176 _innerUpdate(lineDiff) {
165 if (!lineDiff) 177 if (!lineDiff) {
178 this._updateDecorations(this._decorations, []);
179 this._decorations = [];
166 return; 180 return;
181 }
167 182
168 /** @type {!Map<number, !SourceFrame.SourceCodeDiff.GutterDecoration>} */ 183 /** @type {!Map<number, !SourceFrame.SourceCodeDiff.GutterDecoration>} */
169 var oldDecorations = new Map(); 184 var oldDecorations = new Map();
170 for (var i = 0; i < this._decorations.length; ++i) { 185 for (var i = 0; i < this._decorations.length; ++i) {
171 var decoration = this._decorations[i]; 186 var decoration = this._decorations[i];
172 var lineNumber = decoration.lineNumber(); 187 var lineNumber = decoration.lineNumber();
173 if (lineNumber === -1) 188 if (lineNumber === -1)
174 continue; 189 continue;
175 oldDecorations.set(lineNumber, decoration); 190 oldDecorations.set(lineNumber, decoration);
176 } 191 }
(...skipping 17 matching lines...) Expand all
194 this._decorationsSetForTest(newDecorations); 209 this._decorationsSetForTest(newDecorations);
195 } 210 }
196 211
197 /** 212 /**
198 * @param {!Map<number, !{lineNumber: number, type: !SourceFrame.SourceCodeDif f.GutterDecorationType}>} decorations 213 * @param {!Map<number, !{lineNumber: number, type: !SourceFrame.SourceCodeDif f.GutterDecorationType}>} decorations
199 */ 214 */
200 _decorationsSetForTest(decorations) { 215 _decorationsSetForTest(decorations) {
201 } 216 }
202 217
203 dispose() { 218 dispose() {
204 WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this._uiSourceCode, this._update, this); 219 if (this._uiSourceCode)
220 WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this._uiSourceCode , this._update, this);
205 } 221 }
206 }; 222 };
207 223
208 /** @type {string} */ 224 /** @type {string} */
209 SourceFrame.SourceCodeDiff.DiffGutterType = 'CodeMirror-gutter-diff'; 225 SourceFrame.SourceCodeDiff.DiffGutterType = 'CodeMirror-gutter-diff';
210 226
211 /** @enum {symbol} */ 227 /** @enum {symbol} */
212 SourceFrame.SourceCodeDiff.GutterDecorationType = { 228 SourceFrame.SourceCodeDiff.GutterDecorationType = {
213 Insert: Symbol('Insert'), 229 Insert: Symbol('Insert'),
214 Delete: Symbol('Delete'), 230 Delete: Symbol('Delete'),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 274 }
259 275
260 remove() { 276 remove() {
261 var location = this._position.resolve(); 277 var location = this._position.resolve();
262 if (!location) 278 if (!location)
263 return; 279 return;
264 this._textEditor.setGutterDecoration(location.lineNumber, SourceFrame.Source CodeDiff.DiffGutterType, null); 280 this._textEditor.setGutterDecoration(location.lineNumber, SourceFrame.Source CodeDiff.DiffGutterType, null);
265 this._textEditor.toggleLineClass(location.lineNumber, this._className, false ); 281 this._textEditor.toggleLineClass(location.lineNumber, this._className, false );
266 } 282 }
267 }; 283 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/source_frame/UISourceCodeFrame.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698