mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix directory completion for different file-systems
Use the file-system agnostic `System.IO.Path.DirectorySeparatorChar` for `GetReplacementTextForDirectory`, instead of hard-coded backslashes.
This commit is contained in:
@@ -23,6 +23,9 @@ namespace Microsoft.PowerShell
|
||||
private CommandCompletion _tabCompletions;
|
||||
private Runspace _runspace;
|
||||
|
||||
// String helper for directory paths
|
||||
private static string DirectorySeparatorString = System.IO.Path.DirectorySeparatorChar.ToString();
|
||||
|
||||
// Stub helper method so completion can be mocked
|
||||
#if !CORECLR
|
||||
[ExcludeFromCodeCoverage]
|
||||
@@ -275,21 +278,23 @@ namespace Microsoft.PowerShell
|
||||
|
||||
private static string GetReplacementTextForDirectory(string replacementText, ref int cursorAdjustment)
|
||||
{
|
||||
if (!replacementText.EndsWith("\\", StringComparison.Ordinal))
|
||||
if (!replacementText.EndsWith(DirectorySeparatorString , StringComparison.Ordinal))
|
||||
{
|
||||
if (replacementText.EndsWith("\\'", StringComparison.Ordinal) || replacementText.EndsWith("\\\"", StringComparison.Ordinal))
|
||||
if (replacementText.EndsWith(String.Format("{0}\'", DirectorySeparatorString), StringComparison.Ordinal) ||
|
||||
replacementText.EndsWith(String.Format("{0}\"", DirectorySeparatorString), StringComparison.Ordinal))
|
||||
{
|
||||
cursorAdjustment = -1;
|
||||
}
|
||||
else if (replacementText.EndsWith("'", StringComparison.Ordinal) || replacementText.EndsWith("\"", StringComparison.Ordinal))
|
||||
else if (replacementText.EndsWith("'", StringComparison.Ordinal) ||
|
||||
replacementText.EndsWith("\"", StringComparison.Ordinal))
|
||||
{
|
||||
var len = replacementText.Length;
|
||||
replacementText = replacementText.Substring(0, len - 1) + '\\' + replacementText[len - 1];
|
||||
replacementText = replacementText.Substring(0, len - 1) + System.IO.Path.DirectorySeparatorChar + replacementText[len - 1];
|
||||
cursorAdjustment = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
replacementText = replacementText + '\\';
|
||||
replacementText = replacementText + System.IO.Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
return replacementText;
|
||||
|
||||
Reference in New Issue
Block a user