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

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

Issue 1504923008: DevTools: [SASS] implement AST differ. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sass-module-2
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 WebInspector.Diff = { 5 WebInspector.Diff = {
6 /** 6 /**
7 * @param {string} text1 7 * @param {string} text1
8 * @param {string} text2 8 * @param {string} text2
9 * @return {!Array.<!{0: number, 1: string}>} 9 * @return {!Array.<!{0: number, 1: string}>}
10 */ 10 */
(...skipping 29 matching lines...) Expand all
40 var character = lineToChar.get(line); 40 var character = lineToChar.get(line);
41 if (!character) { 41 if (!character) {
42 character = String.fromCharCode(charCode++); 42 character = String.fromCharCode(charCode++);
43 lineToChar.set(line, character); 43 lineToChar.set(line, character);
44 } 44 }
45 text += character; 45 text += character;
46 } 46 }
47 return text; 47 return text;
48 } 48 }
49 }, 49 },
50
51 /**
52 * @param {!Array.<!{0: number, 1: string}>} diff
53 * @return {!Array<!Array<number>>}
54 */
55 convertToEditDiff: function(diff)
56 {
57 var normalized = [];
58 var added = 0;
59 var removed = 0;
60 for (var i = 0; i < diff.length; ++i) {
61 var token = diff[i];
62 if (token[0] === WebInspector.Diff.Operation.Equal) {
63 flush();
64 normalized.push([WebInspector.Diff.Operation.Equal, token[1].len gth]);
65 } else if (token[0] === WebInspector.Diff.Operation.Delete) {
66 removed += token[1].length;
67 } else {
68 added += token[1].length;
69 }
70 }
71 flush();
72 return normalized;
73
74 function flush()
75 {
76 if (added && removed) {
77 var min = Math.min(added, removed);
78 normalized.push([WebInspector.Diff.Operation.Edit, min]);
79 added -= min;
80 removed -= min;
81 }
82 if (added || removed) {
83 var balance = added - removed;
84 var type = balance < 0 ? WebInspector.Diff.Operation.Delete : We bInspector.Diff.Operation.Insert;
85 normalized.push([type, Math.abs(balance)]);
86 added = 0;
87 removed = 0;
88 }
89 }
90 }
91
50 } 92 }
51 93
52 WebInspector.Diff.Operation = { 94 WebInspector.Diff.Operation = {
53 Equal: 0, 95 Equal: 0,
54 Insert: 1, 96 Insert: 1,
55 Delete: -1 97 Delete: -1,
98 Edit: 2
56 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698