Predetermine overflow line breaks

This commit is contained in:
Flashfyre committed 2024-04-06 23:03:20 -04:00
1 parent af3d9cb34c
commit 70a4d54ec9
3 files changed
+19 -3

No files matched your search

+16 -1
View File
@@ -45,8 +45,23 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler {
soundMap.set(actionMatch.index, actionMatch[2]);
break;
}
text = text.slice(0, actionMatch.index) + text.slice(actionMatch.index + actionMatch[2].length + 4);
// Predetermine overflow line breaks to avoid words breaking while displaying
const textWords = text.split(' ');
let lastLineCount = 1;
let newText = textWords[0];
for (let w = 1; w < textWords.length; w++) {
const nextWordText = `${newText} ${textWords[w]}`;
const lineCount = this.message.runWordWrap(nextWordText).split(/\n/g).length;
if (lineCount > lastLineCount) {
lastLineCount = lineCount;
newText = `${newText}\n${textWords[w]}`;
} else
newText = nextWordText;
}
text = newText;
}
if (this.textTimer) {
this.textTimer.remove();