From 0499cf7cb61f1ff2dd0547d2ccaeddd1b0f2d78c Mon Sep 17 00:00:00 2001 From: Stu Leak Date: Thu, 4 Dec 2025 01:41:46 -0500 Subject: [PATCH] Add smart filename truncation in Compare module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents long filenames from manipulating window size: - Truncate filenames longer than 35 characters - Smart truncation preserves file extension - Format: "long-filename-na...mp4" instead of wrapping - Falls back to simple truncation for very long extensions - Removed text wrapping from labels (no longer needed) Examples: - "my-very-long-video-filename.mp4" → "my-very-long-video-fi....mp4" - "short.mp4" → "short.mp4" (unchanged) - "filename.mkv" → kept as-is if under 35 chars This ensures the Compare module labels stay compact and predictable regardless of filename length. --- main.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 662c6d8..1bc9126 100644 --- a/main.go +++ b/main.go @@ -5449,10 +5449,34 @@ func buildCompareView(state *appState) fyne.CanvasObject { } } + // Helper to truncate filename if too long + truncateFilename := func(filename string, maxLen int) string { + if len(filename) <= maxLen { + return filename + } + // Keep extension visible + ext := filepath.Ext(filename) + nameWithoutExt := strings.TrimSuffix(filename, ext) + + // If extension is too long, just truncate the whole thing + if len(ext) > 10 { + return filename[:maxLen-3] + "..." + } + + // Truncate name but keep extension + availableLen := maxLen - len(ext) - 3 // 3 for "..." + if availableLen < 1 { + return filename[:maxLen-3] + "..." + } + return nameWithoutExt[:availableLen] + "..." + ext + } + // Helper to update file display updateFile1 := func() { if state.compareFile1 != nil { - file1Label.SetText(fmt.Sprintf("File 1: %s", filepath.Base(state.compareFile1.Path))) + filename := filepath.Base(state.compareFile1.Path) + displayName := truncateFilename(filename, 35) + file1Label.SetText(fmt.Sprintf("File 1: %s", displayName)) file1Info.SetText(formatMetadata(state.compareFile1)) loadThumbnail(state.compareFile1, file1Thumbnail) } else { @@ -5465,7 +5489,9 @@ func buildCompareView(state *appState) fyne.CanvasObject { updateFile2 := func() { if state.compareFile2 != nil { - file2Label.SetText(fmt.Sprintf("File 2: %s", filepath.Base(state.compareFile2.Path))) + filename := filepath.Base(state.compareFile2.Path) + displayName := truncateFilename(filename, 35) + file2Label.SetText(fmt.Sprintf("File 2: %s", displayName)) file2Info.SetText(formatMetadata(state.compareFile2)) loadThumbnail(state.compareFile2, file2Thumbnail) } else { @@ -5520,10 +5546,6 @@ func buildCompareView(state *appState) fyne.CanvasObject { }, state.window) }) - // Enable text wrapping on file labels to prevent window stretching - file1Label.Wrapping = fyne.TextWrapBreak - file2Label.Wrapping = fyne.TextWrapBreak - // File 1 header (label + button) file1Header := container.NewVBox( file1Label,