Skip to content

Commit 90c9d08

Browse files
committed
Add synchronised horizontal scroll
1 parent dbd8766 commit 90c9d08

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ The HTML output accepts a Javascript object with configuration. Possible options
7070
- `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'`
7171
- `showFiles`: show a file list before the diff: `true` or `false`, default is `false`
7272
- `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none`
73+
- `synchronisedScroll`: scroll both panes in side-by-side mode: `true` or `false`, default is `false`
7374
- `matchWordsThreshold`: similarity threshold for word matching, default is 0.25
7475
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`
7576

bower.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
"url": "git://github.com/rtfpessoa/diff2html.git"
2929
},
3030
"main": [
31-
"./dist/diff2html-templates.js",
3231
"./dist/diff2html.js",
33-
"./dist/diff2html-ui.js",
3432
"./dist/diff2html.css"
3533
],
3634
"license": "MIT",

sample/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@
267267
inputFormat: 'json',
268268
showFiles: true,
269269
matching: 'lines',
270-
outputFormat: 'side-by-side'
270+
outputFormat: 'side-by-side',
271+
synchronisedScroll: true
271272
});
272273
diff2htmlUi.fileListCloseable('#side-by-side', false);
273274
diff2htmlUi.highlightCode('#side-by-side');

src/ui/js/diff2html-ui.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,22 @@
3434
var cfg = config || {};
3535
var $target = this._getTarget(targetId);
3636
$target.html(Diff2Html.getPrettyHtml(diffJson, cfg));
37+
38+
synchronisedScroll($target, config);
3739
};
3840

41+
function synchronisedScroll($target, config) {
42+
if (config.synchronisedScroll) {
43+
44+
$target.find(".d2h-file-side-diff").scroll(function() {
45+
var $this = $(this);
46+
$this.closest(".d2h-file-wrapper").find(".d2h-file-side-diff")
47+
.scrollLeft($this.scrollLeft());
48+
});
49+
50+
}
51+
}
52+
3953
Diff2HtmlUI.prototype.fileListCloseable = function(targetId, startVisible) {
4054
var $target = this._getTarget(targetId);
4155

0 commit comments

Comments
 (0)