diff options
author | 2019-02-07 20:48:57 +0100 | |
---|---|---|
committer | 2019-02-07 20:48:57 +0100 | |
commit | 0900a0139ebeac3f66b185c9f4271c93b498eb16 (patch) | |
tree | c772d7fbea7ec3fa16c0d23dd110330ed8f165b5 | |
parent | fix(Service): Improve focus when switching services (diff) | |
download | ferdium-app-0900a0139ebeac3f66b185c9f4271c93b498eb16.tar.gz ferdium-app-0900a0139ebeac3f66b185c9f4271c93b498eb16.tar.zst ferdium-app-0900a0139ebeac3f66b185c9f4271c93b498eb16.zip |
Spellcheck language autodetection
First prototype is based on slack
-rw-r--r-- | package-lock.json | 99 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/webview/contextMenu.js | 11 | ||||
-rw-r--r-- | src/webview/recipe.js | 44 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 11 |
5 files changed, 119 insertions, 47 deletions
diff --git a/package-lock.json b/package-lock.json index ea3fc58c9..4b8cee089 100644 --- a/package-lock.json +++ b/package-lock.json | |||
@@ -351,23 +351,23 @@ | |||
351 | } | 351 | } |
352 | }, | 352 | }, |
353 | "@babel/helpers": { | 353 | "@babel/helpers": { |
354 | "version": "7.2.0", | 354 | "version": "7.3.1", |
355 | "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.2.0.tgz", | 355 | "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.3.1.tgz", |
356 | "integrity": "sha512-Fr07N+ea0dMcMN8nFpuK6dUIT7/ivt9yKQdEEnjVS83tG2pHwPi03gYmk/tyuwONnZ+sY+GFFPlWGgCtW1hF9A==", | 356 | "integrity": "sha512-Q82R3jKsVpUV99mgX50gOPCWwco9Ec5Iln/8Vyu4osNIOQgSrd9RFrQeUvmvddFNoLwMyOUWU+5ckioEKpDoGA==", |
357 | "dev": true, | 357 | "dev": true, |
358 | "requires": { | 358 | "requires": { |
359 | "@babel/template": "^7.1.2", | 359 | "@babel/template": "^7.1.2", |
360 | "@babel/traverse": "^7.1.5", | 360 | "@babel/traverse": "^7.1.5", |
361 | "@babel/types": "^7.2.0" | 361 | "@babel/types": "^7.3.0" |
362 | }, | 362 | }, |
363 | "dependencies": { | 363 | "dependencies": { |
364 | "@babel/generator": { | 364 | "@babel/generator": { |
365 | "version": "7.2.0", | 365 | "version": "7.3.2", |
366 | "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.2.0.tgz", | 366 | "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.3.2.tgz", |
367 | "integrity": "sha512-BA75MVfRlFQG2EZgFYIwyT1r6xSkwfP2bdkY/kLZusEYWiJs4xCowab/alaEaT0wSvmVuXGqiefeBlP+7V1yKg==", | 367 | "integrity": "sha512-f3QCuPppXxtZOEm5GWPra/uYUjmNQlu9pbAD8D/9jze4pTY83rTtB1igTBSwvkeNlC5gR24zFFkz+2WHLFQhqQ==", |
368 | "dev": true, | 368 | "dev": true, |
369 | "requires": { | 369 | "requires": { |
370 | "@babel/types": "^7.2.0", | 370 | "@babel/types": "^7.3.2", |
371 | "jsesc": "^2.5.1", | 371 | "jsesc": "^2.5.1", |
372 | "lodash": "^4.17.10", | 372 | "lodash": "^4.17.10", |
373 | "source-map": "^0.5.0", | 373 | "source-map": "^0.5.0", |
@@ -375,32 +375,32 @@ | |||
375 | } | 375 | } |
376 | }, | 376 | }, |
377 | "@babel/parser": { | 377 | "@babel/parser": { |
378 | "version": "7.2.0", | 378 | "version": "7.3.2", |
379 | "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.2.0.tgz", | 379 | "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.3.2.tgz", |
380 | "integrity": "sha512-M74+GvK4hn1eejD9lZ7967qAwvqTZayQa3g10ag4s9uewgR7TKjeaT0YMyoq+gVfKYABiWZ4MQD701/t5e1Jhg==", | 380 | "integrity": "sha512-QzNUC2RO1gadg+fs21fi0Uu0OuGNzRKEmgCxoLNzbCdoprLwjfmZwzUrpUNfJPaVRwBpDY47A17yYEGWyRelnQ==", |
381 | "dev": true | 381 | "dev": true |
382 | }, | 382 | }, |
383 | "@babel/traverse": { | 383 | "@babel/traverse": { |
384 | "version": "7.1.6", | 384 | "version": "7.2.3", |
385 | "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.1.6.tgz", | 385 | "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.2.3.tgz", |
386 | "integrity": "sha512-CXedit6GpISz3sC2k2FsGCUpOhUqKdyL0lqNrImQojagnUMXf8hex4AxYFRuMkNGcvJX5QAFGzB5WJQmSv8SiQ==", | 386 | "integrity": "sha512-Z31oUD/fJvEWVR0lNZtfgvVt512ForCTNKYcJBGbPb1QZfve4WGH8Wsy7+Mev33/45fhP/hwQtvgusNdcCMgSw==", |
387 | "dev": true, | 387 | "dev": true, |
388 | "requires": { | 388 | "requires": { |
389 | "@babel/code-frame": "^7.0.0", | 389 | "@babel/code-frame": "^7.0.0", |
390 | "@babel/generator": "^7.1.6", | 390 | "@babel/generator": "^7.2.2", |
391 | "@babel/helper-function-name": "^7.1.0", | 391 | "@babel/helper-function-name": "^7.1.0", |
392 | "@babel/helper-split-export-declaration": "^7.0.0", | 392 | "@babel/helper-split-export-declaration": "^7.0.0", |
393 | "@babel/parser": "^7.1.6", | 393 | "@babel/parser": "^7.2.3", |
394 | "@babel/types": "^7.1.6", | 394 | "@babel/types": "^7.2.2", |
395 | "debug": "^4.1.0", | 395 | "debug": "^4.1.0", |
396 | "globals": "^11.1.0", | 396 | "globals": "^11.1.0", |
397 | "lodash": "^4.17.10" | 397 | "lodash": "^4.17.10" |
398 | } | 398 | } |
399 | }, | 399 | }, |
400 | "@babel/types": { | 400 | "@babel/types": { |
401 | "version": "7.2.0", | 401 | "version": "7.3.2", |
402 | "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.2.0.tgz", | 402 | "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.3.2.tgz", |
403 | "integrity": "sha512-b4v7dyfApuKDvmPb+O488UlGuR1WbwMXFsO/cyqMrnfvRAChZKJAYeeglWTjUO1b9UghKKgepAQM5tsvBJca6A==", | 403 | "integrity": "sha512-3Y6H8xlUlpbGR+XvawiH0UXehqydTmNmEpozWcXymqwcrwYAl5KMvKtQ+TF6f6E08V6Jur7v/ykdDSF+WDEIXQ==", |
404 | "dev": true, | 404 | "dev": true, |
405 | "requires": { | 405 | "requires": { |
406 | "esutils": "^2.0.2", | 406 | "esutils": "^2.0.2", |
@@ -409,31 +409,19 @@ | |||
409 | } | 409 | } |
410 | }, | 410 | }, |
411 | "debug": { | 411 | "debug": { |
412 | "version": "4.1.0", | 412 | "version": "4.1.1", |
413 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", | 413 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", |
414 | "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", | 414 | "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", |
415 | "dev": true, | 415 | "dev": true, |
416 | "requires": { | 416 | "requires": { |
417 | "ms": "^2.1.1" | 417 | "ms": "^2.1.1" |
418 | } | 418 | } |
419 | }, | 419 | }, |
420 | "globals": { | ||
421 | "version": "11.9.0", | ||
422 | "resolved": "https://registry.npmjs.org/globals/-/globals-11.9.0.tgz", | ||
423 | "integrity": "sha512-5cJVtyXWH8PiJPVLZzzoIizXx944O4OmRro5MWKx5fT4MgcN7OfaMutPeaTdJCCURwbWdhhcCWcKIffPnmTzBg==", | ||
424 | "dev": true | ||
425 | }, | ||
426 | "ms": { | 420 | "ms": { |
427 | "version": "2.1.1", | 421 | "version": "2.1.1", |
428 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", | 422 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", |
429 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", | 423 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", |
430 | "dev": true | 424 | "dev": true |
431 | }, | ||
432 | "to-fast-properties": { | ||
433 | "version": "2.0.0", | ||
434 | "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", | ||
435 | "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", | ||
436 | "dev": true | ||
437 | } | 425 | } |
438 | } | 426 | } |
439 | }, | 427 | }, |
@@ -1203,9 +1191,9 @@ | |||
1203 | } | 1191 | } |
1204 | }, | 1192 | }, |
1205 | "@types/node": { | 1193 | "@types/node": { |
1206 | "version": "10.12.19", | 1194 | "version": "10.12.21", |
1207 | "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.19.tgz", | 1195 | "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.21.tgz", |
1208 | "integrity": "sha512-2NVovndCjJQj6fUUn9jCgpP4WSqr+u1SoUZMZyJkhGeBFsm6dE46l31S7lPUYt9uQ28XI+ibrJA1f5XyH5HNtA==", | 1196 | "integrity": "sha512-CBgLNk4o3XMnqMc0rhb6lc77IwShMEglz05deDcn2lQxyXEZivfwgYJu7SMha9V5XcrP6qZuevTHV/QrN2vjKQ==", |
1209 | "dev": true | 1197 | "dev": true |
1210 | }, | 1198 | }, |
1211 | "JSONStream": { | 1199 | "JSONStream": { |
@@ -2487,6 +2475,16 @@ | |||
2487 | "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz", | 2475 | "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz", |
2488 | "integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==" | 2476 | "integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==" |
2489 | }, | 2477 | }, |
2478 | "cld3-asm": { | ||
2479 | "version": "1.0.1", | ||
2480 | "resolved": "https://registry.npmjs.org/cld3-asm/-/cld3-asm-1.0.1.tgz", | ||
2481 | "integrity": "sha512-wuAqZd44Rk164TLKSYyLFZGSObhf82udOR+M/CnOkeEShq9+Tpxb/9RAE0m/KUVD1DnR5gMkZFeYExt51PCAbg==", | ||
2482 | "requires": { | ||
2483 | "emscripten-wasm-loader": "^1.0.0", | ||
2484 | "tslib": "^1.9.0", | ||
2485 | "utf8": "^3.0.0" | ||
2486 | } | ||
2487 | }, | ||
2490 | "cli-boxes": { | 2488 | "cli-boxes": { |
2491 | "version": "1.0.0", | 2489 | "version": "1.0.0", |
2492 | "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-1.0.0.tgz", | 2490 | "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-1.0.0.tgz", |
@@ -7841,9 +7839,9 @@ | |||
7841 | } | 7839 | } |
7842 | }, | 7840 | }, |
7843 | "handlebars": { | 7841 | "handlebars": { |
7844 | "version": "4.0.12", | 7842 | "version": "4.1.0", |
7845 | "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.12.tgz", | 7843 | "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.0.tgz", |
7846 | "integrity": "sha512-RhmTekP+FZL+XNhwS1Wf+bTTZpdLougwt5pcgA1tuz6Jcx0fpH/7z0qd71RKnZHBCxIRBHfBOnio4gViPemNzA==", | 7844 | "integrity": "sha512-l2jRuU1NAWK6AW5qqcTATWQJvNPEwkM7NEKSiv/gqOsoSQbVoWyqVEY5GS+XPQ88zLNmqASRpzfdm8d79hJS+w==", |
7847 | "dev": true, | 7845 | "dev": true, |
7848 | "requires": { | 7846 | "requires": { |
7849 | "async": "^2.5.0", | 7847 | "async": "^2.5.0", |
@@ -13324,7 +13322,7 @@ | |||
13324 | "dependencies": { | 13322 | "dependencies": { |
13325 | "pretty-bytes": { | 13323 | "pretty-bytes": { |
13326 | "version": "1.0.4", | 13324 | "version": "1.0.4", |
13327 | "resolved": "http://registry.npmjs.org/pretty-bytes/-/pretty-bytes-1.0.4.tgz", | 13325 | "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-1.0.4.tgz", |
13328 | "integrity": "sha1-CiLoIQYJrTVUL4yNXSFZr/B1HIQ=", | 13326 | "integrity": "sha1-CiLoIQYJrTVUL4yNXSFZr/B1HIQ=", |
13329 | "dev": true, | 13327 | "dev": true, |
13330 | "requires": { | 13328 | "requires": { |
@@ -14035,7 +14033,7 @@ | |||
14035 | }, | 14033 | }, |
14036 | "readable-stream": { | 14034 | "readable-stream": { |
14037 | "version": "1.1.14", | 14035 | "version": "1.1.14", |
14038 | "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", | 14036 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", |
14039 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", | 14037 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", |
14040 | "dev": true, | 14038 | "dev": true, |
14041 | "requires": { | 14039 | "requires": { |
@@ -14047,13 +14045,13 @@ | |||
14047 | }, | 14045 | }, |
14048 | "string_decoder": { | 14046 | "string_decoder": { |
14049 | "version": "0.10.31", | 14047 | "version": "0.10.31", |
14050 | "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", | 14048 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", |
14051 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", | 14049 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", |
14052 | "dev": true | 14050 | "dev": true |
14053 | }, | 14051 | }, |
14054 | "through2": { | 14052 | "through2": { |
14055 | "version": "0.2.3", | 14053 | "version": "0.2.3", |
14056 | "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz", | 14054 | "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz", |
14057 | "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", | 14055 | "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", |
14058 | "dev": true, | 14056 | "dev": true, |
14059 | "requires": { | 14057 | "requires": { |
@@ -15892,6 +15890,12 @@ | |||
15892 | "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA=", | 15890 | "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA=", |
15893 | "dev": true | 15891 | "dev": true |
15894 | }, | 15892 | }, |
15893 | "to-fast-properties": { | ||
15894 | "version": "2.0.0", | ||
15895 | "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", | ||
15896 | "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", | ||
15897 | "dev": true | ||
15898 | }, | ||
15895 | "to-object-path": { | 15899 | "to-object-path": { |
15896 | "version": "0.3.0", | 15900 | "version": "0.3.0", |
15897 | "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", | 15901 | "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", |
@@ -16351,6 +16355,11 @@ | |||
16351 | "resolved": "https://registry.npmjs.org/user-home/-/user-home-1.1.1.tgz", | 16355 | "resolved": "https://registry.npmjs.org/user-home/-/user-home-1.1.1.tgz", |
16352 | "integrity": "sha1-K1viOjK2Onyd640PKNSFcko98ZA=" | 16356 | "integrity": "sha1-K1viOjK2Onyd640PKNSFcko98ZA=" |
16353 | }, | 16357 | }, |
16358 | "utf8": { | ||
16359 | "version": "3.0.0", | ||
16360 | "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", | ||
16361 | "integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==" | ||
16362 | }, | ||
16354 | "utf8-byte-length": { | 16363 | "utf8-byte-length": { |
16355 | "version": "1.0.4", | 16364 | "version": "1.0.4", |
16356 | "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", | 16365 | "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", |
diff --git a/package.json b/package.json index fba56eb3e..ba141e036 100644 --- a/package.json +++ b/package.json | |||
@@ -34,6 +34,7 @@ | |||
34 | "address-rfc2822": "^2.0.1", | 34 | "address-rfc2822": "^2.0.1", |
35 | "auto-launch": "https://github.com/meetfranz/node-auto-launch.git", | 35 | "auto-launch": "https://github.com/meetfranz/node-auto-launch.git", |
36 | "classnames": "2.2.6", | 36 | "classnames": "2.2.6", |
37 | "cld3-asm": "1.0.1", | ||
37 | "debug-electron": "^0.0.4", | 38 | "debug-electron": "^0.0.4", |
38 | "du": "^0.1.0", | 39 | "du": "^0.1.0", |
39 | "electron-dl": "1.12.0", | 40 | "electron-dl": "1.12.0", |
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index a76c03e5a..7fadfa72b 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -237,6 +237,17 @@ const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheck | |||
237 | type: 'separator', | 237 | type: 'separator', |
238 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage, | 238 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage, |
239 | }, | 239 | }, |
240 | { | ||
241 | id: 'automaticDetection', | ||
242 | label: 'Automatic language detection', | ||
243 | type: 'radio', | ||
244 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage, | ||
245 | checked: spellcheckerLanguage === 'automatic', | ||
246 | click() { | ||
247 | debug('Detect spellchecker language automatically'); | ||
248 | ipcRenderer.sendToHost('set-service-spellchecker-language', 'automatic'); | ||
249 | }, | ||
250 | }, | ||
240 | ...spellcheckingLanguages], | 251 | ...spellcheckingLanguages], |
241 | }); | 252 | }); |
242 | 253 | ||
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index c718b348e..38a65276e 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -1,10 +1,12 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | import { autorun, computed, observable } from 'mobx'; | 3 | import { autorun, computed, observable } from 'mobx'; |
4 | import { loadModule } from 'cld3-asm'; | ||
5 | import { debounce } from 'lodash'; | ||
4 | 6 | ||
5 | import RecipeWebview from './lib/RecipeWebview'; | 7 | import RecipeWebview from './lib/RecipeWebview'; |
6 | 8 | ||
7 | import spellchecker, { switchDict, disable as disableSpellchecker } from './spellchecker'; | 9 | import spellchecker, { switchDict, disable as disableSpellchecker, getSpellcheckerLocaleByFuzzyIdentifier } from './spellchecker'; |
8 | import { injectDarkModeStyle, isDarkModeStyleInjected, removeDarkModeStyle } from './darkmode'; | 10 | import { injectDarkModeStyle, isDarkModeStyleInjected, removeDarkModeStyle } from './darkmode'; |
9 | import contextMenu from './contextMenu'; | 11 | import contextMenu from './contextMenu'; |
10 | import './notifications'; | 12 | import './notifications'; |
@@ -60,6 +62,39 @@ class RecipeController { | |||
60 | ); | 62 | ); |
61 | 63 | ||
62 | autorun(() => this.update()); | 64 | autorun(() => this.update()); |
65 | |||
66 | console.log(JSON.parse(JSON.stringify(this.settings))); | ||
67 | |||
68 | const cldFactory = await loadModule(); | ||
69 | const identifier = cldFactory.create(0, 1000); | ||
70 | |||
71 | window.addEventListener('keyup', debounce((e) => { | ||
72 | const elem = e.target; | ||
73 | |||
74 | let value = ''; | ||
75 | if (elem.isContentEditable) { | ||
76 | value = elem.textContent; | ||
77 | } else { | ||
78 | // | ||
79 | } | ||
80 | |||
81 | // Force a minimum length to get better detection results | ||
82 | if (value.length < 30) return; | ||
83 | |||
84 | debug('Detecting language for', value); | ||
85 | const findResult = identifier.findLanguage(value); | ||
86 | |||
87 | debug('Language detection result', findResult); | ||
88 | |||
89 | if (findResult.is_reliable) { | ||
90 | debug('Language detected reliably, setting spellchecker language to', findResult.language); | ||
91 | const spellcheckerLocale = getSpellcheckerLocaleByFuzzyIdentifier(findResult.language); | ||
92 | debug('reported back', spellcheckerLocale); | ||
93 | if (spellcheckerLocale) { | ||
94 | switchDict(spellcheckerLocale); | ||
95 | } | ||
96 | } | ||
97 | }, 200)); | ||
63 | } | 98 | } |
64 | 99 | ||
65 | loadRecipeModule(event, config, recipe) { | 100 | loadRecipeModule(event, config, recipe) { |
@@ -87,7 +122,12 @@ class RecipeController { | |||
87 | 122 | ||
88 | if (this.settings.app.enableSpellchecking) { | 123 | if (this.settings.app.enableSpellchecking) { |
89 | debug('Setting spellchecker language to', this.spellcheckerLanguage); | 124 | debug('Setting spellchecker language to', this.spellcheckerLanguage); |
90 | switchDict(this.spellcheckerLanguage); | 125 | let { spellcheckerLanguage } = this; |
126 | if (spellcheckerLanguage === 'automatic') { | ||
127 | debug('Found `automatic` locale, falling back to user locale until detected', this.settings.app.locale); | ||
128 | spellcheckerLanguage = this.settings.app.locale; | ||
129 | } | ||
130 | switchDict(spellcheckerLanguage); | ||
91 | } else { | 131 | } else { |
92 | debug('Disable spellchecker'); | 132 | debug('Disable spellchecker'); |
93 | disableSpellchecker(); | 133 | disableSpellchecker(); |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index becaed449..c711382be 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -3,6 +3,7 @@ import { SpellCheckerProvider } from 'electron-hunspell'; | |||
3 | import path from 'path'; | 3 | import path from 'path'; |
4 | 4 | ||
5 | import { DICTIONARY_PATH } from '../config'; | 5 | import { DICTIONARY_PATH } from '../config'; |
6 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | ||
6 | 7 | ||
7 | const debug = require('debug')('Franz:spellchecker'); | 8 | const debug = require('debug')('Franz:spellchecker'); |
8 | 9 | ||
@@ -82,3 +83,13 @@ export function disable() { | |||
82 | currentDict = null; | 83 | currentDict = null; |
83 | } | 84 | } |
84 | } | 85 | } |
86 | |||
87 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { | ||
88 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key.split('-')[0] === identifier); | ||
89 | |||
90 | if (locales.length >= 1) { | ||
91 | return locales[0]; | ||
92 | } | ||
93 | |||
94 | return null; | ||
95 | } | ||