From 1333149d2581817eb56e86b6ad466971b71e3ee5 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Sun, 1 Jun 2025 22:27:15 -0700 Subject: [PATCH] Fix: Set max window title size to 300 to prevent crashing. (#977) --- .../bar/modules/window_title/helpers/title.ts | 18 +++++++++++++----- .../settings/pages/config/bar/index.tsx | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/bar/modules/window_title/helpers/title.ts b/src/components/bar/modules/window_title/helpers/title.ts index 8fc42af..0898334 100644 --- a/src/components/bar/modules/window_title/helpers/title.ts +++ b/src/components/bar/modules/window_title/helpers/title.ts @@ -92,13 +92,21 @@ export const getTitle = ( * If the title exceeds the maximum size, it appends an ellipsis ('...') to the truncated title. * * @param title The title string to truncate. - * @param max_size The maximum size of the truncated title. + * @param maxSize The maximum size of the truncated title. * * @returns The truncated title as a string. If the title is within the maximum size, returns the original title. */ -export const truncateTitle = (title: string, max_size: number): string => { - if (max_size > 0 && title.length > max_size) { - return title.substring(0, max_size).trim() + '...'; +export const truncateTitle = (title: string | null, maxSize: number): string => { + if (title === null) { + return '--'; } - return title; + + const MAX_LABEL_SIZE = 300; + const effectiveSize = maxSize <= 0 ? MAX_LABEL_SIZE : Math.min(maxSize, MAX_LABEL_SIZE); + + if (title.length <= effectiveSize) { + return title; + } + + return title.substring(0, effectiveSize).trim() + '...'; }; diff --git a/src/components/settings/pages/config/bar/index.tsx b/src/components/settings/pages/config/bar/index.tsx index b6377c4..8bba498 100644 --- a/src/components/settings/pages/config/bar/index.tsx +++ b/src/components/settings/pages/config/bar/index.tsx @@ -381,6 +381,7 @@ export const BarSettings = (): JSX.Element => { title="Truncation Size" type="number" min={10} + max={300} />