Skip to content

Feature: Recognize Tilde as %USERPROFILE% #14171

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 18 additions & 9 deletions src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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('>'))
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down