mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-23 02:27:29 +00:00
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:
parent
325b1a1441
commit
abc812e579
@ -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))
|
||||||
{
|
{
|
||||||
|
@ -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 = $"*";
|
||||||
|
@ -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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user