fix/Quoter (#783)

* add linebreak + fix filename truncating if the first word is too many
characters long

* best pr of all time
This commit is contained in:
Jake 2026-02-16 06:49:46 +00:00 • committed by GitHub
parent d0c9dce310
commit ff56a2fa5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}
}
});