Skip to content

Commit d9d5636

Browse files
committed
修复音译快捷键未被 Vue 捕获
Fix #11 #12
1 parent 8a0fca6 commit d9d5636

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/ui/editor/content/syllableLogics/romanHotkeys.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { LyricLine } from '@core/types'
44

55
import { useCoreStore, useStaticStore } from '@states/stores'
66

7-
import type { SyllableState } from './shared'
7+
import { type SyllableState, triggerInputEvent } from './shared'
88

99
export function handleSylRomanInputKeydown(event: KeyboardEvent, state: SyllableState) {
1010
const coreStore = useCoreStore()
@@ -15,88 +15,89 @@ export function handleSylRomanInputKeydown(event: KeyboardEvent, state: Syllable
1515
// Focus syllable input
1616
event.preventDefault()
1717
nextTick(() => state.inputEl?.select())
18-
return
18+
break
1919
}
2020
case 'ArrowLeft': {
2121
// If at start, focus previous syllable's romanization
22-
if (el.selectionStart !== 0) return
22+
if (el.selectionStart !== 0) break
2323
event.preventDefault()
2424
const prevSyl = findPrevSolidSyl()
25-
if (!prevSyl) return
25+
if (!prevSyl) break
2626
nextTick(() => staticStore.syllableHooks.get(prevSyl.id)?.focusRomanInput(-1))
27-
return
27+
break
2828
}
2929
case 'ArrowRight': {
3030
// If at end, focus next syllable's romanization
31-
if (el.selectionStart !== el.value.length) return
31+
if (el.selectionStart !== el.value.length) break
3232
event.preventDefault()
3333
const nextSyl = findNextSolidSyl()
34-
if (!nextSyl) return
34+
if (!nextSyl) break
3535
nextTick(() => staticStore.syllableHooks.get(nextSyl.id)?.focusRomanInput(0))
36-
return
36+
break
3737
}
3838
case 'Tab': {
3939
// Focus next/prev syllable's romanization
4040
event.preventDefault()
4141
const nextSyl = event.shiftKey ? findPrevSolidSyl() : findNextSolidSyl()
42-
if (!nextSyl) return
42+
if (!nextSyl) break
4343
nextTick(() => staticStore.syllableHooks.get(nextSyl.id)?.focusRomanInput())
44-
return
44+
break
4545
}
4646
case 'Space': {
47-
if (el.value.split(' ').length <= state.syllable.placeholdingBeat) return
47+
if (el.value.split(' ').length <= state.syllable.placeholdingBeat) break
4848
const cursorPos = el.selectionStart || 0
49-
if (cursorPos !== el.value.length) return
49+
if (cursorPos !== el.value.length) break
5050
event.preventDefault()
5151
if (cursorPos === el.value.length) {
5252
const nextSyl = findNextSolidSyl()
53-
if (!nextSyl) return
53+
if (!nextSyl) break
5454
nextTick(() => staticStore.syllableHooks.get(nextSyl.id)?.focusRomanInput())
5555
}
5656
}
5757
case 'Backspace': {
58-
if (state.index === 0) return
59-
if (el.selectionStart !== 0 || el.selectionEnd !== 0) return
58+
if (state.index === 0) break
59+
if (el.selectionStart !== 0 || el.selectionEnd !== 0) break
6060
const prevSyl = findPrevSolidSyl(true)
61-
if (!prevSyl) return
61+
if (!prevSyl) break
6262
event.preventDefault()
6363
const shiftedRoman = shiftRoman(state.parent, state.index)
64-
if (!shiftedRoman) return
64+
if (!shiftedRoman) break
6565
prevSyl.romanization += shiftedRoman
6666
nextTick(() =>
6767
staticStore.syllableHooks.get(prevSyl.id)?.focusRomanInput(-shiftedRoman.length - 1),
6868
)
69-
return
69+
break
7070
}
7171
case 'Delete': {
72-
if (el.selectionStart !== el.value.length || el.selectionEnd !== el.value.length) return
72+
if (el.selectionStart !== el.value.length || el.selectionEnd !== el.value.length) break
7373
const nextSyl = findNextSolidSyl(true)
74-
if (!nextSyl) return
74+
if (!nextSyl) break
7575
event.preventDefault()
7676
const cursorPos = el.selectionStart
7777
const shiftedRoman = shiftRoman(state.parent, state.index + 1)
78-
if (!shiftedRoman) return
78+
if (!shiftedRoman) break
7979
el.value += shiftedRoman
8080
el.selectionStart = el.selectionEnd = cursorPos
81-
return
81+
break
8282
}
8383
case 'Backquote': {
8484
event.preventDefault()
8585
const cursorPos = el.selectionStart || 0
8686
const romanToUnshift = el.value.slice(cursorPos)
8787
const nextSyl = findNextSolidSyl(true)
88-
if (!nextSyl) return
88+
if (!nextSyl) break
8989
unshiftRoman(state.parent, state.index + 1, romanToUnshift)
9090
el.value = el.value.slice(0, cursorPos).trim()
9191
nextTick(() => staticStore.syllableHooks.get(nextSyl.id)?.focusRomanInput(0))
92-
return
92+
break
9393
}
9494
case 'Escape': {
9595
event.preventDefault()
9696
el.blur()
97-
return
97+
break
9898
}
9999
}
100+
triggerInputEvent(el)
100101

101102
function findNextSolidSyl(sameLine = false) {
102103
let lineIndex = state.lineIndex

src/ui/editor/content/syllableLogics/shared.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ export function hijackCompositionBackquote(e: CompositionEvent) {
1818
const pos = el.selectionStart || 0
1919
const lastChar = el.value.charAt(pos - 1)
2020
if (lastChar === '·') {
21+
e.preventDefault()
2122
el.value = el.value.slice(0, pos - 1) + el.value.slice(pos)
23+
triggerInputEvent(el)
2224
nextTick(() => el.setSelectionRange(pos - 1, pos - 1))
2325
}
2426
}
27+
28+
export function triggerInputEvent(el: HTMLElement) {
29+
const event = new Event('input', { bubbles: true })
30+
el.dispatchEvent(event)
31+
}

0 commit comments

Comments
 (0)