From 5feb67f67df344f6e66a20ad208ed914ee392afb Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 16 Feb 2019 04:54:54 +0900 Subject: [PATCH] Refactor --- lib/note-content-editor.jsx | 26 +++++++++++++------------- lib/state/settings/reducer.js | 1 - 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/note-content-editor.jsx b/lib/note-content-editor.jsx index 07bc97851..d5c68b633 100644 --- a/lib/note-content-editor.jsx +++ b/lib/note-content-editor.jsx @@ -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 @@ -172,6 +177,7 @@ export default class NoteContentEditor extends Component { lang: window.spellCheckHandler.currentSpellcheckerLanguage, }); }); + } }; // Only relevant in Electron @@ -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(); } } diff --git a/lib/state/settings/reducer.js b/lib/state/settings/reducer.js index 35e92aea7..84bcd9c46 100644 --- a/lib/state/settings/reducer.js +++ b/lib/state/settings/reducer.js @@ -17,7 +17,6 @@ export const initialState = { wpToken: false, }; - function reducer(state = initialState, action) { switch (action.type) { case 'setAccountName':