Skip to content

Commit

Permalink
merge changeIME into selectIME
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Jul 16, 2023
1 parent 2d42d59 commit 03541cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
6 changes: 2 additions & 4 deletions src/components/MyDeployer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useNotification } from 'naive-ui'
import { worker } from '../workerAPI'
import {
changeIME,
selectIME,
deployed,
selectOptions,
setLoading
Expand Down Expand Up @@ -48,10 +48,8 @@ worker.control('deployStatus', async (status: 'start' | 'failure' | 'success', s
value: schema.id
})
}
const currentSchema = schemasJson[0].id
await changeIME(currentSchema)
selectIME(schemasJson[0].id)
}
setLoading(false)
break
}
})
Expand Down
31 changes: 9 additions & 22 deletions src/components/MyMenu.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed, watchEffect } from 'vue'
import { computed, watchEffect } from 'vue'
import { NButton, NButtonGroup, NIcon, NSpace, NSelect } from 'naive-ui'
import { WeatherMoon16Regular, Circle16Regular } from '@vicons/fluent'
import {
Expand All @@ -9,6 +9,7 @@ import {
schemaId,
ime,
selectOptions,
showVariant,
variants,
variant,
isEnglish,
Expand All @@ -17,23 +18,17 @@ import {
isEnglishPunctuation,
enableEmoji,
schemaExtended,
setLoading,
changeLanguage,
changeVariant,
changeWidth,
changeCharset,
changePunctuation,
changeEmoji,
changeIME
selectIME
} from '../control'
import { getTextarea, getQueryString } from '../util'
const showVariant = ref<boolean>(false)
init(getQueryString('schemaId'), getQueryString('variantName')).then(() => {
showVariant.value = true
setLoading(false)
})
init(getQueryString('schemaId'), getQueryString('variantName'))
const variantLabel = computed(() => showVariant.value && !deployed.value ? variant.value.name : '')
const singleVariant = computed(() => !deployed.value && variants.value.length === 1)
Expand All @@ -43,15 +38,6 @@ watchEffect(() => {
localStorage.setItem('variantName', variantLabel.value)
})
async function selectIME (targetIME: string) {
resetFocus()
showVariant.value = false
setLoading(true)
await changeIME(targetIME)
showVariant.value = true
setLoading(false)
}
async function switchVariant () {
showVariant.value = false
await changeVariant()
Expand All @@ -68,9 +54,10 @@ function resetFocus () {
getTextarea(props.textareaSelector).focus()
}
defineExpose({
selectIME
})
function onSelectIME (value: string) {
resetFocus()
selectIME(value)
}
</script>

<template>
Expand All @@ -80,7 +67,7 @@ defineExpose({
:value="ime"
:options="selectOptions"
:loading="loading"
@update:value="selectIME"
@update:value="onSelectIME"
/>
<n-button-group
class="square-group"
Expand Down
7 changes: 3 additions & 4 deletions src/components/MyPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
loading,
hideComment,
changeLanguage,
selectIME,
syncOptions
} from '../control'
import { isMobile, getTextarea } from '../util'
Expand All @@ -22,14 +23,12 @@ const props = defineProps<{
text: string
debugMode?: boolean
updateText:(newText: string) => void
onUpdateSchema?: (targetIME: string) => Promise<void>
}>()
const { textareaSelector, updateText } = toRaw(props)
const {
text,
debugMode,
onUpdateSchema
debugMode
} = toRefs(props)
const mouseX = ref<number>(0)
Expand Down Expand Up @@ -174,7 +173,7 @@ async function analyze (result: RIME_RESULT, rimeKey: string) {
editing.value = false
showMenu.value = false
if (result.state === 2 && result.updatedSchema) {
await onUpdateSchema?.value!(result.updatedSchema.split('/')[0])
await selectIME(result.updatedSchema.split('/')[0])
}
if (result.state === 3 && isPrintable(rimeKey)) {
insert(rimeKey)
Expand Down
13 changes: 10 additions & 3 deletions src/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ for (const schema of schemas as {
}
}

const showVariant = ref<boolean>(false)

const variants = computed(() => schemaVariants[schemaId.value])

const variantIndex = computed({
Expand All @@ -176,7 +178,7 @@ async function init (_schemaId: string, variantName: string) {
break
}
}
return changeIME(schemaId.value)
return selectIME(schemaId.value)
}

const isEnglish = ref<boolean>(false)
Expand Down Expand Up @@ -220,7 +222,9 @@ function changeVariant () {
return setVariant()
}

async function changeIME (targetIME: string) {
async function selectIME (targetIME: string) {
showVariant.value = false
setLoading(true)
try {
await setIME(targetIME)
schemaId.value = targetIME
Expand All @@ -240,6 +244,8 @@ async function changeIME (targetIME: string) {
} catch (e) {
console.error(e)
}
showVariant.value = true
setLoading(false)
}

function syncOptions (updatedOptions: string[]) {
Expand Down Expand Up @@ -285,6 +291,7 @@ export {
schemaId,
ime,
selectOptions,
showVariant,
variants,
variant,
isEnglish,
Expand All @@ -301,6 +308,6 @@ export {
changeCharset,
changePunctuation,
changeEmoji,
changeIME,
selectIME,
syncOptions
}
3 changes: 0 additions & 3 deletions src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ async function copyLink () {
textarea.focus()
}
const menu = ref<InstanceType<typeof MyMenu>>()
const panel = ref<InstanceType<typeof MyPanel>>()
const simulator = ref<InstanceType<typeof MySimulator>>()
const editor = ref<InstanceType<typeof MyEditor>>()
Expand Down Expand Up @@ -87,7 +86,6 @@ const AsyncEditor = defineAsyncComponent(() => import('../components/MyEditor.vu
class="my-column"
>
<my-menu
ref="menu"
:textarea-selector="textareaSelector"
/>
<n-input
Expand Down Expand Up @@ -126,7 +124,6 @@ const AsyncEditor = defineAsyncComponent(() => import('../components/MyEditor.vu
:text="text"
:update-text="updateText"
:debug-mode="simulator?.debugMode"
:on-update-schema="menu?.selectIME"
/>
<my-font />
<my-deployer />
Expand Down

0 comments on commit 03541cf

Please sign in to comment.