Skip to content

Commit c51352f

Browse files
committed
Only use side-by-side for one-sided image diffs (fixes #56)
1 parent 81ef997 commit c51352f

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

testdata/images/left/delete.png

9.9 KB
Loading

testdata/images/right/add.png

9.3 KB
Loading

webdiff/static/js/components.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ var ImageDiffModeSelector = React.createClass({
203203
changeHandler: React.PropTypes.func.isRequired
204204
},
205205
render: function() {
206+
if (isOneSided(this.props.filePair)) {
207+
return null; // Only "side-by-side" makes sense for one-sided diffs.
208+
}
209+
206210
// Returns the text, optionally wrapped in a link and/or <b> tag.
207211
var linkOrB = (isLink, isB, val, text) => {
208212
var inner = isB ? <b>{text}</b> : text;
@@ -306,6 +310,9 @@ var ImageDiff = React.createClass({
306310
},
307311
render: function() {
308312
var mode = this.props.imageDiffMode;
313+
if (isOneSided(this.props.filePair)) {
314+
mode = 'side-by-side'; // Only one that makes sense for one-sided diffs.
315+
}
309316
var component = {
310317
'side-by-side': ImageSideBySide,
311318
'blink': ImageBlinker,

webdiff/static/js/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ function filePairDisplayName(filePair) {
3939

4040
return out;
4141
}
42+
43+
44+
/**
45+
* Checks whether the diff is one-sided, i.e. an add or delete.
46+
*/
47+
function isOneSided(filePair) {
48+
return (filePair.type == 'add' || filePair.type == 'delete');
49+
}

0 commit comments

Comments
 (0)