Skip to content

Commit 2cec974

Browse files
committed
Both editor writable
1 parent 16f7381 commit 2cec974

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

diff-area.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var DIFF = {
99
EQUAL: 0
1010
};
1111

12-
var DEBOUNCE_WAIT = 600; // ms
12+
var DEBOUNCE_WAIT = 300; // ms
1313
var DEBOUNCE_OPTS = {
1414
trailing: true // We want to update after the delay only
1515
};
@@ -48,27 +48,37 @@ var DiffArea = React.createClass({
4848
return state;
4949
},
5050

51-
onChange: function (rightState) {
51+
onRightChanged: function (rightState) {
5252
// Text changed ?
5353
var contentChanged = this.state.rightState.getCurrentContent()
5454
!== rightState.getCurrentContent();
55-
5655
// Update diffs
5756
if (contentChanged) {
5857
this.debouncedUpdateDiffs();
5958
}
60-
6159
// Update the EditorState
6260
this.setState({
63-
leftState: this.state.leftState,
6461
rightState: rightState
6562
});
6663
},
6764

65+
onLeftChanged: function (leftState) {
66+
var contentChanged = this.state.leftState.getCurrentContent()
67+
!== leftState.getCurrentContent();
68+
// Update diffs
69+
if (contentChanged) {
70+
this.debouncedUpdateDiffs();
71+
}
72+
// Update the EditorState
73+
this.setState({
74+
leftState: leftState
75+
});
76+
},
77+
6878
// We use a debounced version of it
6979
updateDiffs: function () {
7080
var newState = {};
71-
var left = this.props.left;
81+
var left = this.state.leftState.getCurrentContent().getPlainText();
7282
var right = this.state.rightState.getCurrentContent().getPlainText();
7383

7484
var diffs = computeDiff(left, right);
@@ -91,13 +101,13 @@ var DiffArea = React.createClass({
91101
<div className='left'>
92102
<Draft.Editor
93103
editorState={this.state.leftState}
94-
readOnly={true}
104+
onChange={this.onLeftChanged}
95105
/>
96106
</div>
97107
<div className='right'>
98108
<Draft.Editor
99109
editorState={this.state.rightState}
100-
onChange={this.onChange}
110+
onChange={this.onRightChanged}
101111
/>
102112
</div>
103113
</div>;

diff.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ body {
22
font-family: monospace;
33
}
44

5-
.left {
6-
color: #666;
7-
}
8-
95
.left, .right {
106
width: 44%;
117
margin: 20px 3%;

0 commit comments

Comments
 (0)