CmdPal: Fix paths to dirs on the Run fallback (#40850)

We were being too clever with `\`; and yet simultaneously not clever
enough.
* When we saw `c:\users`, we'd treat that as a path with a Title
`users\`
* but when we saw `c:\users\`, we'd fail to find a file name, and the
just treat the name as `\`. That was dumb.
* And we'd add trailing `\`'s even if there already was one.
* But then if the user typed `c:\users`, we would immediately start
enumerating children of that dir, which didn't really feel right

This PR fixes all of that.

Closes #40797
This commit is contained in:
Mike Griese 2025-07-28 18:50:33 -05:00 committed by GitHub
parent 325b1a1441
commit abc812e579
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View File

@ -154,11 +154,11 @@ internal sealed partial class FallbackExecuteItem : FallbackCommandItem, IDispos
else if (pathIsDir) else if (pathIsDir)
{ {
var pathItem = new PathListItem(exe, query, _addToHistory); var pathItem = new PathListItem(exe, query, _addToHistory);
Command = pathItem.Command;
MoreCommands = pathItem.MoreCommands;
Title = pathItem.Title; Title = pathItem.Title;
Subtitle = pathItem.Subtitle; Subtitle = pathItem.Subtitle;
Icon = pathItem.Icon; Icon = pathItem.Icon;
Command = pathItem.Command;
MoreCommands = pathItem.MoreCommands;
} }
else if (System.Uri.TryCreate(searchText, UriKind.Absolute, out var uri)) else if (System.Uri.TryCreate(searchText, UriKind.Absolute, out var uri))
{ {

View File

@ -367,7 +367,7 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable
} }
// Easiest case: text is literally already a full directory // Easiest case: text is literally already a full directory
else if (Directory.Exists(trimmed)) else if (Directory.Exists(trimmed) && trimmed.EndsWith('\\'))
{ {
directoryPath = trimmed; directoryPath = trimmed;
searchPattern = $"*"; searchPattern = $"*";

View File

@ -20,15 +20,27 @@ internal sealed partial class PathListItem : ListItem
: base(new OpenUrlWithHistoryCommand(path, addToHistory)) : base(new OpenUrlWithHistoryCommand(path, addToHistory))
{ {
var fileName = Path.GetFileName(path); var fileName = Path.GetFileName(path);
if (string.IsNullOrEmpty(fileName))
{
fileName = Path.GetFileName(Path.GetDirectoryName(path)) ?? string.Empty;
}
_isDirectory = Directory.Exists(path); _isDirectory = Directory.Exists(path);
if (_isDirectory) if (_isDirectory)
{ {
path = path + "\\"; if (!path.EndsWith('\\'))
fileName = fileName + "\\"; {
path = path + "\\";
}
if (!fileName.EndsWith('\\'))
{
fileName = fileName + "\\";
}
} }
Title = fileName; Title = fileName; // Just the name of the file is the Title
Subtitle = path; Subtitle = path; // What the user typed is the subtitle
// NOTE ME: // NOTE ME:
// If there are spaces on originalDir, trim them off, BEFORE combining originalDir and fileName. // If there are spaces on originalDir, trim them off, BEFORE combining originalDir and fileName.