Skip to content

Commit a9533f8

Browse files
committed
1 parent add234c commit a9533f8

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
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.

docs/src/components/Editor.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ function mapState(state) {
142142
}
143143
}
144144

145-
export default connect(mapState)(Editor)
145+
export default connect(mapState)(Editor)

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ var Controlled = (function(_super) {
214214
};
215215
Controlled.prototype.initChange = function(value) {
216216
this.emulating = true;
217-
this.editor.setValue(value);
217+
var lastLine = this.editor.lastLine();
218+
var lastChar = this.editor.getLine(this.editor.lastLine()).length;
219+
this.editor.replaceRange(value || '', { line: 0, ch: 0 }, { line: lastLine, ch: lastChar });
218220
this.mirror.setValue(value);
219221
this.editor.clearHistory();
220222
this.mirror.clearHistory();
@@ -389,7 +391,9 @@ var UnControlled = (function(_super) {
389391
var _this = this;
390392
Object.keys(props.options || {}).forEach(function(key) { return _this.editor.setOption(key, props.options[key]); });
391393
if (!this.hydrated) {
392-
this.editor.setValue(props.value || '');
394+
var lastLine = this.editor.lastLine();
395+
var lastChar = this.editor.getLine(this.editor.lastLine()).length;
396+
this.editor.replaceRange(props.value || '', { line: 0, ch: 0 }, { line: lastLine, ch: lastChar });
393397
}
394398
this.hydrated = true;
395399
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-codemirror2",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "a tiny react codemirror component wrapper",
55
"main": "index.js",
66
"typings": "index.d.ts",

src/index.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ class Shared implements ICommon {
120120
console.warn('`resetCursorOnSet` has been deprecated. Use `autoCursor` instead\n\nSee https://github.com/scniro/react-codemirror2#props');
121121
}
122122

123-
if(this.props.onSet !== undefined) {
123+
if (this.props.onSet !== undefined) {
124124
console.warn('`onSet` has been deprecated. User `editorDidMount` instead. See https://github.com/scniro/react-codemirror2#events');
125125
}
126126

127-
if(this.props.onBeforeSet !== undefined) {
127+
if (this.props.onBeforeSet !== undefined) {
128128
console.warn('`onBeforeSet` has been deprecated. User `onBeforeChange` for `Controlled`. instead. See https://github.com/scniro/react-codemirror2#events');
129129
}
130130
}
@@ -319,7 +319,13 @@ export class Controlled extends React.Component<IControlledCodeMirror, any> {
319319

320320
this.emulating = true;
321321

322-
this.editor.setValue(value);
322+
let lastLine = this.editor.lastLine();
323+
let lastChar = this.editor.getLine(this.editor.lastLine()).length;
324+
325+
this.editor.replaceRange(value || '',
326+
{line: 0, ch: 0},
327+
{line: lastLine, ch: lastChar});
328+
323329
this.mirror.setValue(value);
324330
this.editor.clearHistory();
325331
this.mirror.clearHistory();
@@ -331,13 +337,9 @@ export class Controlled extends React.Component<IControlledCodeMirror, any> {
331337
private resolveChange() {
332338

333339
this.editor.operation(() => {
334-
335340
this.emulating = true;
336-
337341
this.editor.replaceRange(this.deferred.text.join('\n'), this.deferred.from, this.deferred.to, this.deferred.origin);
338-
339342
this.emulating = false;
340-
341343
this.deferred = null;
342344
});
343345
}
@@ -559,7 +561,13 @@ export class UnControlled extends React.Component<IUnControlledCodeMirror, any>
559561
Object.keys(props.options || {}).forEach(key => this.editor.setOption(key, props.options[key]));
560562

561563
if (!this.hydrated) {
562-
this.editor.setValue(props.value || '');
564+
// this.editor.setValue(props.value || '');
565+
let lastLine = this.editor.lastLine();
566+
let lastChar = this.editor.getLine(this.editor.lastLine()).length;
567+
568+
this.editor.replaceRange(props.value || '',
569+
{line: 0, ch: 0},
570+
{line: lastLine, ch: lastChar});
563571
}
564572

565573
this.hydrated = true;

0 commit comments

Comments
 (0)