diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/FallbackExecuteItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/FallbackExecuteItem.cs index 2dee80d4e4..6f5efb45fd 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/FallbackExecuteItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/FallbackExecuteItem.cs @@ -154,11 +154,11 @@ internal sealed partial class FallbackExecuteItem : FallbackCommandItem, IDispos else if (pathIsDir) { var pathItem = new PathListItem(exe, query, _addToHistory); + Command = pathItem.Command; + MoreCommands = pathItem.MoreCommands; Title = pathItem.Title; Subtitle = pathItem.Subtitle; Icon = pathItem.Icon; - Command = pathItem.Command; - MoreCommands = pathItem.MoreCommands; } else if (System.Uri.TryCreate(searchText, UriKind.Absolute, out var uri)) { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/Pages/ShellListPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/Pages/ShellListPage.cs index 52e3da1651..fdff707b3a 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/Pages/ShellListPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/Pages/ShellListPage.cs @@ -367,7 +367,7 @@ internal sealed partial class ShellListPage : DynamicListPage, IDisposable } // Easiest case: text is literally already a full directory - else if (Directory.Exists(trimmed)) + else if (Directory.Exists(trimmed) && trimmed.EndsWith('\\')) { directoryPath = trimmed; searchPattern = $"*"; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/PathListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/PathListItem.cs index ba3c7c445c..0ecec3cb2d 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/PathListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Shell/PathListItem.cs @@ -20,15 +20,27 @@ internal sealed partial class PathListItem : ListItem : base(new OpenUrlWithHistoryCommand(path, addToHistory)) { var fileName = Path.GetFileName(path); + if (string.IsNullOrEmpty(fileName)) + { + fileName = Path.GetFileName(Path.GetDirectoryName(path)) ?? string.Empty; + } + _isDirectory = Directory.Exists(path); if (_isDirectory) { - path = path + "\\"; - fileName = fileName + "\\"; + if (!path.EndsWith('\\')) + { + path = path + "\\"; + } + + if (!fileName.EndsWith('\\')) + { + fileName = fileName + "\\"; + } } - Title = fileName; - Subtitle = path; + Title = fileName; // Just the name of the file is the Title + Subtitle = path; // What the user typed is the subtitle // NOTE ME: // If there are spaces on originalDir, trim them off, BEFORE combining originalDir and fileName.