File tree Expand file tree Collapse file tree 5 files changed +24
-4
lines changed Expand file tree Collapse file tree 5 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ require('codemirror/mode/javascript/javascript');
50
50
- ` options ` - see codemirror [ configuration] ( https://codemirror.net/doc/manual.html#config )
51
51
- ` value ` - set component value through props
52
52
> triggers ` onValueSet `
53
+ - ` resetCursorOnSet `
54
+ > ` boolean ` reset the internal codemirror cursor position should a new ` value ` prob be set. Default: ` false `
53
55
54
56
## component specific events
55
57
Original file line number Diff line number Diff line change @@ -148,9 +148,17 @@ var CodeMirror = function (_React$Component) {
148
148
149
149
if ( this . props . value !== nextProps . value ) {
150
150
this . hydrated = false ;
151
+
152
+ if ( ! this . props . resetCursorOnSet ) {
153
+ this . cursorPos = this . editor . getCursor ( ) ;
154
+ }
151
155
}
152
156
153
157
this . hydrate ( nextProps ) ;
158
+
159
+ if ( ! this . props . resetCursorOnSet ) {
160
+ this . editor . setCursor ( this . cursorPos ) ;
161
+ }
154
162
}
155
163
} , {
156
164
key : 'componentWillUnmount' ,
@@ -174,6 +182,7 @@ var CodeMirror = function (_React$Component) {
174
182
}
175
183
176
184
if ( this . props . value && ! this . hydrated ) {
185
+
177
186
this . editor . setValue ( props . value ) ;
178
187
179
188
if ( this . props . onValueSet ) {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-codemirror2" ,
3
- "version" : " 0.0.7 " ,
3
+ "version" : " 0.0.8 " ,
4
4
"description" : " a tiny react codemirror component wrapper" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
54
54
"react" : " 15.6.1" ,
55
55
"react-dom" : " 15.6.1" ,
56
56
"react-redux" : " 5.0.5" ,
57
- "redux" : " 3.7.1 " ,
57
+ "redux" : " 3.7.2 " ,
58
58
"sass-loader" : " 6.0.6" ,
59
59
"style-loader" : " 0.18.2" ,
60
- "webpack" : " 3.1 .0"
60
+ "webpack" : " 3.2 .0"
61
61
}
62
62
}
Original file line number Diff line number Diff line change @@ -120,9 +120,17 @@ export default class CodeMirror extends React.Component {
120
120
121
121
if ( this . props . value !== nextProps . value ) {
122
122
this . hydrated = false ;
123
+
124
+ if ( ! this . props . resetCursorOnSet ) {
125
+ this . cursorPos = this . editor . getCursor ( ) ;
126
+ }
123
127
}
124
128
125
129
this . hydrate ( nextProps ) ;
130
+
131
+ if ( ! this . props . resetCursorOnSet ) {
132
+ this . editor . setCursor ( this . cursorPos ) ;
133
+ }
126
134
}
127
135
128
136
componentWillUnmount ( ) {
@@ -141,6 +149,7 @@ export default class CodeMirror extends React.Component {
141
149
}
142
150
143
151
if ( this . props . value && ! this . hydrated ) {
152
+
144
153
this . editor . setValue ( props . value ) ;
145
154
146
155
if ( this . props . onValueSet ) {
You can’t perform that action at this time.
0 commit comments