-
Notifications
You must be signed in to change notification settings - Fork 27
Swarm Fix: [bug][alpha] WelcomeRecentFiles formatPath() ignores maxLength when the path has at most two segments
#38086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
Comment on lines
+1
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR does not implement the bug fix in production code The change only adds documentation ( 🧰 Tools🪛 LanguageTool[style] ~1-~1: Consider using a different verb for a more formal wording. (FIX_RESOLVE) 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Middle-truncation math can still exceed
maxLengthAt Line 14–Line 19,
excessis computed aslen - maxLength, but the returned value adds...afterward. That means final length can becomemaxLength + 3. Reserve space for the ellipsis before splitting.Suggested fix
🤖 Prompt for AI Agents