From 9ef13e5f671e3c356ba5043bf23faceaa0b06086 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sun, 7 Apr 2024 19:11:34 -0400 Subject: [PATCH] Fix crash related to null text --- src/ui/message-ui-handler.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/ui/message-ui-handler.ts b/src/ui/message-ui-handler.ts index 03ed8191c..a0d1b3108 100644 --- a/src/ui/message-ui-handler.ts +++ b/src/ui/message-ui-handler.ts @@ -48,27 +48,29 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { 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]}`; - if (textWords[w].includes('\n')) { - newText = nextWordText; - lastLineCount++; - } else { - const lineCount = this.message.runWordWrap(nextWordText).split(/\n/g).length; - if (lineCount > lastLineCount) { - lastLineCount = lineCount; - newText = `${newText}\n${textWords[w]}`; - } else + if (text) { + // 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]}`; + if (textWords[w].includes('\n')) { newText = nextWordText; + lastLineCount++; + } else { + 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; } - text = newText; - if (this.textTimer) { this.textTimer.remove(); if (this.textCallbackTimer)