File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,12 @@ const CodeMirror = React.createClass({
1515 options : React . PropTypes . object ,
1616 path : React . PropTypes . string ,
1717 value : React . PropTypes . string ,
18+ preserveScrollPosition : React . PropTypes . bool ,
19+ } ,
20+ getDefaultProps ( ) {
21+ return {
22+ preserveScrollPosition : false ,
23+ } ;
1824 } ,
1925 getCodeMirrorInstance ( ) {
2026 return this . props . codeMirrorInstance || require ( 'codemirror' ) ;
@@ -45,7 +51,13 @@ const CodeMirror = React.createClass({
4551 } ,
4652 componentWillReceiveProps : function ( nextProps ) {
4753 if ( this . codeMirror && nextProps . value !== undefined && this . codeMirror . getValue ( ) !== nextProps . value ) {
48- this . codeMirror . setValue ( nextProps . value ) ;
54+ if ( this . props . preserveScrollPosition ) {
55+ var prevScrollPosition = this . codeMirror . getScrollInfo ( ) ;
56+ this . codeMirror . setValue ( nextProps . value ) ;
57+ this . codeMirror . scrollTo ( prevScrollPosition . left , prevScrollPosition . top ) ;
58+ } else {
59+ this . codeMirror . setValue ( nextProps . value ) ;
60+ }
4961 }
5062 if ( typeof nextProps . options === 'object' ) {
5163 for ( let optionName in nextProps . options ) {
You can’t perform that action at this time.
0 commit comments