diff options
author | 2017-12-13 11:20:13 +0100 | |
---|---|---|
committer | 2017-12-13 11:20:13 +0100 | |
commit | fc49f232d9ac116f2a3bd7667fdd3e553df7516f (patch) | |
tree | 441d3ccf76b7a3f5483c6b114d96af0159fb7560 /src/webview | |
parent | fix mobx issue with settings model (diff) | |
download | ferdium-app-fc49f232d9ac116f2a3bd7667fdd3e553df7516f.tar.gz ferdium-app-fc49f232d9ac116f2a3bd7667fdd3e553df7516f.tar.zst ferdium-app-fc49f232d9ac116f2a3bd7667fdd3e553df7516f.zip |
override spellchecker attribute on inputs to enable/disable spellchecker
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/plugin.js | 15 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 21 |
2 files changed, 26 insertions, 10 deletions
diff --git a/src/webview/plugin.js b/src/webview/plugin.js index 610dffc8e..cf38169d3 100644 --- a/src/webview/plugin.js +++ b/src/webview/plugin.js | |||
@@ -21,23 +21,18 @@ ipcRenderer.on('initializeRecipe', (e, data) => { | |||
21 | } | 21 | } |
22 | }); | 22 | }); |
23 | 23 | ||
24 | let contextMenuBuilder = new ContextMenuBuilder(null, null, isDevMode); | ||
25 | const spellchecker = new Spellchecker(); | 24 | const spellchecker = new Spellchecker(); |
25 | spellchecker.initialize(); | ||
26 | |||
27 | const contextMenuBuilder = new ContextMenuBuilder(spellchecker.handler, null, isDevMode); | ||
26 | 28 | ||
27 | new ContextMenuListener((info) => { // eslint-disable-line | 29 | new ContextMenuListener((info) => { // eslint-disable-line |
28 | contextMenuBuilder.showPopupMenu(info); | 30 | contextMenuBuilder.showPopupMenu(info); |
29 | }); | 31 | }); |
30 | 32 | ||
31 | ipcRenderer.on('settings-update', (e, data) => { | 33 | ipcRenderer.on('settings-update', (e, data) => { |
32 | if (data.enableSpellchecking && !spellchecker.isInitialized) { | 34 | console.log('settings-update', data); |
33 | spellchecker.initialize(); | 35 | spellchecker.toggleSpellchecker(data.enableSpellchecking); |
34 | |||
35 | contextMenuBuilder = new ContextMenuBuilder(spellchecker.handler, null, isDevMode); | ||
36 | |||
37 | new ContextMenuListener((info) => { // eslint-disable-line | ||
38 | contextMenuBuilder.showPopupMenu(info); | ||
39 | }); | ||
40 | } | ||
41 | }); | 36 | }); |
42 | 37 | ||
43 | // initSpellche | 38 | // initSpellche |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 5704779d7..a504a4039 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -6,6 +6,11 @@ export default class Spellchecker { | |||
6 | isInitialized = false; | 6 | isInitialized = false; |
7 | handler = null; | 7 | handler = null; |
8 | initRetries = 0; | 8 | initRetries = 0; |
9 | DOMCheckInterval = null; | ||
10 | |||
11 | get inputs() { | ||
12 | return document.querySelectorAll('input[type="text"], [contenteditable="true"], textarea'); | ||
13 | } | ||
9 | 14 | ||
10 | initialize() { | 15 | initialize() { |
11 | this.handler = new SpellCheckHandler(); | 16 | this.handler = new SpellCheckHandler(); |
@@ -38,5 +43,21 @@ export default class Spellchecker { | |||
38 | this.isInitialized = true; | 43 | this.isInitialized = true; |
39 | } | 44 | } |
40 | } | 45 | } |
46 | |||
47 | toggleSpellchecker(enable = false) { | ||
48 | this.inputs.forEach((input) => { | ||
49 | input.setAttribute('spellcheck', enable); | ||
50 | }); | ||
51 | |||
52 | this.intervalHandler(enable); | ||
53 | } | ||
54 | |||
55 | intervalHandler(enable) { | ||
56 | clearInterval(this.DOMCheckInterval); | ||
57 | |||
58 | if (enable) { | ||
59 | this.DOMCheckInterval = setInterval(() => this.toggleSpellchecker(enable), 30000); | ||
60 | } | ||
61 | } | ||
41 | } | 62 | } |
42 | 63 | ||