Skip to content

Commit f1df1ce

Browse files
fix: move auto-ruby to an independent entrance (#203)
1 parent f84d55a commit f1df1ce

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

locales/en-US/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@
201201
{
202202
"index": "Per-Word Romanization",
203203
"check": "Check Per-Word Romanization",
204-
"distribute": "Distribute Romanization..."
204+
"distribute": "Distribute Romanization...",
205+
"autoRuby": "Auto Ruby"
205206
},
206207
"help": "Help",
207208
"helpDoc": "Documentation (CN)",

locales/zh-CN/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@
201201
{
202202
"index": "逐字音译",
203203
"check": "检查逐字音译一致性",
204-
"distribute": "自动分配罗马音..."
204+
"distribute": "自动分配罗马音...",
205+
"autoRuby": "自动注音"
205206
},
206207
"help": "帮助",
207208
"helpDoc": "使用说明",

src/components/TopMenu/modals/ToolMenu.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const ToolMenuItems = () => {
4848
</DropdownMenu.Item>
4949
</DropdownMenu.SubContent>
5050
</DropdownMenu.Sub>
51+
<DropdownMenu.Item onSelect={menu.onAutoRuby}>
52+
{t("topBar.menu.perWordRomanization.autoRuby", "自动注音")}
53+
</DropdownMenu.Item>
5154
<DropdownMenu.Item onSelect={menu.onOpenLatencyTest}>
5255
{t("settingsDialog.common.latencyTest", "音频/输入延迟测试")}
5356
</DropdownMenu.Item>

src/components/TopMenu/useTopMenuActions.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ export const useTopMenuActions = () => {
403403
line.words.forEach((word, wordIndex) => {
404404
if (!results[wordIndex]) return;
405405
word.romanWord = results[wordIndex];
406-
applyGeneratedRuby(word);
407406
});
408407
applyRomanizationWarnings(line.words);
409408
} catch (e) {
@@ -413,6 +412,21 @@ export const useTopMenuActions = () => {
413412
});
414413
}, [editLyricLines, store]);
415414

415+
const onAutoRuby = useCallback(() => {
416+
const selectedLines = store.get(selectedLinesAtom);
417+
const hasSelection = selectedLines.size > 0;
418+
editLyricLines((draft) => {
419+
draft.lyricLines.forEach((line) => {
420+
if (hasSelection && !selectedLines.has(line.id)) return;
421+
if (line.words.length === 0) return;
422+
line.words.forEach((word) => {
423+
if (!word.romanWord || word.romanWord.trim() === "") return;
424+
applyGeneratedRuby(word);
425+
});
426+
});
427+
});
428+
}, [editLyricLines, store]);
429+
416430
const onCheckRomanizationWarnings = useCallback(() => {
417431
editLyricLines((draft) => {
418432
for (const line of draft.lyricLines) {
@@ -460,6 +474,7 @@ export const useTopMenuActions = () => {
460474
onOpenAdvancedSegmentation,
461475
onSyncLineTimestamps,
462476
onOpenDistributeRomanization,
477+
onAutoRuby,
463478
onCheckRomanizationWarnings,
464479
onOpenLatencyTest,
465480
onOpenGitHub,

src/modules/project/modals/DistributeRomanization.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { useEffect, useState } from "react";
1414
import { useTranslation } from "react-i18next";
1515
import { predictLineRomanization } from "$/modules/segmentation/utils/Transliteration/distributor";
1616
import { applyRomanizationWarnings } from "$/modules/segmentation/utils/Transliteration/roman-warning";
17-
import { applyGeneratedRuby } from "$/modules/lyric-editor/utils/ruby-generator";
1817
import { distributeRomanizationDialogAtom } from "$/states/dialogs";
1918
import { lyricLinesAtom, selectedLinesAtom } from "$/states/main";
2019

@@ -95,7 +94,6 @@ export const DistributeRomanizationDialog = () => {
9594
line.words.forEach((word, wordIndex) => {
9695
if (results[wordIndex]) {
9796
word.romanWord = results[wordIndex];
98-
applyGeneratedRuby(word);
9997
}
10098
});
10199
applyRomanizationWarnings(line.words);

0 commit comments

Comments
 (0)