Skip to content

Commit 428df0a

Browse files
committed
Fixed an issue where changed speaker names were not properly shown #6
1 parent 63e1643 commit 428df0a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/dialogs.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class YesterdayDialog extends MarkdownRenderChild {
3636
];
3737

3838
allSpeakers: Set<string> = new Set();
39-
spokenYet: Set<string> = new Set();
39+
lastSpeakerByType: Map<string, string> = new Map();
4040
lastSpeaker: string = null;
4141
lastLineElement: HTMLLIElement = null;
4242

@@ -48,6 +48,8 @@ export class YesterdayDialog extends MarkdownRenderChild {
4848
onload() {
4949
this.speakersMap.clear();
5050
this.allSpeakers.clear();
51+
this.lastSpeakerByType.clear();
52+
5153
let lines = this.text.split("\n.");
5254
lines = lines.map((entry, index) => (index === 0 ? entry : '.' + entry));
5355

@@ -93,7 +95,8 @@ export class YesterdayDialog extends MarkdownRenderChild {
9395
if (!speaker) return null; // Skip lines without a speaker
9496

9597
const dialogType = this.speakersMap.get(speaker.toLowerCase()) || "their-dialog";
96-
const showSpeaker = !this.spokenYet.has(speaker.toLowerCase());
98+
const lastSpeakerOfType = this.lastSpeakerByType.get(dialogType);
99+
const showSpeaker = !lastSpeakerOfType || lastSpeakerOfType !== speaker.toLowerCase();
97100
const hasComment = comment !== "";
98101

99102
const line = document.createElement("li");
@@ -129,7 +132,8 @@ export class YesterdayDialog extends MarkdownRenderChild {
129132

130133
statementElement.innerHTML = statement.replace(/\n/g, "<br>");
131134
line.appendChild(statementElement);
132-
this.spokenYet.add(speaker.toLowerCase());
135+
136+
this.lastSpeakerByType.set(dialogType, speaker.toLowerCase());
133137

134138
if (this.lastSpeaker && this.lastSpeaker !== speaker) {
135139
if (this.lastLineElement) {
@@ -160,4 +164,4 @@ export class YesterdayDialog extends MarkdownRenderChild {
160164

161165
return emojiRegex.test(str);
162166
}
163-
}
167+
}

0 commit comments

Comments
 (0)