Skip to content

Commit c2e45fe

Browse files
committed
only show current language checkbox
1 parent 43c62c4 commit c2e45fe

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

src/InputMethodConfig.vue

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const adding = ref(false)
5555
5656
const selectedLanguage = ref<string | null>(null)
5757
58-
const availableInputMethodOptions = ref<{
58+
const languageOptions = ref<{
5959
label: string
6060
key: string
6161
}[]>([])
@@ -77,7 +77,7 @@ watchEffect(() => {
7777
displayName: im.displayName,
7878
})
7979
}
80-
availableInputMethodOptions.value = []
80+
languageOptions.value = []
8181
const sortedLanguageCodes = Object.keys(map).sort((a: string, b: string) => {
8282
if (!a) {
8383
return 1
@@ -96,15 +96,15 @@ watchEffect(() => {
9696
return la.localeCompare(lb)
9797
})
9898
for (const languageCode of sortedLanguageCodes) {
99-
availableInputMethodOptions.value.push({
100-
label: languageCode ? (languageName.of(languageCode) ?? languageCode) : languageCode,
99+
languageOptions.value.push({
100+
label: languageCode ? (languageName.of(languageCode) ?? languageCode) : 'Unknown',
101101
key: languageCode,
102102
})
103103
}
104104
})
105105
106106
const inputMethodsForLanguage = computed(() => {
107-
if (!selectedLanguage.value) {
107+
if (selectedLanguage.value === null) {
108108
return []
109109
}
110110
const enabledIMs = props.inputMethods.map(({ name }) => name)
@@ -118,6 +118,16 @@ function add() {
118118
window.fcitx.updateStatusArea()
119119
imsToAdd.value = []
120120
}
121+
122+
const onlyShowCurrentLanguage = ref(false)
123+
124+
const filteredLanguageOptions = computed(() => {
125+
if (onlyShowCurrentLanguage.value) {
126+
const currentLanguage = navigator.language.split('-')[0]
127+
return languageOptions.value.filter(({ key }) => key.split('-')[0] === currentLanguage)
128+
}
129+
return languageOptions.value
130+
})
121131
</script>
122132

123133
<template>
@@ -131,12 +141,22 @@ function add() {
131141
@collapse="collapsed = true"
132142
@expand="collapsed = false"
133143
>
134-
<div v-if="adding">
135-
<NMenu
136-
v-model:value="selectedLanguage"
137-
:options="availableInputMethodOptions"
138-
/>
139-
</div>
144+
<NLayout v-if="adding" style="height: 100%">
145+
<NLayout position="absolute" style="bottom: 50px">
146+
<NMenu
147+
v-model:value="selectedLanguage"
148+
:options="filteredLanguageOptions"
149+
/>
150+
</NLayout>
151+
<NLayoutFooter position="absolute">
152+
<NCheckbox
153+
v-model:checked="onlyShowCurrentLanguage"
154+
style="height: 50px; display: flex; justify-content: center; align-items: center"
155+
>
156+
Only show current language
157+
</NCheckbox>
158+
</NLayoutFooter>
159+
</NLayout>
140160
<div
141161
v-else
142162
style="display: flex; flex-direction: column; justify-content: space-between; height: 100%"
@@ -156,7 +176,13 @@ function add() {
156176
</NLayoutSider>
157177
<NLayout style="min-height: 480px; max-height: calc(100vh - 100px)">
158178
<template v-if="adding">
159-
<NLayout position="absolute" style="bottom: 50px; padding: 16px 0 16px 16px">
179+
<div
180+
v-if="selectedLanguage === null"
181+
style="display: flex; justify-content: center; align-items: center; height: calc(100% - 50px);"
182+
>
183+
Select a language from the left list
184+
</div>
185+
<NLayout v-else position="absolute" style="bottom: 50px; padding: 16px 0 16px 16px">
160186
<NCheckboxGroup v-model:value="imsToAdd">
161187
<NFlex vertical>
162188
<NCheckbox

0 commit comments

Comments
 (0)