Skip to content

Commit cecd32b

Browse files
committed
FEATURE: delete caption in editor
1 parent 50257d4 commit cecd32b

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

dist/editor/index.js

+41-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/editor/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/editor/captions.service.ts

+23
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export class KaraokeGroup {
5050
return this.words.pop()!;
5151
}
5252

53+
public shiftIndices(shift: number) {
54+
this.indexStart += shift;
55+
this.indexEnd += shift;
56+
}
57+
5358
public get id() {
5459
return `${this.indexStart}-${this.indexEnd}`;
5560
}
@@ -129,6 +134,24 @@ export class CaptionsService {
129134
}
130135
}
131136

137+
public deleteKaraokeGroup(karaokeGroupId: string) {
138+
const groups: KaraokeGroup[] = [];
139+
let shift = 0;
140+
141+
for (const group of this.groups) {
142+
if (group.id === karaokeGroupId) {
143+
shift = group.indexStart - group.indexEnd - 1;
144+
} else {
145+
if (~shift) {
146+
group.shiftIndices(shift);
147+
}
148+
groups.push(group);
149+
}
150+
}
151+
152+
this.groups = groups;
153+
}
154+
132155
public get karaokeGroups(): KaraokeGroup[] {
133156
return [...this.groups];
134157
}

src/editor/components/cue.component.vue

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const props = defineProps<{ karaokeGroup: KaraokeGroup }>();
1010
defineEmits<{
1111
(event: 'move-word-to-prec', value: KaraokeWord): void;
1212
(event: 'move-word-to-next', value: KaraokeWord): void;
13+
(event: 'delete', value: string): void;
1314
}>();
1415
1516
const timecodeStart = new Timecode(props.karaokeGroup.startTimeMs);
@@ -23,6 +24,14 @@ const millisChanged = timecodeStart.millis !== timecodeEnd.millis;
2324

2425
<template>
2526
<tr>
27+
<td>
28+
<button class="button is-small is-danger"
29+
@click="$emit('delete', karaokeGroup.id);">
30+
<span class="icon is-small">
31+
<i class="fas fa-times"></i>
32+
</span>
33+
</button>
34+
</td>
2635
<td>
2736
<indexes v-bind="{ karaokeGroup: karaokeGroup }"></indexes>
2837
</td>

src/editor/components/subtitles-table.component.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ function moveLastWordToNextGroup(groupId: number) {
2323
captionService.moveLastWordToNextGroup(groupId);
2424
groups.value = captionService.karaokeGroups;
2525
}
26+
27+
function deleteKaraokeGroup(karaokeGroupId: string) {
28+
captionService.deleteKaraokeGroup(karaokeGroupId);
29+
groups.value = captionService.karaokeGroups;
30+
}
2631
</script>
2732

2833
<template>
2934
<table class="table is-fullwidth is-hoverable">
3035
<thead>
3136
<tr class="is-link">
37+
<th style="width: 3%"></th>
3238
<th class="has-text-white" style="width: 5%">Indexes</th>
3339
<th class="has-text-white" style="width: 15%">Start</th>
3440
<th class="has-text-white" style="width: 15%">End</th>
@@ -41,7 +47,8 @@ function moveLastWordToNextGroup(groupId: number) {
4147
:key="karaokeGroup.id"
4248
:karaoke-group="karaokeGroup"
4349
@move-word-to-prec="moveFirstWordToPrecedentGroup(index)"
44-
@move-word-to-next="moveLastWordToNextGroup(index)"></cue>
50+
@move-word-to-next="moveLastWordToNextGroup(index)"
51+
@delete="deleteKaraokeGroup(karaokeGroup.id)"></cue>
4552
</tbody>
4653
</table>
4754
</template>

0 commit comments

Comments
 (0)