Skip to content

Commit ebc6c7a

Browse files
feat: add batch ignore for background line (#186)
* feat: add batch ignore for background line * fix: a patch of 5e8485e
1 parent 4314a06 commit ebc6c7a

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/components/RibbonBar/edit-mode.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ const AuxiliaryDisplayField: FC = () => {
545545

546546
export const EditModeRibbonBar: FC = forwardRef<HTMLDivElement>(
547547
(_props, ref) => {
548-
const editLyricLines = useSetAtom(lyricLinesAtom);
548+
const editLyricLines = useSetImmerAtom(lyricLinesAtom);
549549
const { t } = useTranslation();
550550

551551
return (
@@ -556,11 +556,8 @@ export const EditModeRibbonBar: FC = forwardRef<HTMLDivElement>(
556556
size="1"
557557
variant="soft"
558558
onClick={() =>
559-
editLyricLines((prev) => {
560-
return {
561-
...prev,
562-
lyricLines: [...prev.lyricLines, newLyricLine()],
563-
};
559+
editLyricLines((draft) => {
560+
draft.lyricLines.push(newLyricLine());
564561
})
565562
}
566563
>
@@ -588,9 +585,9 @@ export const EditModeRibbonBar: FC = forwardRef<HTMLDivElement>(
588585
<Grid columns="0fr 0fr" gap="4" gapY="1" flexGrow="1" align="center">
589586
<CheckboxField
590587
label={t("ribbonBar.editMode.bgLyric", "背景歌词")}
588+
defaultValue={false}
591589
isWordField={false}
592590
fieldName="isBG"
593-
defaultValue={false}
594591
/>
595592
<CheckboxField
596593
label={t("ribbonBar.editMode.duetLyric", "对唱歌词")}

src/components/RibbonBar/sync-mode.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
keySyncNextAtom,
2929
keySyncStartAtom,
3030
} from "$/states/keybindings.ts";
31+
import { bgLyricIgnoreSyncAtom, lyricLinesAtom } from "$/states/main.ts";
3132
import {
3233
Checkbox,
3334
Flex,
@@ -37,6 +38,7 @@ import {
3738
TextField,
3839
} from "@radix-ui/themes";
3940
import { useAtom, useAtomValue } from "jotai";
41+
import { useSetImmerAtom } from "jotai-immer";
4042
import { type FC, forwardRef } from "react";
4143
import { useTranslation } from "react-i18next";
4244
import { KeyBinding } from "../KeyBinding/index.tsx";
@@ -84,6 +86,10 @@ export const SyncModeRibbonBar: FC = forwardRef<HTMLDivElement>(
8486
const [displayRomanizationInSync, setdisplayRomanizationInSync] = useAtom(
8587
displayRomanizationInSyncAtom,
8688
);
89+
const [bgLyricIgnoreSync, setBgLyricIgnoreSync] = useAtom(
90+
bgLyricIgnoreSyncAtom,
91+
);
92+
const editLyricLines = useSetImmerAtom(lyricLinesAtom);
8793
const showWordRomanizationInput = useAtomValue(
8894
showWordRomanizationInputAtom,
8995
);
@@ -140,6 +146,27 @@ export const SyncModeRibbonBar: FC = forwardRef<HTMLDivElement>(
140146
checked={showTouchSyncPanel}
141147
onCheckedChange={(v) => setShowTouchSyncPanel(!!v)}
142148
/>
149+
<Text wrap="nowrap" size="1">
150+
{t(
151+
"ribbonBar.syncMode.bgLyricIgnoreSync",
152+
"背景歌词忽略打轴",
153+
)}
154+
</Text>
155+
<Checkbox
156+
checked={bgLyricIgnoreSync}
157+
onCheckedChange={(v) => {
158+
const next = !!v;
159+
setBgLyricIgnoreSync(next);
160+
editLyricLines((state) => {
161+
for (const line of state.lyricLines) {
162+
if (line.isBG) {
163+
line.ignoreSync = next;
164+
}
165+
}
166+
return state;
167+
});
168+
}}
169+
/>
143170
</Grid>
144171
</RibbonSection>
145172
<RibbonSection

src/states/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export const showUnselectedLinesAtom = atomWithStorage(
124124
"showUnselectedLines",
125125
true,
126126
);
127+
export const bgLyricIgnoreSyncAtom = atom(false);
127128

128129
export interface EditingTimeFieldState {
129130
isWord: boolean;

0 commit comments

Comments
 (0)