Skip to content

Commit

Permalink
KeyOption
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Sep 4, 2024
1 parent 11556b7 commit a9ace87
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/BasicConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Config } from 'fcitx5-js'
import IntegerOption from './option/IntegerOption.vue'
import BooleanOption from './option/BooleanOption.vue'
import EnumOption from './option/EnumOption.vue'
import KeyOption from './option/KeyOption.vue'
import GroupOption from './option/GroupOption.vue'
import UnknownOption from './option/UnknownOption.vue'
import { isMobile } from './util'
Expand All @@ -26,6 +27,8 @@ function toComponent(child: { Type: string, Children: any[] | null }) {
return BooleanOption
case 'Enum':
return EnumOption
case 'Key':
return KeyOption
default: {
if (child.Children) {
return GroupOption
Expand Down
37 changes: 37 additions & 0 deletions src/option/KeyOption.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { NButton } from 'naive-ui'
const props = defineProps<{
value: string
onUpdate: (value: string) => void
}>()
const recording = ref(false)
const pressed = ref(false)
const label = computed(() => recording.value && !pressed.value ? '' : props.value || '●REC')
function keydown(e: KeyboardEvent) {
pressed.value = true
props.onUpdate(window.fcitx.jsKeyToFcitxString(e))
}
function click() {
recording.value = true
pressed.value = false
}
function blur() {
recording.value = false
}
</script>

<template>
<NButton
@keydown.stop.prevent="keydown"
@click="click"
@blur="blur"
>
{{ label }}
</NButton>
</template>

0 comments on commit a9ace87

Please sign in to comment.