-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
In my eyes, spawning a new tab is a special case of splitting a nonexistent window into one pane.
Right now, we have a lot of divergence between opening a tab (1) and opening a pane (2); in both cases we spawn a new control, but the way it gets propagated into the tree is vastly different. The same applies for duplicating an active pane; the code in pane splitting suggests that duplicating a pane keeps the working directory but a tab does not (!) (see 3) EDIT: No, we accounted for it. Double the code, double the places to look 😉
1
terminal/src/cascadia/TerminalApp/TabManagement.cpp
Lines 242 to 272 in 10992b7
| auto connection = existingConnection ? existingConnection : _CreateConnectionFromSettings(profile, settings.DefaultSettings()); | |
| // If we had an `existingConnection`, then this is an inbound handoff from somewhere else. | |
| // We need to tell it about our size information so it can match the dimensions of what | |
| // we are about to present. | |
| if (existingConnection) | |
| { | |
| connection.Resize(settings.DefaultSettings().InitialRows(), settings.DefaultSettings().InitialCols()); | |
| } | |
| TerminalConnection::ITerminalConnection debugConnection{ nullptr }; | |
| if (_settings.GlobalSettings().DebugFeaturesEnabled()) | |
| { | |
| const CoreWindow window = CoreWindow::GetForCurrentThread(); | |
| const auto rAltState = window.GetKeyState(VirtualKey::RightMenu); | |
| const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu); | |
| const bool bothAltsPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) && | |
| WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); | |
| if (bothAltsPressed) | |
| { | |
| std::tie(connection, debugConnection) = OpenDebugTapConnection(connection); | |
| } | |
| } | |
| // Give term control a child of the settings so that any overrides go in the child | |
| // This way, when we do a settings reload we just update the parent and the overrides remain | |
| auto term = _InitControl(settings, connection); | |
| auto newTabImpl = winrt::make_self<TerminalTab>(profile, term); | |
| _RegisterTerminalEvents(term); | |
| _InitializeTab(newTabImpl); |
2
terminal/src/cascadia/TerminalApp/TerminalPage.cpp
Lines 1391 to 1416 in 10992b7
| const auto controlConnection = _CreateConnectionFromSettings(profile, controlSettings.DefaultSettings()); | |
| const float contentWidth = ::base::saturated_cast<float>(_tabContent.ActualWidth()); | |
| const float contentHeight = ::base::saturated_cast<float>(_tabContent.ActualHeight()); | |
| const winrt::Windows::Foundation::Size availableSpace{ contentWidth, contentHeight }; | |
| auto realSplitType = splitType; | |
| if (realSplitType == SplitState::Automatic) | |
| { | |
| realSplitType = tab.PreCalculateAutoSplit(availableSpace); | |
| } | |
| const auto canSplit = tab.PreCalculateCanSplit(realSplitType, splitSize, availableSpace); | |
| if (!canSplit) | |
| { | |
| return; | |
| } | |
| auto newControl = _InitControl(controlSettings, controlConnection); | |
| // Hookup our event handlers to the new terminal | |
| _RegisterTerminalEvents(newControl); | |
| _UnZoomIfNeeded(); | |
| tab.SplitPane(realSplitType, splitSize, profile, newControl); |
Collapsed note 3
3
terminal/src/cascadia/TerminalApp/TerminalPage.cpp
Lines 1359 to 1370 in 10992b7
| if (splitMode == SplitType::Duplicate) | |
| { | |
| profile = tab.GetFocusedProfile(); | |
| if (profile) | |
| { | |
| controlSettings = TerminalSettings::CreateWithProfile(_settings, profile, *_bindings); | |
| const auto workingDirectory = tab.GetActiveTerminalControl().WorkingDirectory(); | |
| const auto validWorkingDirectory = !workingDirectory.empty(); | |
| if (validWorkingDirectory) | |
| { | |
| controlSettings.DefaultSettings().StartingDirectory(workingDirectory); | |
| } |