terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Fix issue with pasting while tab renaming also sending the paste command to terminal

Open marcelwgn opened this issue 2 years ago • 9 comments

The issue was that pasting while renaming a tab is also sending that text to the terminal. The proposed fix is to ignore paste commands while we are renaming a tab.

Other solutions I considered where looking for shell focus to undermine sending paste commands (how would you paste something if the shell is not focused) or diving deeper into the events to actually prevent it from bubbling up so far. Due to complexity and possible problems however, I went with just looking for renaming tabs instead.

Validation Steps Performed

  1. Start Terminal
  2. Rename tab
  3. Press Ctrl+V and see if the shell gets pasted content

Closes #14381

marcelwgn avatar Jan 11 '23 23:01 marcelwgn

TerminalPage::_PasteFromClipboardHandler "This function is called when the TermControl requests that we send it the clipboard's content."

Can it be fixed such that TermControl does not even receive the UI event or translate it to a paste request, if the tab is being renamed? I'm thinking, if an extension of Windows Terminal were running a script that pastes for reasons not related to UI events, then it should not be affected by whether the user is renaming a tab.

KalleOlaviNiemitalo avatar Jan 15 '23 10:01 KalleOlaviNiemitalo

Thank you for raising this concern @KalleOlaviNiemitalo! Honestly, I'm afraid the event handling is quite complicated in that area. #12260 introduced the behavior that the KeyUp event of the tab row also get sent to the key event handler of the TerminalPage to fix some a11y issue. I think that trying to fix this issue in could potentially undo the effect of #12260.

Looking at who requests a pasting of text to the control, it seems that this is only done through UI interaction with the terminal control. It is worth noting though that this PR introduces the behavior that right clicking the terminal while renaming a tab also no longer pastes the content and instead just cancels renaming the tab. I see this as an improvement, but opinions might diverge on that matter.

marcelwgn avatar Jan 15 '23 11:01 marcelwgn

How about searching for text in the terminal and pasting to the search box, does that have the same problem as in renaming the tab?

KalleOlaviNiemitalo avatar Jan 15 '23 11:01 KalleOlaviNiemitalo

It seems, that the searching box seems to handle the behavior correctly.

marcelwgn avatar Jan 15 '23 14:01 marcelwgn

I'd like to wait on this a little bit to cost out how much it would take to simply fix all of our key eventing issues. The core problem is that we're using PreviewKeyDown on TermControl, when we should be using KeyDown. Every other workaround has fallen out from there. Thanks for doing it, though, and I'm going to keep it open until we've made that assessment!

DHowett avatar Jan 20 '23 00:01 DHowett

Yo @DHowett was the cost as big as we thought?

zadjii-msft avatar Jan 29 '23 12:01 zadjii-msft

I don't want to be pushy but I'm curious what the next steps for this PR are or if there is anything that needs adjustment 😃

marcelwgn avatar Aug 23 '23 16:08 marcelwgn

@zadjii-msft would you mind doing that costing I mentioned? :smile:

DHowett avatar Aug 24 '23 15:08 DHowett

Hi guys, is there any movement on this issue?

leewilmott avatar Aug 05 '24 09:08 leewilmott