Skip to content

Commit 0fb0371

Browse files
committed
Fixed diff updates...
1 parent 145bbef commit 0fb0371

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

diff-area.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ var DiffArea = React.createClass({
4040
var newState = {};
4141

4242
// Text changed ?
43-
var contentChanged = this.state.rightState.getCurrentContent() !== rightState.getCurrentContent();
43+
var contentChanged = this.state.rightState.getCurrentContent()
44+
!== rightState.getCurrentContent();
4445

4546
// Update diffs
4647
if (contentChanged) {
47-
var right = rightState.getCurrentContent().getPlainText();
4848
var left = this.props.left;
49+
var right = rightState.getCurrentContent().getPlainText();
4950

5051
var diffs = computeDiff(left, right);
5152

@@ -58,6 +59,7 @@ var DiffArea = React.createClass({
5859
});
5960
} else {
6061
// Just update the EditorState
62+
newState.leftState = this.state.leftState;
6163
newState.rightState = rightState;
6264
}
6365

@@ -68,8 +70,8 @@ var DiffArea = React.createClass({
6870
return <div className='diffarea'>
6971
<div className='left'>
7072
<Draft.Editor
71-
readOnly={true}
7273
editorState={this.state.leftState}
74+
readOnly={true}
7375
/>
7476
</div>
7577
<div className='right'>
@@ -96,14 +98,8 @@ function editorStateFromText(text, decorator) {
9698
return Draft.EditorState.createWithContent(content, decorator);
9799
}
98100

99-
// Check for changes
100-
function contentStateHasChanged(oldEditorState, newEditorState) {
101-
return (!oldEditorState || !newEditorState)
102-
|| oldEditorState.getCurrentContent() !== newEditorState.getCurrentContent();
103-
}
104-
105101
function computeDiff(txt1, txt2) {
106-
var diffs = DMP.diff_main(left, right);
102+
var diffs = DMP.diff_main(txt1, txt2);
107103
// Simplify diffs a bit to make it human readable (but non optimal)
108104
DMP.diff_cleanupSemantic(diffs);
109105
return diffs;
@@ -112,10 +108,10 @@ function computeDiff(txt1, txt2) {
112108
// Decorators
113109

114110
var InsertedSpan = function (props) {
115-
return <span {...props} style={{backgroundColor: '#eaffea'}}>{props.children}</span>;
111+
return <span {...props} className="inserted">{props.children}</span>;
116112
};
117113
var RemovedSpan = function (props) {
118-
return <span {...props} style={{backgroundColor: '#ffecec'}}>{props.children}</span>;
114+
return <span {...props} className="removed">{props.children}</span>;
119115
};
120116

121117
/**

diff.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ body {
88

99
.left, .right {
1010
width: 44%;
11-
margin: 3%;
11+
margin: 20px 3%;
1212
display: inline-block;
1313
vertical-align: text-top;
1414
}
15+
16+
.removed {
17+
background-color: #ffecec
18+
}
19+
.inserted {
20+
background-color: #eaffea
21+
}

0 commit comments

Comments
 (0)