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

Unified Diff: Source/devtools/front_end/diff/Diff.js

Issue 1336803005: DevTools: use diff_match_patch instead of jsdifflib for text diffing. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix file permissions Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/diff/diff_match_patch.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/diff/Diff.js
diff --git a/Source/devtools/front_end/diff/Diff.js b/Source/devtools/front_end/diff/Diff.js
new file mode 100644
index 0000000000000000000000000000000000000000..9b844ad8b435192c4b3f78e686c85cf416e10328
--- /dev/null
+++ b/Source/devtools/front_end/diff/Diff.js
@@ -0,0 +1,56 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+WebInspector.Diff = {
+ /**
+ * @param {string} text1
+ * @param {string} text2
+ * @return {!Array.<!{0: number, 1: string}>}
+ */
+ charDiff: function(text1, text2)
+ {
+ var differ = new diff_match_patch();
+ return differ.diff_main(text1, text2);
+ },
+
+ /**
+ * @param {!Array.<string>} lines1
+ * @param {!Array.<string>} lines2
+ * @return {!Array.<!{0: number, 1: string}>}
+ */
+ lineDiff: function(lines1, lines2)
+ {
+ var lineToChar = new Map();
+ var charCode = 33;
+ var text1 = encode(lines1);
+ var text2 = encode(lines2);
+
+ return WebInspector.Diff.charDiff(text1, text2);
+
+ /**
+ * @param {!Array.<string>} lines
+ * @return {string}
+ */
+ function encode(lines)
+ {
+ var text = "";
+ for (var i = 0; i < lines.length; ++i) {
+ var line = lines[i];
+ var character = lineToChar.get(line);
+ if (!character) {
+ character = String.fromCharCode(charCode++);
+ lineToChar.set(line, character);
+ }
+ text += character;
+ }
+ return text;
+ }
+ },
+}
+
+WebInspector.Diff.Operation = {
+ Equal: 0,
+ Insert: 1,
+ Delete: -1
+}
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/diff/diff_match_patch.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698