Skip to content

Commit

Permalink
IM switch
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Aug 25, 2024
1 parent 715ab07 commit 5643968
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/components/MyContent.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<script setup lang="ts">
// import { ref, onMounted } from 'vue'
import { NInput, NSpace } from 'naive-ui'
import StatusArea from './StatusArea.vue'
// const input = ref<InstanceType<typeof NInput>>()
// onMounted(() => {
// input.value.focus()
// })
</script>

<template>
<NSpace class="my-column" vertical>
<StatusArea />

<NInput
type="textarea"
clearable
Expand Down
23 changes: 23 additions & 0 deletions src/components/StatusArea.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { computed } from 'vue'
import { NSelect, NSpace } from 'naive-ui'
import { inputMethod, inputMethods, loading } from '../fcitx'
const options = computed(() => {
return inputMethods.value.map(({ displayName, name }) => ({
label: displayName,
value: name,
}))
})
</script>

<template>
<NSpace>
<NSelect
v-model:value="inputMethod"
style="width: 220px"
:loading="loading"
:options="options"
/>
</NSpace>
</template>
29 changes: 29 additions & 0 deletions src/fcitx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ref, watch } from 'vue'
import { fcitxReady } from 'fcitx5-js'

export const loading = ref(true)

export const inputMethod = ref('')

watch(inputMethod, (value: string) => {
window.fcitx.setCurrentInputMethod(value)
})

export const inputMethods = ref<{
name: string
displayName: string
}[]>([])

function statusAreaCallback() {
inputMethods.value = window.fcitx.getInputMethods()
inputMethod.value = window.fcitx.currentInputMethod()
}

fcitxReady.then(() => {
window.fcitx.setStatusAreaCallback(statusAreaCallback)
window.fcitx.enable()
window.fcitx.setInputMethods(['keyboard-us', 'pinyin'])
document.querySelector('textarea')?.focus()
window.fcitx.updateStatusArea()
loading.value = false
})
6 changes: 0 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { createApp } from 'vue'
import { fcitxReady } from 'fcitx5-js'
import App from './App.vue'
import './main.css'

fcitxReady.then(() => {
window.fcitx.enable()
window.fcitx.setInputMethods(['pinyin'])
})

createApp(App).mount('#app')

0 comments on commit 5643968

Please sign in to comment.