terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Selected tab title not used for `Export Text` file name

Open elsaco opened this issue 2 years ago • 8 comments

Windows Terminal version

main 1ef4a4276

Windows build number

10.0.19044.0

Other Software

No response

Steps to reproduce

  • build WT with Use the tab's active title for "Export Text" patch applied, commit 2c341c8de
  • rename some tabs
  • export text from a tab other than active one

Foo was the active tab and Bar was used for export: wt_export_text

Expected Behavior

  • tab's title used for filename

Actual Behavior

  • the active's tab title is being used instead

elsaco avatar Sep 08 '22 19:09 elsaco

It's much worse than that: it actually only exports the active tab. It can't export a non-active tab.

How? It takes tab in as an action argument...! Did we mess something up this egregiously?

DHowett avatar Sep 08 '22 20:09 DHowett

So this and #13942 are somewhat related.

Of the tab related context menu items "Duplicate Tab", "Split Tab", "Export Text" and "Find", the only one that does what you expect on an unfocused tab is "Split Tab".

The callbacks are all set up in TabManagement.cpp:

https://github.com/microsoft/terminal/blob/95a9d8c31b3f4e27fb10ccefa525d66eacf26f96/src/cascadia/TerminalApp/TabManagement.cpp#L193-L233

They delegate to:

  • TerminalPage::_DuplicateTab(): duplicates the currently focused tab
  • TerminalPage::_SplitTab(): works as expected, as it focuses the selected tab and then splits it
  • TerminalPage::_HandleExportBuffer(): exports the currently focused tab's content
  • TerminalPage::_Find(): searches the currently focused tab's control

I guess the quick win would be to replicate what SplitTab() does - i.e. focus the selected tab and then do the duplicate/export/find. Is that reasonable?

ianjoneill avatar Sep 09 '22 08:09 ianjoneill

That seems like a reasonable solution to me. Think that'll knock out all of this issue, #13942 and #13579 all in one go?

zadjii-msft avatar Sep 09 '22 11:09 zadjii-msft

Hmm doesn't look like it's that straight forward - _SetFocusedTab() is async. As @JerBast suggests - _DuplicateTab() and _SplitTab() delegate to _MakePane(), which won't necessarily get the focused tab due it's async nature.

ianjoneill avatar Sep 09 '22 13:09 ianjoneill

Generally speaking, I'd rather us fix the event plumbing so that things that come out of (1) the pane, (2) the tab and (3) the terminal control are tagged up appropriately so we know their origination chain. Is that something doable on a reasonable time horizon?

DHowett avatar Sep 09 '22 18:09 DHowett

maybe _MakePane(newTerminalArgs, bool duplicate, existingConnection) should accept something like const TerminalTab& sourceTab instead of bool duplicate? That way _DuplicateTab will pass the tab to _MakePane and it should work.

serd2011 avatar Sep 09 '22 18:09 serd2011

Changing _MakePane would work for #13942 for sure. For this issue, it is also possible to replace the call to pane->_HandleExportBuffer(...) with a call to pane->_ExportTab(*tab, L"") directly.

JerBast avatar Sep 09 '22 18:09 JerBast

I'd come to the same conclusions. There's no point 3 people working on it though, so I'll leave it to you 🙂

ianjoneill avatar Sep 09 '22 19:09 ianjoneill

:tada:This issue was addressed in #14673, which has now been successfully released as Windows Terminal Preview v1.17.1023.:tada:

Handy links:

ghost avatar Jan 24 '23 18:01 ghost