Skip to content

Commit b26abdd

Browse files
author
Arinde Eniola
committed
fix bug causing editor text to be overwritten when language is changed
1 parent 7988883 commit b26abdd

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

app/js/containers/TextEditorContainer.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TextEditorContainer extends React.Component {
1515
this.state = {
1616
cursorPosition: {row: 0, column: 0}
1717
}
18+
this.currentLanguage = this.props.language
1819
}
1920

2021
changeTheme(theme) {
@@ -24,6 +25,7 @@ class TextEditorContainer extends React.Component {
2425
changeLanguage(language) {
2526
if (language === 'coffeescript') language = 'coffee';
2627
this.aceEditor.session.setMode(`ace/mode/${language}`);
28+
this.currentLanguage = language;
2729
this.aceEditor.setValue("");
2830
}
2931

@@ -35,11 +37,6 @@ class TextEditorContainer extends React.Component {
3537
if (nextProps.language !== this.props.language) {
3638
this.changeLanguage(nextProps.language);
3739
}
38-
39-
// Load saved text when a prop change is detected
40-
if (nextProps.language !== this.props.language){
41-
GeneralActions.loadSavedEditorText(nextProps.language);
42-
}
4340
}
4441

4542
componentWillMount() {
@@ -124,9 +121,11 @@ class TextEditorContainer extends React.Component {
124121
if (this.props.language === "markdown") {
125122
this.props.getEditorText(this.aceEditor.getValue());
126123
}
127-
// automatically save text in editor when ther is a change
124+
// automatically save text in editor when there is a change
128125
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;
130129
}
131130
}
132131

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ ipc.on('load-editor-text', function(event, arg){
5555
}
5656
mainWindow.webContents.send('loaded-editor-text', data)
5757
});
58-
});
58+
});

0 commit comments

Comments
 (0)