|
10 | 10 | using System.Diagnostics.CodeAnalysis; |
11 | 11 | using System.Globalization; |
12 | 12 | using System.Linq; |
13 | | -using System.Runtime.InteropServices; |
14 | 13 | using System.Management.Automation; |
15 | 14 | using System.Management.Automation.Runspaces; |
16 | 15 | using Microsoft.PowerShell.Internal; |
@@ -300,17 +299,27 @@ private CommandCompletion GetCompletions() |
300 | 299 | if (start < 0 || start > _singleton._buffer.Length) return null; |
301 | 300 | if (length < 0 || length > (_singleton._buffer.Length - start)) return null; |
302 | 301 |
|
303 | | - // Only filter out duplicates on Windows. |
304 | | - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && _tabCompletions.CompletionMatches.Count > 1) |
| 302 | + if (_tabCompletions.CompletionMatches.Count > 1) |
305 | 303 | { |
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; |
308 | 308 |
|
309 | | - foreach (var match in _tabCompletions.CompletionMatches.ToArray()) |
| 309 | + for (int i = 0; i < matches.Count; i++) |
310 | 310 | { |
311 | | - if (!hashSet.Add(match.ListItemText)) |
| 311 | + if (!hashSet.Add(matches[i].ListItemText)) |
312 | 312 | { |
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]); |
314 | 323 | } |
315 | 324 | } |
316 | 325 | } |
|
0 commit comments