Skip to content

Commit

Permalink
#25
Browse files Browse the repository at this point in the history
  • Loading branch information
scniro committed Oct 18, 2017
1 parent add234c commit a9533f8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/app.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/src/components/Editor.jsx
Expand Up @@ -142,4 +142,4 @@ function mapState(state) {
}
}

export default connect(mapState)(Editor)
export default connect(mapState)(Editor)
8 changes: 6 additions & 2 deletions index.js
Expand Up @@ -214,7 +214,9 @@ var Controlled = (function(_super) {
};
Controlled.prototype.initChange = function(value) {
this.emulating = true;
this.editor.setValue(value);
var lastLine = this.editor.lastLine();
var lastChar = this.editor.getLine(this.editor.lastLine()).length;
this.editor.replaceRange(value || '', { line: 0, ch: 0 }, { line: lastLine, ch: lastChar });
this.mirror.setValue(value);
this.editor.clearHistory();
this.mirror.clearHistory();
Expand Down Expand Up @@ -389,7 +391,9 @@ var UnControlled = (function(_super) {
var _this = this;
Object.keys(props.options || {}).forEach(function(key) { return _this.editor.setOption(key, props.options[key]); });
if (!this.hydrated) {
this.editor.setValue(props.value || '');
var lastLine = this.editor.lastLine();
var lastChar = this.editor.getLine(this.editor.lastLine()).length;
this.editor.replaceRange(props.value || '', { line: 0, ch: 0 }, { line: lastLine, ch: lastChar });
}
this.hydrated = true;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-codemirror2",
"version": "3.0.0",
"version": "3.0.1",
"description": "a tiny react codemirror component wrapper",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
24 changes: 16 additions & 8 deletions src/index.tsx
Expand Up @@ -120,11 +120,11 @@ class Shared implements ICommon {
console.warn('`resetCursorOnSet` has been deprecated. Use `autoCursor` instead\n\nSee https://github.com/scniro/react-codemirror2#props');
}

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

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

this.emulating = true;

this.editor.setValue(value);
let lastLine = this.editor.lastLine();
let lastChar = this.editor.getLine(this.editor.lastLine()).length;

this.editor.replaceRange(value || '',
{line: 0, ch: 0},
{line: lastLine, ch: lastChar});

this.mirror.setValue(value);
this.editor.clearHistory();
this.mirror.clearHistory();
Expand All @@ -331,13 +337,9 @@ export class Controlled extends React.Component<IControlledCodeMirror, any> {
private resolveChange() {

this.editor.operation(() => {

this.emulating = true;

this.editor.replaceRange(this.deferred.text.join('\n'), this.deferred.from, this.deferred.to, this.deferred.origin);

this.emulating = false;

this.deferred = null;
});
}
Expand Down Expand Up @@ -559,7 +561,13 @@ export class UnControlled extends React.Component<IUnControlledCodeMirror, any>
Object.keys(props.options || {}).forEach(key => this.editor.setOption(key, props.options[key]));

if (!this.hydrated) {
this.editor.setValue(props.value || '');
// this.editor.setValue(props.value || '');
let lastLine = this.editor.lastLine();
let lastChar = this.editor.getLine(this.editor.lastLine()).length;

this.editor.replaceRange(props.value || '',
{line: 0, ch: 0},
{line: lastLine, ch: lastChar});
}

this.hydrated = true;
Expand Down

0 comments on commit a9533f8

Please sign in to comment.