pbu88/diffy

Enable synchronisedScroll in side-by-side panes

Closed this issue · 4 comments

I'm trying to use synchronisedScroll from diff2html in /diff/:id with this patch:

--- src/app.js.orig     2017-03-06 09:20:59.672312000 -0500
+++ src/app.js  2017-03-06 09:23:19.211881000 -0500
@@ -67,16 +67,14 @@
         }
         var jsonDiff = row.diff;
         jsonDiff = jsonDiff.sort(utils.sortByFilenameCriteria);
-        var tree = new FileTree();
-        jsonDiff.forEach(function(e) {
-            tree.insert(utils.getFileName(e));
-        });
-        var html = tree.printTree(tree, 0);

+        var HtmlConfig = {};
+        HtmlConfig.matching = 'none';
+        HtmlConfig.showFiles = true;
+        HtmlConfig.synchronisedScroll = true;
         res.render('diff.html', {
             id: id,
-            diff: diff2html.Diff2Html.getPrettyHtmlFromJson(jsonDiff),
-            fileTreeHtml: html,
+            diff: diff2html.Diff2Html.getPrettySideBySideHtmlFromJson(jsonDiff, HtmlConfig),
             files: jsonDiff,
             dbObj: row
         });

because I'm mostly interested in a side-by-side diff.
Everything works (including showFiles) but synchronisedScroll.

Any hint?

Thanks in advance,
d.

pbu88 commented

Hmmm, I don't understand. Currently diffy only shows the patch in single diff mode, not side by side. How are you trying to do this?

pbu88 commented

Actually, not everything works for me. Files do show up but only one file will appear and you won't be able to switch files. As for the synchronized scroll I'm not sure what is not working. They both scroll at the same time.

You are trying to perform some changes that use diff2html features that are not compatible with diffy like for example the list of files on top. Would it be useful for you to just making a change to display side by side?

diff --git a/src/app.js b/src/app.js
index d1d252e..5648c65 100644
--- a/src/app.js
+++ b/src/app.js
@@ -75,6 +75,7 @@ app.get('/diff/:id', function (req, res) {
 
         res.render('diff.html', {
             id: id,
-            diff: diff2html.Diff2Html.getPrettyHtmlFromJson(jsonDiff),
+            diff: diff2html.Diff2Html.getPrettySideBySideHtmlFromJson(jsonDiff),
             fileTreeHtml: html,
             files: jsonDiff,
             dbObj: row

Thanks for your answer but that's exactly what I was trying to do. Maybe it was something related to the browser I was using but then I moved to diff2html-cli.