Skip to content

Commit ed9b0e2

Browse files
author
Justin Martin
committed
make sure both input views are bound and scroll together.
1 parent b6aa6b8 commit ed9b0e2

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

js/main.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@
175175
var rightInputView = new JsonInputView(document.getElementById('json-diff-right'));
176176
leftInputView.on('change', compareJson);
177177
rightInputView.on('change', compareJson);
178-
leftInputView.on('scroll', function () {
179-
178+
leftInputView.codemirror.on('scroll', function () {
179+
var scrollInfo = leftInputView.codemirror.getScrollInfo();
180+
rightInputView.codemirror.scrollTo(scrollInfo.left, scrollInfo.top);
180181
});
181-
rightInputView.on('scroll', function () {
182-
182+
rightInputView.codemirror.on('scroll', function () {
183+
var scrollInfo = rightInputView.codemirror.getScrollInfo();
184+
leftInputView.codemirror.scrollTo(scrollInfo.left, scrollInfo.top);
183185
});
184186

185187
function compareJson() {

tests.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
{
2+
"data": [{
3+
"type": "articles",
4+
"id": "1",
5+
"attributes": {
6+
"title": "JSON API paints my bikeshed!",
7+
"body": "The shortest article. Ever.",
8+
"created": "2015-05-22T14:56:29.000Z",
9+
"updated": "2015-05-22T14:56:28.000Z"
10+
},
11+
"relationships": {
12+
"author": {
13+
"data": {"id": "42", "type": "people"}
14+
}
15+
}
16+
}],
17+
"included": [
18+
{
19+
"type": "people",
20+
"id": "42",
21+
"attributes": {
22+
"name": "John",
23+
"age": 80,
24+
"gender": "male"
25+
}
26+
}
27+
]
28+
}
29+
30+
131
{
232
"glossary": {
333
"title": "example glossary",

0 commit comments

Comments
 (0)