Skip to content

Commit 17a016d

Browse files
committed
Merge pull request #99 from danvk/diff-fixes
PDiff fixes
2 parents 1094d41 + 88030d6 commit 17a016d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

webdiff/argparser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ def parse(args):
8080
# TODO: move into dirdiff?
8181
def _shim_for_file_diff(a_file, b_file):
8282
'''Sets A_DIR, B_DIR and DIFF to do a one-file diff.'''
83-
dirname = os.path.dirname
84-
basename = os.path.basename
85-
return LocalFileDiff(dirname(a_file), basename(a_file),
86-
dirname(b_file), basename(b_file),
83+
return LocalFileDiff(os.path.dirname(a_file), a_file,
84+
os.path.dirname(b_file), b_file,
8785
False) # probably not a move
8886

8987

webdiff/static/js/components.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ var makeRoot = function(filePairs, initiallySelectedIndex) {
5757
var idx = this.getIndex(),
5858
filePair = this.props.filePairs[idx];
5959

60-
if (this.state.pdiffMode == PDIFF_MODE.BBOX && !filePair.diffData) {
61-
// XXX this might shoot off unnecessary XHRs--use a Promise!
62-
this.computePerceptualDiffBox();
63-
}
64-
6560
return (
6661
<div>
6762
<FileSelector selectedFileIndex={idx}
@@ -251,6 +246,7 @@ var DiffView = React.createClass({
251246
},
252247
componentDidMount: function() {
253248
getThickDiff(this.props.thinFilePair.idx).done(filePair => {
249+
filePair.idx = this.props.thinFilePair.idx;
254250
this.setState({filePair});
255251
});
256252
},

webdiff/static/js/image.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,29 @@ var ImageDiff = React.createClass({
7070
componentWillUnmount: function() {
7171
$(window).off('resize.shrink-to-fit');
7272
},
73+
computePerceptualDiffBox: function(fp) {
74+
if (!isSameSizeImagePair(fp)) return;
75+
$.getJSON(`/pdiffbbox/${fp.idx}`)
76+
.done(bbox => {
77+
if (!fp.diffData) fp.diffData = {};
78+
fp.diffData.diffBounds = bbox;
79+
this.forceUpdate(); // tell react about this change
80+
}).fail(error => {
81+
console.error(error);
82+
});
83+
},
7384
render: function() {
7485
var mode = this.props.imageDiffMode;
7586
var pair = this.props.filePair;
7687
if (isOneSided(pair)) {
7788
mode = 'side-by-side'; // Only one that makes sense for one-sided diffs.
7889
}
90+
91+
if (this.props.pdiffMode == PDIFF_MODE.BBOX && !pair.diffData) {
92+
// XXX this might shoot off unnecessary XHRs--use a Promise!
93+
this.computePerceptualDiffBox(pair);
94+
}
95+
7996
var component = {
8097
'side-by-side': ImageSideBySide,
8198
'blink': ImageBlinker,

0 commit comments

Comments
 (0)