-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Right click paste should work mostly like Ctrl+v paste #579
Comments
So I mentioned capturing mouse events and I came up with this PoC https://github.com/Tadas/PSReadLine/tree/MouseHook Basically this installs a global Windows event hook to capture right clicks. It looks for ones going to our console window, makes sure that the click was in the client area and if we're in quick edit mode calls With some more hackery I think it would be possible to intercept Paste action from the context menu. |
Interesting approach. I'm not interested in taking a dependency on I'm also a bit concerned about ensuring |
One other thing - ideally we can fix this on every platform, not just Windows. The heuristic approach should work cross-platform, but I'm open to more reliable approaches like yours if there is a solution for the various non-Windows platforms as well. |
@MaximoTrinidad - PSReadLine has always worked this way and it is a little different than without PSReadLine. It wasn't much of a problem because Ctrl+v is preferred - it is way faster and characters like Tab don't get expanded incorrectly. Now this problem is more annoying on PowerShell Core because the port that the PowerShell team did not support the clipboard. My port does, so when PSReadLine 2.0 is widely available, I'll continue to recommend folks use Ctrl+v instead of right click. That said, it would be nice to see this fixed at some point. |
Hum! Interesting. They force me to close my incident about the issue with the If-Else block not working after pasting it into PowerShell Core as it breaks at the "else". I just tried using Ctrl-V and it do nothing. In the other hand, doing the right-click on the mouse works. My issue wasn't really the pasting of the code. The If-Else should work with both structure:
I know if I remove the module then is works as expected. |
As I said, Ctrl+v works in Windows PowerShell, but you need PSReadLine 2.0 (no official builds available yet) for PowerShell Core. And I fully understand the problem, you don't need to keep repeating yourself. Without PSReadLine, if there is multi-line input, you must enter a single blank line before the input is accepted. With PSReadLine, if the input is "complete", as in, it parses without an IncompleteParseException, then the input will be accepted without that extra blank line. So PSReadLine is just different and that's not changing. If you aren't pasting, you use Shift+Enter when you know you're not done - this way you can enter your When you paste, you can't use Shift+Enter, so the input might get accepted before you wanted. This issue is to attempt to emulate Ctrl+v when you right click paste so that the experience is better, but I do not plan on requiring a blank line to accept multi-line input. |
My Apologies! It's been a tough day! At least, it's manageable, and not show stopper as the script will execute regardless of the way I code the If-Else block. I appreciate all the information, :) |
I don't understand why you mentioned cross platform'ness - isn't this right-click paste issue strictly a Windows thing? Anyway, I've removed Seems like always calling |
Maybe not with a right click, but Linux and Mac terminals definitely support paste. For example, the default graphical terminal in CentOS has Edit|Paste in the main menu and Paste in a right click popup menu. My concern about As you pointed out, the busy loop is too busy. I use a 300ms wait to check for idle events in the main input loop - 300ms is supposedly long enough to not hurt battery life. |
Just to summarize the status quo on (some) Unix-like platforms (macOS 10.13 with either Terminal.app or iTerm2.app, Ubuntu 16 with its default terminal):
|
I don't see an obvious way to fix this. On Windows, I can see that when pasting via Ctrl+V (which is handled by Windows Terminal and not PSRL), the end of line is It is interesting that without PSReadLine, the basic ReadLine in pwsh handles this correctly... |
@SteveL-MSFT: As for macOS: haven't looked in detail, but multi-line pasting with the default keyboard shortcut (Cmd-V) seems to work just fine in PSRL 2.0.0 beta.4, with both CRLF- and platform-native LF-only text.
In case you're referring to the platform-native newline sequence on macOS: When macOS became OS X in 2001 and thereby became Unix-like, LF ( |
@SteveL-MSFT - I hinted at the solution above and probably describe it in detail in a linked issue. If we can infer that a user "pasted" via right click, then we can process keys differently. By tracking the time between key presses, I think it's probably reasonable to infer the user isn't actually typing. I'm guessing that if the delay between keys is less than 25ms or so, it's not a human typing, especially if we average over enough keys. |
@mklement0 I'm running Catalina, the @lzybkr detecting that the input isn't human may be good enough. |
Thanks for clarifying and sorry fo the distraction, @SteveL-MSFT (I didn't know that Unix terminals apparently translate So while the multi-line issues specifically appear not to affect macOS and Linux, PSRL's processing of the input as being typed by the user can cause problems in combination with custom key handlers that modify / complete input (as shown in #735), so the fix proposed by @lzybkr should help on these platforms too. |
I didn't find the behavior to be any different in Ubuntu's terminal when pasting. Pasting a multiline IF ELSEIF ELSE statement still got executed between the statement blocks if PSReadLine was imported. |
This comment has been minimized.
This comment has been minimized.
@daxian-dbw looks like Windows Terminal now has support for bracketed paste, so we should be able to fix this in PSReadLine now |
Hopefully I'm wrong, but it might not be easy to use bracketed paste, see #1471 (comment) |
Have you tried reversing the paste order when right clicking? Seems like it should be an easy fix, just change from [$len..0] to [0..$len] Kinda absurd that this simple issue keeps popping up. |
I found my way here regarding the right-click paste in reverse issue. It's now 2024, and this is still an issue in Powershell 7. I cannot follow the thread above as it just seems the conversation about this died (unless I'm missing something), but the referenced issue (#496) is marked closed. What was the final disposition on this issue? Can it not be fixed? It's so annoying copying code from ChatGPT only to have it reversed when pasted. A right click is easier for me than ctrl+v. |
The only solution I found was to use a different console host. |
Still not fixed in v7, SEVEN YEARS LATER, as of v7.4.4. |
Hey all - I was able to mitigate this by pasting snippit(s)/command(s) into notepad, ensure the formatting is correct, copy the snippit/command from notepad and paste into the console. |
FYI you have to do all that. Just use Ctrl+V on the keyboard to paste and it should be fine. The issue is only with paste via mouse right-click. |
I've been having the same issue; I find this unbelievable this has been open for 7 years, as we come up on the anniversary date! |
There's no AI component so the board room doesn't care. |
There are various complaints about the right click to paste behavior - all of which are non-issues with Ctrl+v paste.
This includes:
\n
comes in reverse (Right-click paste with \n comes out upside down? #496)The fix for this should also address #290 by checking if the input is "complete" after a newline, though it should check if the last statement could be continued even if it is complete, e.g.
if
w/o anelse
ortry
without afinally
.The text was updated successfully, but these errors were encountered: