Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka authored and dmsnell committed Nov 5, 2019
1 parent ca99d22 commit afbc023
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/note-content-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ export default class NoteContentEditor extends Component {

const { editorState } = this.state;

const setAutoDetectedLanguage = () => {
const updateLanguage = () => {
const minimumContentLength = 10;
if (!detectLanguage || content.text.length < minimumContentLength) {
window.spellCheckHandler.switchLanguage(navigator.language);
this.setState({ lang: undefined });
} else {
// Auto-detect the note content language to switch spellchecker
window.spellCheckHandler.provideHintText(content.text).then(() => {
// Use the auto-detected language to set a `lang` attribute on the
Expand All @@ -172,6 +177,7 @@ export default class NoteContentEditor extends Component {
lang: window.spellCheckHandler.currentSpellcheckerLanguage,
});
});
}
};

// Only relevant in Electron
Expand All @@ -183,20 +189,14 @@ export default class NoteContentEditor extends Component {
if (spellCheckEnabled !== prevProps.spellCheckEnabled) {
this.editorKey += 1;
this.forceUpdate();
updateLanguage();
}

// Update language related settings when another note is selected
if (noteId !== prevProps.noteId && detectLanguage) {
setAutoDetectedLanguage();
}

if (detectLanguage !== prevProps.detectLanguage) {
if (detectLanguage) {
setAutoDetectedLanguage();
} else {
window.spellCheckHandler.switchLanguage(navigator.language);
this.setState({ lang: undefined });
}
if (
noteId !== prevProps.noteId ||
detectLanguage !== prevProps.detectLanguage
) {
updateLanguage();
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/state/settings/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const initialState = {
wpToken: false,
};


function reducer(state = initialState, action) {
switch (action.type) {
case 'setAccountName':
Expand Down

0 comments on commit afbc023

Please sign in to comment.