diff options
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/plugin.js | 16 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 40 |
2 files changed, 42 insertions, 14 deletions
diff --git a/src/webview/plugin.js b/src/webview/plugin.js index fec353f34..c877132b1 100644 --- a/src/webview/plugin.js +++ b/src/webview/plugin.js | |||
@@ -3,10 +3,12 @@ import path from 'path'; | |||
3 | 3 | ||
4 | import RecipeWebview from './lib/RecipeWebview'; | 4 | import RecipeWebview from './lib/RecipeWebview'; |
5 | 5 | ||
6 | import './spellchecker.js'; | 6 | import Spellchecker from './spellchecker.js'; |
7 | import './notifications.js'; | 7 | import './notifications.js'; |
8 | import './ime.js'; | 8 | import './ime.js'; |
9 | 9 | ||
10 | const spellchecker = new Spellchecker(); | ||
11 | |||
10 | ipcRenderer.on('initializeRecipe', (e, data) => { | 12 | ipcRenderer.on('initializeRecipe', (e, data) => { |
11 | const modulePath = path.join(data.recipe.path, 'webview.js'); | 13 | const modulePath = path.join(data.recipe.path, 'webview.js'); |
12 | // Delete module from cache | 14 | // Delete module from cache |
@@ -20,7 +22,17 @@ ipcRenderer.on('initializeRecipe', (e, data) => { | |||
20 | }); | 22 | }); |
21 | 23 | ||
22 | ipcRenderer.on('settings-update', (e, data) => { | 24 | ipcRenderer.on('settings-update', (e, data) => { |
23 | console.log(data); | 25 | if (data.enableSpellchecking) { |
26 | if (!spellchecker.isEnabled) { | ||
27 | spellchecker.enable(); | ||
28 | |||
29 | // TODO: this does not work yet, needs more testing | ||
30 | // if (data.spellcheckingLanguage !== 'auto') { | ||
31 | // console.log('set spellchecking language to', data.spellcheckingLanguage); | ||
32 | // spellchecker.switchLanguage(data.spellcheckingLanguage); | ||
33 | // } | ||
34 | } | ||
35 | } | ||
24 | }); | 36 | }); |
25 | 37 | ||
26 | document.addEventListener('DOMContentLoaded', () => { | 38 | document.addEventListener('DOMContentLoaded', () => { |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index ec8807874..5beb77e03 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -1,14 +1,30 @@ | |||
1 | import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker'; | 1 | import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker'; |
2 | 2 | ||
3 | window.spellCheckHandler = new SpellCheckHandler(); | 3 | import { isMac } from '../environment'; |
4 | setTimeout(() => { | 4 | |
5 | window.spellCheckHandler.attachToInput(); | 5 | export default class Spellchecker { |
6 | }, 1000); | 6 | isEnabled = false; |
7 | 7 | spellchecker = null; | |
8 | // TODO: should we set the language to user settings? | 8 | |
9 | // window.spellCheckHandler.switchLanguage('en-US'); | 9 | enable() { |
10 | 10 | this.spellchecker = new SpellCheckHandler(); | |
11 | const contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler); | 11 | if (!isMac) { |
12 | const contextMenuListener = new ContextMenuListener((info) => { // eslint-disable-line | 12 | this.spellchecker.attachToInput(); |
13 | contextMenuBuilder.showPopupMenu(info); | 13 | this.spellchecker.switchLanguage(navigator.language); |
14 | }); | 14 | } |
15 | |||
16 | const contextMenuBuilder = new ContextMenuBuilder(this.spellchecker); | ||
17 | |||
18 | new ContextMenuListener((info) => { // eslint-disable-line | ||
19 | contextMenuBuilder.showPopupMenu(info); | ||
20 | }); | ||
21 | } | ||
22 | |||
23 | // TODO: this does not work yet, needs more testing | ||
24 | // switchLanguage(language) { | ||
25 | // if (language !== 'auto') { | ||
26 | // this.spellchecker.switchLanguage(language); | ||
27 | // } | ||
28 | // } | ||
29 | } | ||
30 | |||