diff --git a/src/Microsoft.PowerShell.Linux.Host/readline.cs b/src/Microsoft.PowerShell.Linux.Host/readline.cs index 18491c0ce..532d37014 100644 --- a/src/Microsoft.PowerShell.Linux.Host/readline.cs +++ b/src/Microsoft.PowerShell.Linux.Host/readline.cs @@ -59,16 +59,6 @@ namespace Microsoft.PowerShell.Linux.Host /// private System.Collections.Hashtable options = new System.Collections.Hashtable(); - /// - /// Retain original buffer for TabCompletion - /// - private StringBuilder tabBuffer; - - /// - /// tabbuffer for storing result of tabcompletion - /// - private string tabResult; - /// The count of characters in buffer rendered. /// private int rendered; @@ -239,24 +229,20 @@ namespace Microsoft.PowerShell.Linux.Host //if the buffer has been modified in any way, get the new command completion if (previousKeyPress.Key != ConsoleKey.Tab) { - tabBuffer = this.buffer; - cmdCompleteOpt = CommandCompletion.CompleteInput(this.tabBuffer.ToString(), this.current, options, powershell); - } - - try - { - if (tabCompletionPos > cmdCompleteOpt.CompletionMatches.Count || tabCompletionPos == cmdCompleteOpt.CompletionMatches.Count) + cmdCompleteOpt = CommandCompletion.CompleteInput(this.buffer.ToString(), this.current, options, powershell); + if (cmdCompleteOpt.CompletionMatches.Count == 0) { - tabCompletionPos = 1; + return; } + } - tabResult = cmdCompleteOpt.CompletionMatches[tabCompletionPos].CompletionText; - } - catch (Exception) + if (tabCompletionPos >= cmdCompleteOpt.CompletionMatches.Count) { - return; + tabCompletionPos = 0; } + string tabResult = cmdCompleteOpt.CompletionMatches[tabCompletionPos].CompletionText; + tabCompletionPos++; //if there is a command for the user before the uncompleted option @@ -268,30 +254,24 @@ namespace Microsoft.PowerShell.Linux.Host tabResult = tabResult.Replace(".\\", ""); } - if (this.buffer.ToString().Contains(" ")) + var replaceIndex = cmdCompleteOpt.ReplacementIndex; + string replaceBuffer = this.buffer.ToString(); + + if (replaceBuffer.Length < replaceIndex) { - var replaceIndex = cmdCompleteOpt.ReplacementIndex; - string replaceBuffer = this.buffer.ToString(); - - - if (replaceBuffer.Length < replaceIndex) - { - replaceIndex = replaceBuffer.Length; - } - - if (replaceBuffer.Length == replaceIndex) - { - tabResult = replaceBuffer + tabResult; - } - - else - { - replaceBuffer = replaceBuffer.Remove(replaceIndex); - tabResult = replaceBuffer + tabResult; - } - - + replaceIndex = replaceBuffer.Length; } + + if (replaceBuffer.Length == replaceIndex) + { + tabResult = replaceBuffer + tabResult; + } + else + { + replaceBuffer = replaceBuffer.Remove(replaceIndex); + tabResult = replaceBuffer + tabResult; + } + BufferFromString(tabResult); this.Render(); }