Skip to content

Commit 4bfc4e9

Browse files
authored
Make tab completion show results whose ListItemText are different by case only (#3456)
1 parent c8db4f5 commit 4bfc4e9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

PSReadLine/Completion.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Diagnostics.CodeAnalysis;
1111
using System.Globalization;
1212
using System.Linq;
13-
using System.Runtime.InteropServices;
1413
using System.Management.Automation;
1514
using System.Management.Automation.Runspaces;
1615
using Microsoft.PowerShell.Internal;
@@ -300,17 +299,27 @@ private CommandCompletion GetCompletions()
300299
if (start < 0 || start > _singleton._buffer.Length) return null;
301300
if (length < 0 || length > (_singleton._buffer.Length - start)) return null;
302301

303-
// Only filter out duplicates on Windows.
304-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && _tabCompletions.CompletionMatches.Count > 1)
302+
if (_tabCompletions.CompletionMatches.Count > 1)
305303
{
306-
// Filter out apparent duplicates
307-
var hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
304+
// Filter out apparent duplicates -- the 'ListItemText' is exactly the same.
305+
var hashSet = new HashSet<string>();
306+
var matches = _tabCompletions.CompletionMatches;
307+
List<int> indices = null;
308308

309-
foreach (var match in _tabCompletions.CompletionMatches.ToArray())
309+
for (int i = 0; i < matches.Count; i++)
310310
{
311-
if (!hashSet.Add(match.ListItemText))
311+
if (!hashSet.Add(matches[i].ListItemText))
312312
{
313-
_tabCompletions.CompletionMatches.Remove(match);
313+
indices ??= new List<int>();
314+
indices.Add(i);
315+
}
316+
}
317+
318+
if (indices is not null)
319+
{
320+
for (int i = indices.Count - 1; i >= 0; i--)
321+
{
322+
matches.RemoveAt(indices[i]);
314323
}
315324
}
316325
}

0 commit comments

Comments
 (0)