Skip to content

Commit a9ace87

Browse files
committed
KeyOption
1 parent 11556b7 commit a9ace87

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/BasicConfig.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Config } from 'fcitx5-js'
55
import IntegerOption from './option/IntegerOption.vue'
66
import BooleanOption from './option/BooleanOption.vue'
77
import EnumOption from './option/EnumOption.vue'
8+
import KeyOption from './option/KeyOption.vue'
89
import GroupOption from './option/GroupOption.vue'
910
import UnknownOption from './option/UnknownOption.vue'
1011
import { isMobile } from './util'
@@ -26,6 +27,8 @@ function toComponent(child: { Type: string, Children: any[] | null }) {
2627
return BooleanOption
2728
case 'Enum':
2829
return EnumOption
30+
case 'Key':
31+
return KeyOption
2932
default: {
3033
if (child.Children) {
3134
return GroupOption

src/option/KeyOption.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup lang="ts">
2+
import { computed, ref } from 'vue'
3+
import { NButton } from 'naive-ui'
4+
5+
const props = defineProps<{
6+
value: string
7+
onUpdate: (value: string) => void
8+
}>()
9+
10+
const recording = ref(false)
11+
const pressed = ref(false)
12+
const label = computed(() => recording.value && !pressed.value ? '' : props.value || '●REC')
13+
14+
function keydown(e: KeyboardEvent) {
15+
pressed.value = true
16+
props.onUpdate(window.fcitx.jsKeyToFcitxString(e))
17+
}
18+
19+
function click() {
20+
recording.value = true
21+
pressed.value = false
22+
}
23+
24+
function blur() {
25+
recording.value = false
26+
}
27+
</script>
28+
29+
<template>
30+
<NButton
31+
@keydown.stop.prevent="keydown"
32+
@click="click"
33+
@blur="blur"
34+
>
35+
{{ label }}
36+
</NButton>
37+
</template>

0 commit comments

Comments
 (0)