Skip to content

Commit eaa7eb4

Browse files
committed
1 parent d63881f commit eaa7eb4

File tree

5 files changed

+125
-66
lines changed

5 files changed

+125
-66
lines changed

docs/app.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ var CodeMirror = function (_React$Component) {
6262
value: function componentDidMount() {
6363
var _this2 = this;
6464

65-
/* deprecation warnings per 1.0.0 release */
66-
if (this.props.onValueChange) {
67-
console.warn('`onValueChange` has been deprecated. Please use `onChange` instead');
68-
}
69-
70-
if (this.props.onValueSet) {
71-
console.warn('`onValueSet` has been deprecated. Please use `onSet` instead');
72-
}
73-
/* end deprecation warnings per 1.0.0 release */
74-
7565
if (this.props.defineMode) {
7666
if (this.props.defineMode.name && this.props.defineMode.fn) {
7767
codemirror.defineMode(this.props.defineMode.name, this.props.defineMode.fn);
@@ -264,7 +254,10 @@ var CodeMirror = function (_React$Component) {
264254

265255
if (!this.hydrated) {
266256

267-
this.editor.setValue(props.value || '');
257+
var lastLine = this.editor.lastLine();
258+
var lastChar = this.editor.getLine(this.editor.lastLine()).length;
259+
260+
this.editor.replaceRange(props.value || '', { line: 0, ch: 0 }, { line: lastLine, ch: lastChar });
268261

269262
if (this.props.onBeforeSet) {
270263
this.props.onBeforeSet(this.editor, this.onBeforeSetCb);

package-lock.json

Lines changed: 112 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-codemirror2",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "a tiny react codemirror component wrapper",
55
"main": "index.js",
66
"scripts": {
@@ -45,7 +45,7 @@
4545
"babel-register": "6.26.0",
4646
"codemirror": "^5.0.0",
4747
"css-loader": "0.28.7",
48-
"express": "4.15.5",
48+
"express": "4.16.0",
4949
"js-beautify": "1.7.3",
5050
"node-sass": "4.5.3",
5151
"open": "0.0.5",

src/react-codemirror2.jsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ export default class CodeMirror extends React.Component {
3535

3636
componentDidMount() {
3737

38-
/* deprecation warnings per 1.0.0 release */
39-
if (this.props.onValueChange) {
40-
console.warn('`onValueChange` has been deprecated. Please use `onChange` instead');
41-
}
42-
43-
if (this.props.onValueSet) {
44-
console.warn('`onValueSet` has been deprecated. Please use `onSet` instead');
45-
}
46-
/* end deprecation warnings per 1.0.0 release */
47-
4838
if (this.props.defineMode) {
4939
if (this.props.defineMode.name && this.props.defineMode.fn) {
5040
codemirror.defineMode(this.props.defineMode.name, this.props.defineMode.fn);
@@ -232,7 +222,12 @@ export default class CodeMirror extends React.Component {
232222

233223
if (!this.hydrated) {
234224

235-
this.editor.setValue(props.value || '');
225+
let lastLine = this.editor.lastLine();
226+
let lastChar = this.editor.getLine(this.editor.lastLine()).length;
227+
228+
this.editor.replaceRange(props.value || '',
229+
{line: 0, ch: 0},
230+
{line: lastLine, ch: lastChar});
236231

237232
if (this.props.onBeforeSet) {
238233
this.props.onBeforeSet(this.editor, this.onBeforeSetCb);

0 commit comments

Comments
 (0)