Skip to content

Commit

Permalink
fix bug causing editor text to be overwritten when language is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Arinde Eniola committed Feb 23, 2016
1 parent 7988883 commit b26abdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/js/containers/TextEditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TextEditorContainer extends React.Component {
this.state = {
cursorPosition: {row: 0, column: 0}
}
this.currentLanguage = this.props.language
}

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

Expand All @@ -35,11 +37,6 @@ class TextEditorContainer extends React.Component {
if (nextProps.language !== this.props.language) {
this.changeLanguage(nextProps.language);
}

// Load saved text when a prop change is detected
if (nextProps.language !== this.props.language){
GeneralActions.loadSavedEditorText(nextProps.language);
}
}

componentWillMount() {
Expand Down Expand Up @@ -124,9 +121,11 @@ class TextEditorContainer extends React.Component {
if (this.props.language === "markdown") {
this.props.getEditorText(this.aceEditor.getValue());
}
// automatically save text in editor when ther is a change
// automatically save text in editor when there is a change
if (event.data.action == 'insertText' || event.data.action == 'removeText') {
this.saveEditorText();
// ensure the editor text is saved only if the current language is equal to
// the language passed through the props.
this.currentLanguage == this.props.language ? this.saveEditorText() : null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ ipc.on('load-editor-text', function(event, arg){
}
mainWindow.webContents.send('loaded-editor-text', data)
});
});
});

0 comments on commit b26abdd

Please sign in to comment.