diff --git a/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs b/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs index a1e425de5286..069839c9ba53 100644 --- a/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs +++ b/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs @@ -302,7 +302,7 @@ private static PathBoxItem GetPathItem(string component, string path) private static string GetPathWithoutEnvironmentVariable(string path) { - if (path.StartsWith("~\\", StringComparison.Ordinal)) + if (path.StartsWith("~\\", StringComparison.Ordinal) || path.StartsWith("~/", StringComparison.Ordinal) || path.Equals("~", StringComparison.Ordinal)) path = $"{Constants.UserEnvironmentPaths.HomePath}{path.Remove(0, 1)}"; path = path.Replace("%temp%", Constants.UserEnvironmentPaths.TempPath, StringComparison.OrdinalIgnoreCase); diff --git a/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs index 5b14ef081e20..2ed74653d064 100644 --- a/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs @@ -664,6 +664,19 @@ public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem p } } + private static string NormalizePathInput(string currentInput, bool isFtp) + { + if (currentInput.Contains('/') && !isFtp) + currentInput = currentInput.Replace("/", "\\", StringComparison.Ordinal); + + currentInput = currentInput.Replace("\\\\", "\\", StringComparison.Ordinal); + + if (currentInput.StartsWith('\\') && !currentInput.StartsWith("\\\\", StringComparison.Ordinal)) + currentInput = currentInput.Insert(0, "\\"); + + return currentInput; + } + public async Task CheckPathInputAsync(string currentInput, string currentSelectedPath, IShellPage shellPage) { if (currentInput.StartsWith('>')) @@ -685,13 +698,7 @@ await DialogDisplayHelper.ShowDialogAsync("CommandNotExecutable".GetLocalizedRes var isFtp = FtpHelpers.IsFtpPath(currentInput); - if (currentInput.Contains('/') && !isFtp) - currentInput = currentInput.Replace("/", "\\", StringComparison.Ordinal); - - currentInput = currentInput.Replace("\\\\", "\\", StringComparison.Ordinal); - - if (currentInput.StartsWith('\\') && !currentInput.StartsWith("\\\\", StringComparison.Ordinal)) - currentInput = currentInput.Insert(0, "\\"); + currentInput = NormalizePathInput(currentInput, isFtp); if (currentSelectedPath == currentInput || string.IsNullOrWhiteSpace(currentInput)) return; @@ -810,8 +817,10 @@ public async Task SetAddressBarSuggestionsAsync(AutoSuggestBox sender, IShellPag else { IsCommandPaletteOpen = false; - var isFtp = FtpHelpers.IsFtpPath(sender.Text); - var expandedPath = StorageFileExtensions.GetResolvedPath(sender.Text, isFtp); + var currentInput = sender.Text; + var isFtp = FtpHelpers.IsFtpPath(currentInput); + currentInput = NormalizePathInput(currentInput, isFtp); + var expandedPath = StorageFileExtensions.GetResolvedPath(currentInput, isFtp); var folderPath = PathNormalization.GetParentDir(expandedPath) ?? expandedPath; StorageFolderWithPath folder = await shellpage.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);