Skip to content

Commit 2738964

Browse files
committed
Normalising line endings in compWillReceiveProps, manual merge of JedWatson#61
Closes JedWatson#61
1 parent 53be55f commit 2738964

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Codemirror.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const findDOMNode = ReactDOM.findDOMNode;
44
const className = require('classnames');
55
const debounce = require('lodash.debounce');
66

7+
function normalizeLineEndings (str) {
8+
if (!str) return str;
9+
return str.replace(/\r\n|\r/g, '\n');
10+
}
11+
712
const CodeMirror = React.createClass({
813
propTypes: {
914
className: React.PropTypes.any,
@@ -50,7 +55,7 @@ const CodeMirror = React.createClass({
5055
}
5156
},
5257
componentWillReceiveProps: function (nextProps) {
53-
if (this.codeMirror && nextProps.value !== undefined && this.codeMirror.getValue() !== nextProps.value) {
58+
if (this.codeMirror && nextProps.value !== undefined && normalizeLineEndings(this.codeMirror.getValue()) !== normalizeLineEndings(nextProps.value)) {
5459
if (this.props.preserveScrollPosition) {
5560
var prevScrollPosition = this.codeMirror.getScrollInfo();
5661
this.codeMirror.setValue(nextProps.value);

0 commit comments

Comments
 (0)