forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspellcheckerLanguage.js
More file actions
58 lines (50 loc) · 1.66 KB
/
spellcheckerLanguage.js
File metadata and controls
58 lines (50 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import bus from '../bus'
import notice from '@/services/notification'
import { delay } from '@/util'
import { SpellChecker } from '@/spellchecker'
import { getLanguageName } from '@/spellchecker/languageMap'
// Command to switch the spellchecker language
class SpellcheckerLanguageCommand {
constructor (spellchecker) {
this.id = 'spellchecker.switch-language'
this.description = 'Spelling: Switch language'
this.placeholder = 'Select a language to switch to'
this.shortcut = null
this.spellchecker = spellchecker
this.subcommands = []
this.subcommandSelectedIndex = -1
}
run = async () => {
const langs = await SpellChecker.getAvailableDictionaries()
this.subcommands = langs.map(lang => {
return {
id: `spellchecker.switch-language-id-${lang}`,
description: getLanguageName(lang),
value: lang
}
})
const currentLanguage = this.spellchecker.lang
this.subcommandSelectedIndex = this.subcommands.findIndex(cmd => cmd.value === currentLanguage)
}
execute = async () => {
// Timeout to hide the command palette and then show again to prevent issues.
await delay(100)
bus.$emit('show-command-palette', this)
}
executeSubcommand = async id => {
const command = this.subcommands.find(cmd => cmd.id === id)
if (this.spellchecker.isEnabled) {
bus.$emit('switch-spellchecker-language', command.value)
} else {
notice.notify({
title: 'Spelling',
type: 'warning',
message: 'Cannot change language because spellchecker is disabled.'
})
}
}
unload = () => {
this.subcommands = []
}
}
export default SpellcheckerLanguageCommand