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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/diff/Diff.js
diff --git a/third_party/WebKit/Source/devtools/front_end/diff/Diff.js b/third_party/WebKit/Source/devtools/front_end/diff/Diff.js
index 9b844ad8b435192c4b3f78e686c85cf416e10328..13fc91d1d158fd6ff2df04404b43fce479fd74b3 100644
--- a/third_party/WebKit/Source/devtools/front_end/diff/Diff.js
+++ b/third_party/WebKit/Source/devtools/front_end/diff/Diff.js
@@ -47,10 +47,53 @@ WebInspector.Diff = {
return text;
}
},
+
+ /**
+ * @param {!Array.<!{0: number, 1: string}>} diff
+ * @return {!Array<!Array<number>>}
+ */
+ convertToEditDiff: function(diff)
+ {
+ var normalized = [];
+ var added = 0;
+ var removed = 0;
+ for (var i = 0; i < diff.length; ++i) {
+ var token = diff[i];
+ if (token[0] === WebInspector.Diff.Operation.Equal) {
+ flush();
+ normalized.push([WebInspector.Diff.Operation.Equal, token[1].length]);
+ } else if (token[0] === WebInspector.Diff.Operation.Delete) {
+ removed += token[1].length;
+ } else {
+ added += token[1].length;
+ }
+ }
+ flush();
+ return normalized;
+
+ function flush()
+ {
+ if (added && removed) {
+ var min = Math.min(added, removed);
+ normalized.push([WebInspector.Diff.Operation.Edit, min]);
+ added -= min;
+ removed -= min;
+ }
+ if (added || removed) {
+ var balance = added - removed;
+ var type = balance < 0 ? WebInspector.Diff.Operation.Delete : WebInspector.Diff.Operation.Insert;
+ normalized.push([type, Math.abs(balance)]);
+ added = 0;
+ removed = 0;
+ }
+ }
+ }
+
}
WebInspector.Diff.Operation = {
Equal: 0,
Insert: 1,
- Delete: -1
+ Delete: -1,
+ Edit: 2
}

Powered by Google App Engine
This is Rietveld 408576698