diff --git a/FIX_PROPOSAL.md b/FIX_PROPOSAL.md new file mode 100644 index 0000000..71d287e --- /dev/null +++ b/FIX_PROPOSAL.md @@ -0,0 +1,28 @@ +To fix the issue, we need to modify the `formatPath()` function in `WelcomeRecentFiles.tsx` to apply max-length truncation even when the path has two or fewer segments. Here's the exact code fix: + +```typescript +function formatPath(path: string, maxLength: number = 60): string { + const normalized = path.replace(/\\/g, '/'); // Normalize slashes + if (normalized.length <= maxLength) { + return normalized; + } + + const parts = normalized.split('/'); + if (parts.length <= 2) { + // Apply max-length truncation + if (normalized.length > maxLength) { + const excess = normalized.length - maxLength; + const middleIndex = Math.floor(normalized.length / 2); + const left = normalized.substring(0, middleIndex - excess / 2); + const right = normalized.substring(middleIndex + excess / 2); + return `${left}...${right}`; + } + return normalized; + } + + // Existing logic for paths with more than two segments + // ... +} +``` + +In this code, we added a check to see if the normalized path is longer than the `maxLength` when there are two or fewer segments. If it is, we apply a middle truncation by removing characters from the middle of the string and replacing them with an ellipsis. This ensures that the displayed path respects the `maxLength` constraint in all branches. \ No newline at end of file