From ff56a2fa5e17500b0e1dfa9b5e0371b34f1dd0c3 Mon Sep 17 00:00:00 2001 From: Jake <134332787+justjxke@users.noreply.github.com> Date: Mon, 16 Feb 2026 06:49:46 +0000 Subject: [PATCH] fix/Quoter (#783) * add linebreak + fix filename truncating if the first word is too many characters long * best pr of all time --- src/equicordplugins/quoter/utils.tsx | 32 ++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/equicordplugins/quoter/utils.tsx b/src/equicordplugins/quoter/utils.tsx index faf83dd6f..44fcf7cba 100644 --- a/src/equicordplugins/quoter/utils.tsx +++ b/src/equicordplugins/quoter/utils.tsx @@ -46,7 +46,8 @@ export function fixUpQuote(quote: string): string { export function generateFileNamePreview(message: string): string { const words = message.split(" "); - return words.length > 6 ? words.slice(0, 6).join(" ") : words.join(" "); + const preview = words.length > 6 ? words.slice(0, 6).join(" ") : words.join(" "); + return preview.slice(0, 10); } export function getFileExtension(saveAsGif: boolean): string { @@ -153,12 +154,31 @@ function calculateTextLines( let currentLine: string[] = []; words.forEach(word => { - const testLine = [...currentLine, word].join(" "); - if (ctx.measureText(testLine).width > maxWidth && currentLine.length) { - lines.push(currentLine.join(" ")); - currentLine = [word]; + if (ctx.measureText(word).width > maxWidth) { + if (currentLine.length) { + lines.push(currentLine.join(" ")); + currentLine = []; + } + + let chunk = ""; + for (const char of word) { + const testChunk = chunk + char; + if (ctx.measureText(testChunk).width > maxWidth) { + if (chunk) lines.push(chunk); + chunk = char; + } else { + chunk = testChunk; + } + } + if (chunk) lines.push(chunk); } else { - currentLine.push(word); + const testLine = [...currentLine, word].join(" "); + if (ctx.measureText(testLine).width > maxWidth && currentLine.length) { + lines.push(currentLine.join(" ")); + currentLine = [word]; + } else { + currentLine.push(word); + } } });