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

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: doc 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 /**
25 * @param {?Workspace.UISourceCode} uiSourceCode
26 */
27 setUISourceCode(uiSourceCode) {
28 if (uiSourceCode === this._uiSourceCode)
29 return;
30 if (this._uiSourceCode)
31 this._workspaceDiff.unsubscribeFromDiffChange(this._uiSourceCode, this._up date, this);
32 if (uiSourceCode)
33 this._workspaceDiff.subscribeToDiffChange(uiSourceCode, this._update, this );
34 this._uiSourceCode = uiSourceCode;
35 this._update();
36 }
37
26 /** 38 /**
27 * @param {?string} oldContent 39 * @param {?string} oldContent
28 * @param {?string} newContent 40 * @param {?string} newContent
29 */ 41 */
30 highlightModifiedLines(oldContent, newContent) { 42 highlightModifiedLines(oldContent, newContent) {
31 if (typeof oldContent !== 'string' || typeof newContent !== 'string') 43 if (typeof oldContent !== 'string' || typeof newContent !== 'string')
32 return; 44 return;
33 45
34 var diff = this._computeDiff(Diff.Diff.lineDiff(oldContent.split('\n'), newC ontent.split('\n'))); 46 var diff = this._computeDiff(Diff.Diff.lineDiff(oldContent.split('\n'), newC ontent.split('\n')));
35 var changedLines = []; 47 var changedLines = [];
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 from -= 1; 160 from -= 1;
149 } 161 }
150 result.push({type: type, from: from, to: to}); 162 result.push({type: type, from: from, to: to});
151 isInsideBlock = false; 163 isInsideBlock = false;
152 hasAdded = false; 164 hasAdded = false;
153 hasRemoved = false; 165 hasRemoved = false;
154 } 166 }
155 } 167 }
156 168
157 _update() { 169 _update() {
158 this._workspaceDiff.requestDiff(this._uiSourceCode).then(this._innerUpdate.b ind(this)); 170 if (this._uiSourceCode)
171 this._workspaceDiff.requestDiff(this._uiSourceCode).then(this._innerUpdate .bind(this));
172 else
173 this._innerUpdate(null);
159 } 174 }
160 175
161 /** 176 /**
162 * @param {?Diff.Diff.DiffArray} lineDiff 177 * @param {?Diff.Diff.DiffArray} lineDiff
163 */ 178 */
164 _innerUpdate(lineDiff) { 179 _innerUpdate(lineDiff) {
165 if (!lineDiff) 180 if (!lineDiff) {
181 this._updateDecorations(this._decorations, []);
182 this._decorations = [];
166 return; 183 return;
184 }
167 185
168 /** @type {!Map<number, !SourceFrame.SourceCodeDiff.GutterDecoration>} */ 186 /** @type {!Map<number, !SourceFrame.SourceCodeDiff.GutterDecoration>} */
169 var oldDecorations = new Map(); 187 var oldDecorations = new Map();
170 for (var i = 0; i < this._decorations.length; ++i) { 188 for (var i = 0; i < this._decorations.length; ++i) {
171 var decoration = this._decorations[i]; 189 var decoration = this._decorations[i];
172 var lineNumber = decoration.lineNumber(); 190 var lineNumber = decoration.lineNumber();
173 if (lineNumber === -1) 191 if (lineNumber === -1)
174 continue; 192 continue;
175 oldDecorations.set(lineNumber, decoration); 193 oldDecorations.set(lineNumber, decoration);
176 } 194 }
(...skipping 17 matching lines...) Expand all
194 this._decorationsSetForTest(newDecorations); 212 this._decorationsSetForTest(newDecorations);
195 } 213 }
196 214
197 /** 215 /**
198 * @param {!Map<number, !{lineNumber: number, type: !SourceFrame.SourceCodeDif f.GutterDecorationType}>} decorations 216 * @param {!Map<number, !{lineNumber: number, type: !SourceFrame.SourceCodeDif f.GutterDecorationType}>} decorations
199 */ 217 */
200 _decorationsSetForTest(decorations) { 218 _decorationsSetForTest(decorations) {
201 } 219 }
202 220
203 dispose() { 221 dispose() {
204 WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this._uiSourceCode, this._update, this); 222 if (this._uiSourceCode)
223 WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this._uiSourceCode , this._update, this);
205 } 224 }
206 }; 225 };
207 226
208 /** @type {string} */ 227 /** @type {string} */
209 SourceFrame.SourceCodeDiff.DiffGutterType = 'CodeMirror-gutter-diff'; 228 SourceFrame.SourceCodeDiff.DiffGutterType = 'CodeMirror-gutter-diff';
210 229
211 /** @enum {symbol} */ 230 /** @enum {symbol} */
212 SourceFrame.SourceCodeDiff.GutterDecorationType = { 231 SourceFrame.SourceCodeDiff.GutterDecorationType = {
213 Insert: Symbol('Insert'), 232 Insert: Symbol('Insert'),
214 Delete: Symbol('Delete'), 233 Delete: Symbol('Delete'),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 277 }
259 278
260 remove() { 279 remove() {
261 var location = this._position.resolve(); 280 var location = this._position.resolve();
262 if (!location) 281 if (!location)
263 return; 282 return;
264 this._textEditor.setGutterDecoration(location.lineNumber, SourceFrame.Source CodeDiff.DiffGutterType, null); 283 this._textEditor.setGutterDecoration(location.lineNumber, SourceFrame.Source CodeDiff.DiffGutterType, null);
265 this._textEditor.toggleLineClass(location.lineNumber, this._className, false ); 284 this._textEditor.toggleLineClass(location.lineNumber, this._className, false );
266 } 285 }
267 }; 286 };
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