Skip to content

Conversation

@jianyunt
Copy link
Contributor

@jianyunt jianyunt commented Jun 6, 2018

In the #663, @gshacklett has commented get- and then tab PSReadLine will throw. This case is very often on cloudshell because Azure cmdlets are quite long and people use tab a lot.

The fix is to let contents display until complete for the menu not selected case. I tested on Windows, Linux and cloudshell, the fix seems to be working. Please code review. Thanks.

However I broke the PossibleCompletions() tests. The fix changed the parameter in calling InvokePrompt https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/Completion.cs#L736 so code path is different. With the fix, we are executing the else block in https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/ReadLine.cs#L942.

@lzybkr
Copy link
Contributor

lzybkr commented Aug 15, 2018

It looks like MenuComplete is still a problem and should be fixed at the same time.

It seems reasonable to fall back to this fix if the menu + the command line won't fit on the screen.

Also - when selecting items from the menu, the tooltip is displayed below the menu. That should be disabled if it won't fit on the screen.

@jianyunt
Copy link
Contributor Author

Thank you @lzybkr for your comments. Could you please give me more detailed info when you say "it looks like MenuComplete is still a problem "?

@lzybkr
Copy link
Contributor

lzybkr commented Aug 15, 2018

If you invoke MenuComplete, e.g. bind Tab like this:

Set-PSReadLineKeyBinding -Key Tab -Function MenuComplete

Then you will hit the call that tries to set the cursor position incorrectly. Your change avoids that call, but it is still reachable and many people do use MenuComplete.

@jianyunt
Copy link
Contributor Author

jianyunt commented Aug 15, 2018

For the cursor position issue while hit the Tab, we also need to apply the fix from https://github.com/PowerShell/PowerShell/pull/7299/files (the next release of pscore will contain it).

Once applied the fix, invoking the MenuComplete should work fine. I tested it on Linux and CloudShell. I don't see the cursor issue.
Also if the tooltip does not fit the screen while a user selects a menu, PSReadline scroll up the screen first. It seems to work fine.

@lzybkr
Copy link
Contributor

lzybkr commented Aug 15, 2018

I don't think that's correct. I have your to PSReadLine and shouldn't need the fix to PowerShell (no Write-Progress calls).

Try opening an instance of PowerShell, set the window height to 20, type Get-CCtrl+Space then use the arrow keys until Get-ChildItem is selected.

After doing this, I see the same exception as the one you are trying to fix.

else
{
// Start a new line to show the menu contents
console.Write("\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could write over some of the buffer if you press Tab anywhere that is not the last line, e.g.:

PS> & { Get-C<Tab><Tab>
>> }

After pressing Tab Tab, the screen might look like:

PS> & { Get-C<Tab><Tab>
Get-C1   Get-C2    Get-C3
PS> & { Get-C
>> }

When it should look like:

PS> & { Get-C<Tab><Tab>
>> }
Get-C1   Get-C2    Get-C3
PS> & { Get-C
>> }

Copy link
Contributor Author

@jianyunt jianyunt Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jason, I submitted the fix and tested it. It seems working fine now. Please take a look it again. Thanks!

}
else
{
EnsureMenuAndInputIsVisible(console, tooltipLineCount: 0, rows:0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this call necessary? I suspected it wasn't and tested briefly with it removed, I didn't see any problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. we needed it. On Windows, I do not see problem either. But on Linux the System.ArgumentOutOfRangeException occurs on the EnsureMenuAndInputIsVisible() , Singleton._initialY -= toScroll becomes negative when rows is large.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jianyunt - after resolving this comment (either removing the call or confirming it is needed), I think this PR is ready to merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@lzybkr lzybkr Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you relying on the + 1 to write out a single newline?

Based on the comment in EnsureMenuAndInputIsVisible, I could see that + 1 being removed at some point, and then the method would do nothing, right?

If my understanding is correct, it would be good to have some way to ensure this problem doesn't come back if someone removes that + 1 - a test, or maybe pass rows:1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found calling EnsureMenuAndInputIsVisible can cause the ArgumentOutOfRangeException when the window is reduced to one line height or the following can cause the exception too when the window height is 5 in this case (full screen editing). Thus I changed back to use console.Write(), after console.SetCursorPosition(0, this.Top); . It seems work fine for all cases now. Thanks.

& {Get-C
abc1
abc2
abc3
}

}
else
{
// Update the cursor coordinates after showing the menu.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this block necessary? InvokePrompt is called immediately after the call site that passes menuSelect: false and InvokePrompt is correctly updating these fields.

I tested briefly with these commented out and didn't see any problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. We do not need it. I added it because I used Console.Write("\n") before. Removed it now. Thanks.

Copy link
Contributor Author

@jianyunt jianyunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
else
{
EnsureMenuAndInputIsVisible(console, tooltipLineCount: 0, rows:0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. we needed it. On Windows, I do not see problem either. But on Linux the System.ArgumentOutOfRangeException occurs on the EnsureMenuAndInputIsVisible() , Singleton._initialY -= toScroll becomes negative when rows is large.

}
else
{
// Update the cursor coordinates after showing the menu.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. We do not need it. I added it because I used Console.Write("\n") before. Removed it now. Thanks.

@lzybkr lzybkr merged commit fbccefc into PowerShell:master Aug 21, 2018
@jianyunt jianyunt deleted the tabissue branch August 21, 2018 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants