From f595b3437470ab9fa04f4afaf38916a40743c352 Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Tue, 22 Dec 2015 12:32:56 -0800 Subject: [PATCH] Fixed tabcompletion index issue with buffer ending in whitespace --- .../readline.cs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Linux.Host/readline.cs b/src/Microsoft.PowerShell.Linux.Host/readline.cs index 718a71b392..da77f4fa25 100644 --- a/src/Microsoft.PowerShell.Linux.Host/readline.cs +++ b/src/Microsoft.PowerShell.Linux.Host/readline.cs @@ -259,7 +259,7 @@ namespace Microsoft.PowerShell.Linux.Host } tabCompletionPos++; - + //if there is a command for the user before the uncompleted option if (!String.IsNullOrEmpty(tabResult)) { @@ -270,18 +270,33 @@ namespace Microsoft.PowerShell.Linux.Host } if (this.buffer.ToString().Contains(" ")) - { + { var replaceIndex = cmdCompleteOpt.ReplacementIndex; string replaceBuffer = this.buffer.ToString(); - replaceBuffer = replaceBuffer.Remove(replaceIndex); - tabResult = replaceBuffer + tabResult; - } + //test + if (replaceBuffer.Length < replaceIndex) + { + replaceIndex = replaceBuffer.Length; + } + + if (replaceBuffer.Length == replaceIndex) + { + tabResult = replaceBuffer + tabResult; + } + + else + { + replaceBuffer = replaceBuffer.Remove(replaceIndex); + tabResult = replaceBuffer + tabResult; + } + - BufferFromString(tabResult); - this.Render(); + BufferFromString(tabResult); + this.Render(); + } } - + } //end of OnTab() ///