private string GetUnambiguousPrefix(System.Collections.ObjectModel.Collection <CompletionResult> matches, out bool ambiguous) { // Find the longest unambiguous prefix. This might be the empty // string, in which case we don't want to remove any of the users input, // instead we'll immediately show possible completions. // For the purposes of unambiguous prefix, we'll ignore quotes if // some completions aren't quoted. ambiguous = false; var firstResult = matches[0]; bool consistentQuoting = IsConsistentQuoting(matches); var replacementText = GetUnquotedText(firstResult, consistentQuoting); foreach (var match in matches.Skip(1)) { var matchText = GetUnquotedText(match, consistentQuoting); for (int i = 0; i < replacementText.Length; i++) { if (i == matchText.Length || char.ToLowerInvariant(replacementText[i]) != char.ToLowerInvariant(matchText[i])) { ambiguous = true; replacementText = replacementText.Substring(0, i); break; } } if (replacementText.Length == 0) { break; } } if (replacementText.Length == 0) { replacementText = firstResult.ListItemText; foreach (var match in matches.Skip(1)) { var matchText = match.ListItemText; for (int i = 0; i < replacementText.Length; i++) { if (i == matchText.Length || char.ToLowerInvariant(replacementText[i]) != char.ToLowerInvariant(matchText[i])) { ambiguous = true; replacementText = replacementText.Substring(0, i); break; } } if (replacementText.Length == 0) { break; } } } return(replacementText); }