@@ -15,6 +15,7 @@ class TextEditorContainer extends React.Component {
15
15
this . state = {
16
16
cursorPosition : { row : 0 , column : 0 }
17
17
}
18
+ this . currentLanguage = this . props . language
18
19
}
19
20
20
21
changeTheme ( theme ) {
@@ -24,6 +25,7 @@ class TextEditorContainer extends React.Component {
24
25
changeLanguage ( language ) {
25
26
if ( language === 'coffeescript' ) language = 'coffee' ;
26
27
this . aceEditor . session . setMode ( `ace/mode/${ language } ` ) ;
28
+ this . currentLanguage = language ;
27
29
this . aceEditor . setValue ( "" ) ;
28
30
}
29
31
@@ -35,11 +37,6 @@ class TextEditorContainer extends React.Component {
35
37
if ( nextProps . language !== this . props . language ) {
36
38
this . changeLanguage ( nextProps . language ) ;
37
39
}
38
-
39
- // Load saved text when a prop change is detected
40
- if ( nextProps . language !== this . props . language ) {
41
- GeneralActions . loadSavedEditorText ( nextProps . language ) ;
42
- }
43
40
}
44
41
45
42
componentWillMount ( ) {
@@ -124,9 +121,11 @@ class TextEditorContainer extends React.Component {
124
121
if ( this . props . language === "markdown" ) {
125
122
this . props . getEditorText ( this . aceEditor . getValue ( ) ) ;
126
123
}
127
- // automatically save text in editor when ther is a change
124
+ // automatically save text in editor when there is a change
128
125
if ( event . data . action == 'insertText' || event . data . action == 'removeText' ) {
129
- this . saveEditorText ( ) ;
126
+ // ensure the editor text is saved only if the current language is equal to
127
+ // the language passed through the props.
128
+ this . currentLanguage == this . props . language ? this . saveEditorText ( ) : null ;
130
129
}
131
130
}
132
131
0 commit comments