diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index c9d9e215bb3..0459c36bcfa 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -271,54 +271,6 @@ Pane::BuildStartupState Pane::BuildStartupActions(uint32_t currentId, uint32_t n return { actions, firstState.firstPane, focusedPaneId, firstState.panesCreated + secondState.panesCreated + 1 }; } -// Method Description: -// - Update the size of this pane. Resizes each of our columns so they have the -// same relative sizes, given the newSize. -// - Because we're just manually setting the row/column sizes in pixels, we have -// to be told our new size, we can't just use our own OnSized event, because -// that _won't fire when we get smaller_. -// Arguments: -// - newSize: the amount of space that this pane has to fill now. -// Return Value: -// - -void Pane::ResizeContent(const Size& newSize) -{ - const auto width = newSize.Width; - const auto height = newSize.Height; - - _CreateRowColDefinitions(); - - if (_splitState == SplitState::Vertical) - { - const auto paneSizes = _CalcChildrenSizes(width); - - const Size firstSize{ paneSizes.first, height }; - const Size secondSize{ paneSizes.second, height }; - _firstChild->ResizeContent(firstSize); - _secondChild->ResizeContent(secondSize); - } - else if (_splitState == SplitState::Horizontal) - { - const auto paneSizes = _CalcChildrenSizes(height); - - const Size firstSize{ width, paneSizes.first }; - const Size secondSize{ width, paneSizes.second }; - _firstChild->ResizeContent(firstSize); - _secondChild->ResizeContent(secondSize); - } -} - -// Method Description: -// - Recalculates and reapplies sizes of all descendant panes. -// Arguments: -// - -// Return Value: -// - -void Pane::Relayout() -{ - ResizeContent(_root.ActualSize()); -} - // Method Description: // - Adjust our child percentages to increase the size of one of our children // and decrease the size of the other. @@ -355,7 +307,7 @@ bool Pane::_Resize(const ResizeDirection& direction) _desiredSplitPosition = _ClampSplitPosition(changeWidth, _desiredSplitPosition - amount, actualDimension); // Resize our columns to match the new percentages. - ResizeContent(actualSize); + _CreateRowColDefinitions(); return true; } @@ -496,16 +448,8 @@ std::shared_ptr Pane::NavigateDirection(const std::shared_ptr source // Fixed movement if (direction == FocusDirection::First) { - std::shared_ptr firstPane = nullptr; - WalkTree([&](auto p) { - if (p->_IsLeaf()) - { - firstPane = p; - return true; - } - - return false; - }); + // Just get the first leaf pane. + auto firstPane = _FindPane([](const auto& p) { return p->_IsLeaf(); }); // Don't need to do any movement if we are the source and target pane. if (firstPane == sourcePane) @@ -662,22 +606,9 @@ std::shared_ptr Pane::PreviousPane(const std::shared_ptr targetPane) // - the parent of `pane` if pane is in this tree. std::shared_ptr Pane::_FindParentOfPane(const std::shared_ptr pane) { - if (_IsLeaf()) - { - return nullptr; - } - - if (_firstChild == pane || _secondChild == pane) - { - return shared_from_this(); - } - - if (auto p = _firstChild->_FindParentOfPane(pane)) - { - return p; - } - - return _secondChild->_FindParentOfPane(pane); + return _FindPane([&](const auto& p) { + return p->_firstChild == pane || p->_secondChild == pane; + }); } // Method Description: @@ -805,23 +736,15 @@ bool Pane::SwapPanes(std::shared_ptr first, std::shared_ptr second) } // Refocus the last pane if there was a pane focused - first->WalkTree([](auto p) { - if (p->_lastActive) - { - p->_Focus(); - return true; - } - return false; - }); + if (const auto focus = first->GetActivePane()) + { + focus->_Focus(); + } - second->WalkTree([](auto p) { - if (p->_lastActive) - { - p->_Focus(); - return true; - } - return false; - }); + if (const auto focus = second->GetActivePane()) + { + focus->_Focus(); + } return true; } @@ -1227,21 +1150,7 @@ Controls::Grid Pane::GetRootElement() // `_lastActive`, else returns this std::shared_ptr Pane::GetActivePane() { - if (_lastActive) - { - return shared_from_this(); - } - if (_IsLeaf()) - { - return nullptr; - } - - auto firstFocused = _firstChild->GetActivePane(); - if (firstFocused != nullptr) - { - return firstFocused; - } - return _secondChild->GetActivePane(); + return _FindPane([](const auto& p) { return p->_lastActive; }); } // Method Description: @@ -1474,18 +1383,10 @@ std::shared_ptr Pane::AttachPane(std::shared_ptr pane, SplitDirectio // If the new pane has a child that was the focus, re-focus it // to steal focus from the currently focused pane. - if (pane->_HasFocusedChild()) + if (const auto focus = pane->GetActivePane()) { - pane->WalkTree([](auto p) { - if (p->_lastActive) - { - p->_Focus(); - return true; - } - return false; - }); + focus->_Focus(); } - return first; } @@ -1527,7 +1428,6 @@ std::shared_ptr Pane::DetachPane(std::shared_ptr pane) // Trigger the detached event on each child detached->WalkTree([](auto pane) { pane->_DetachedHandlers(pane); - return false; }); return detached; @@ -1616,7 +1516,6 @@ void Pane::_CloseChild(const bool closeFirst, const bool isDetaching) p->_control.ConnectionStateChanged(p->_connectionStateChangedToken); p->_control.WarningBell(p->_warningBellToken); } - return false; }); } @@ -1706,7 +1605,6 @@ void Pane::_CloseChild(const bool closeFirst, const bool isDetaching) p->_control.ConnectionStateChanged(p->_connectionStateChangedToken); p->_control.WarningBell(p->_warningBellToken); } - return false; }); } @@ -2254,7 +2152,7 @@ void Pane::_SetupEntranceAnimation() // tree, we'll reduce the size passed to each subsequent recursive call. The // size passed to this method represents how much space this Pane _will_ have // to use. -// * If this pane is a leaf, and it's the pane we're looking for, use the +// * If this pane is the pane we're looking for, use the // available space to calculate which direction to split in. // * If this pane is _any other leaf_, then just return nullopt, to indicate // that the `target` Pane is not down this branch. @@ -2265,30 +2163,34 @@ void Pane::_SetupEntranceAnimation() // - splitType: The direction we're attempting to split in. // - availableSpace: The theoretical space that's available for this pane to be able to split. // Return Value: -// - nullopt if `target` is not this pane or a child of this pane, otherwise -// true iff we could split this pane, given `availableSpace` -// Note: -// - This method is highly similar to Pane::PreCalculateAutoSplit -std::optional Pane::PreCalculateCanSplit(const std::shared_ptr target, - SplitDirection splitType, - const float splitSize, - const winrt::Windows::Foundation::Size availableSpace) const +// - nullopt if the target is not found, or if there is not enough space to fit. +// Otherwise will return the "real split direction" (converting automatic splits), +// and will return either the split direction or nullopt. +std::optional> Pane::PreCalculateCanSplit(const std::shared_ptr target, + SplitDirection splitType, + const float splitSize, + const winrt::Windows::Foundation::Size availableSpace) const { if (target.get() == this) { const auto firstPercent = 1.0f - splitSize; const auto secondPercent = splitSize; - // If this pane is a leaf, and it's the pane we're looking for, use + // If this pane is the pane we're looking for, use // the available space to calculate which direction to split in. const Size minSize = _GetMinSize(); + if (splitType == SplitDirection::Automatic) + { + splitType = availableSpace.Width > availableSpace.Height ? SplitDirection::Right : SplitDirection::Down; + } + if (splitType == SplitDirection::Left || splitType == SplitDirection::Right) { const auto widthMinusSeparator = availableSpace.Width - CombinedPaneBorderSize; const auto newFirstWidth = widthMinusSeparator * firstPercent; const auto newSecondWidth = widthMinusSeparator * secondPercent; - return { newFirstWidth > minSize.Width && newSecondWidth > minSize.Width }; + return newFirstWidth > minSize.Width && newSecondWidth > minSize.Width ? std::optional{ splitType } : std::nullopt; } else if (splitType == SplitDirection::Up || splitType == SplitDirection::Down) @@ -2297,7 +2199,7 @@ std::optional Pane::PreCalculateCanSplit(const std::shared_ptr targe const auto newFirstHeight = heightMinusSeparator * firstPercent; const auto newSecondHeight = heightMinusSeparator * secondPercent; - return { newFirstHeight > minSize.Height && newSecondHeight > minSize.Height }; + return newFirstHeight > minSize.Height && newSecondHeight > minSize.Height ? std::optional{ splitType } : std::nullopt; } } else if (_IsLeaf()) @@ -2630,24 +2532,19 @@ void Pane::Id(uint32_t id) noexcept bool Pane::FocusPane(const uint32_t id) { // Always clear the parent child path if we are focusing a leaf - _parentChildPath.reset(); - if (_IsLeaf() && id == _id) - { - // Make sure to use _FocusFirstChild here - that'll properly update the - // focus if we're in startup. - _FocusFirstChild(); - return true; - } - else - { - if (_firstChild && _secondChild) + return WalkTree([=](auto p) { + p->_parentChildPath.reset(); + if (p->_id == id) { - return _firstChild->FocusPane(id) || - _secondChild->FocusPane(id); + // Make sure to use _FocusFirstChild here - that'll properly update the + // focus if we're in startup. + p->_FocusFirstChild(); + return true; } - } - return false; + return false; + }); } + // Method Description: // - Focuses the given pane if it is in the tree. // - This is different than FocusPane(id) in that it allows focusing @@ -2658,22 +2555,16 @@ bool Pane::FocusPane(const uint32_t id) // - true if focus was set bool Pane::FocusPane(const std::shared_ptr pane) { - if (this == pane.get()) - { - _Focus(); - return true; - } - else - { - // clear the parent child path if we are not the pane being focused. - _parentChildPath.reset(); - if (_firstChild && _secondChild) + return WalkTree([&](auto p) { + if (p == pane) { - return _firstChild->FocusPane(pane) || - _secondChild->FocusPane(pane); + p->_Focus(); + return true; } - } - return false; + // clear the parent child path if we are not the pane being focused. + p->_parentChildPath.reset(); + return false; + }); } // Method Description: @@ -2684,17 +2575,14 @@ bool Pane::FocusPane(const std::shared_ptr pane) // - true if the child was found. bool Pane::_HasChild(const std::shared_ptr child) { - if (_IsLeaf()) + if (child == nullptr) { return false; } - if (_firstChild == child || _secondChild == child) - { - return true; - } - - return _firstChild->_HasChild(child) || _secondChild->_HasChild(child); + return WalkTree([&](const auto& p) { + return p->_firstChild == child || p->_secondChild == child; + }); } // Method Description: @@ -2705,26 +2593,7 @@ bool Pane::_HasChild(const std::shared_ptr child) // - A pointer to the pane with the given ID, if found. std::shared_ptr Pane::FindPane(const uint32_t id) { - if (_IsLeaf()) - { - if (id == _id) - { - return shared_from_this(); - } - } - else - { - if (auto pane = _firstChild->FindPane(id)) - { - return pane; - } - if (auto pane = _secondChild->FindPane(id)) - { - return pane; - } - } - - return nullptr; + return _FindPane([=](const auto& p) { return p->_IsLeaf() && p->_id == id; }); } // Method Description: @@ -3162,68 +3031,6 @@ int Pane::GetLeafPaneCount() const noexcept return _IsLeaf() ? 1 : (_firstChild->GetLeafPaneCount() + _secondChild->GetLeafPaneCount()); } -// Method Description: -// - This is a helper to determine which direction an "Automatic" split should -// happen in for a given pane, but without using the ActualWidth() and -// ActualHeight() methods. This is used during the initialization of the -// Terminal, when we could be processing many "split-pane" commands _before_ -// we've ever laid out the Terminal for the first time. When this happens, the -// Pane's don't have an actual size yet. However, we'd still like to figure -// out how to do an "auto" split when these Panes are all laid out. -// - This method assumes that the Pane we're attempting to split is `target`, -// and this method should be called on the root of a tree of Panes. -// - We'll walk down the tree attempting to find `target`. As we traverse the -// tree, we'll reduce the size passed to each subsequent recursive call. The -// size passed to this method represents how much space this Pane _will_ have -// to use. -// * If this pane is a leaf, and it's the pane we're looking for, use the -// available space to calculate which direction to split in. -// * If this pane is _any other leaf_, then just return nullopt, to indicate -// that the `target` Pane is not down this branch. -// * If this pane is a parent, calculate how much space our children will be -// able to use, and recurse into them. -// Arguments: -// - target: The Pane we're attempting to split. -// - availableSpace: The theoretical space that's available for this pane to be able to split. -// Return Value: -// - nullopt if `target` is not this pane or a child of this pane, otherwise the -// SplitDirection that `target` would use for an `Automatic` split given -// `availableSpace` -std::optional Pane::PreCalculateAutoSplit(const std::shared_ptr target, - const winrt::Windows::Foundation::Size availableSpace) const -{ - if (target.get() == this) - { - // If this pane is the pane we are looking for, use the available space - // to calculate which direction to split in. - return availableSpace.Width > availableSpace.Height ? SplitDirection::Right : SplitDirection::Down; - } - else if (_IsLeaf()) - { - // If this pane is _any other leaf_, then just return nullopt, to - // indicate that the `target` Pane is not down this branch. - return std::nullopt; - } - else - { - // If this pane is a parent, calculate how much space our children will - // be able to use, and recurse into them. - - const bool isVerticalSplit = _splitState == SplitState::Vertical; - const float firstWidth = isVerticalSplit ? (availableSpace.Width * _desiredSplitPosition) : availableSpace.Width; - const float secondWidth = isVerticalSplit ? (availableSpace.Width - firstWidth) : availableSpace.Width; - const float firstHeight = !isVerticalSplit ? (availableSpace.Height * _desiredSplitPosition) : availableSpace.Height; - const float secondHeight = !isVerticalSplit ? (availableSpace.Height - firstHeight) : availableSpace.Height; - - const auto firstResult = _firstChild->PreCalculateAutoSplit(target, { firstWidth, firstHeight }); - return firstResult.has_value() ? firstResult : _secondChild->PreCalculateAutoSplit(target, { secondWidth, secondHeight }); - } - - // We should not possibly be getting here - both the above branches should - // return a value. - FAIL_FAST(); -} - // Method Description: // - Returns true if the pane or one of its descendants is read-only bool Pane::ContainsReadOnly() const diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index 28e4caf6b43..b9918e8271c 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -96,8 +96,6 @@ class Pane : public std::enable_shared_from_this void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, const winrt::Microsoft::Terminal::Settings::Model::Profile& profile); - void ResizeContent(const winrt::Windows::Foundation::Size& newSize); - void Relayout(); bool ResizePane(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction); std::shared_ptr NavigateDirection(const std::shared_ptr sourcePane, const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction, @@ -112,12 +110,10 @@ class Pane : public std::enable_shared_from_this std::shared_ptr pane); bool ToggleSplitOrientation(); float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const; - std::optional PreCalculateAutoSplit(const std::shared_ptr target, - const winrt::Windows::Foundation::Size parentSize) const; - std::optional PreCalculateCanSplit(const std::shared_ptr target, - winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType, - const float splitSize, - const winrt::Windows::Foundation::Size availableSpace) const; + std::optional> PreCalculateCanSplit(const std::shared_ptr target, + winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType, + const float splitSize, + const winrt::Windows::Foundation::Size availableSpace) const; void Shutdown(); void Close(); @@ -140,14 +136,15 @@ class Pane : public std::enable_shared_from_this // Method Description: // - A helper method for ad-hoc recursion on a pane tree. Walks the pane - // tree, calling a predicate on each pane in a depth-first pattern. - // - If the predicate returns true, recursion is stopped early. + // tree, calling a function on each pane in a depth-first pattern. + // - If that function returns void, then it will be called on every pane. + // - Otherwise, iteration will continue until a value with operator bool + // returns true. // Arguments: // - f: The function to be applied to each pane. // Return Value: - // - true if the predicate returned true on any pane. + // - The value of the function applied on a Pane template - //requires std::predicate> auto WalkTree(F f) -> decltype(f(shared_from_this())) { using R = std::invoke_result_t>; @@ -164,20 +161,36 @@ class Pane : public std::enable_shared_from_this } else { - if (f(shared_from_this())) + if (const auto res = f(shared_from_this())) { - return true; + return res; } if (!_IsLeaf()) { - return _firstChild->WalkTree(f) || _secondChild->WalkTree(f); + if (const auto res = _firstChild->WalkTree(f)) + { + return res; + } + return _secondChild->WalkTree(f); } - return false; + return R{}; } } + template + std::shared_ptr _FindPane(F f) + { + return WalkTree([f](const auto& pane) -> std::shared_ptr { + if (f(pane)) + { + return pane; + } + return nullptr; + }); + } + void CollectTaskbarStates(std::vector& states); WINRT_CALLBACK(Closed, winrt::Windows::Foundation::EventHandler); @@ -279,8 +292,6 @@ class Pane : public std::enable_shared_from_this SplitState _convertAutomaticOrDirectionalSplitState(const winrt::Microsoft::Terminal::Settings::Model::SplitDirection& splitType) const; - std::optional _preCalculateAutoSplit(const std::shared_ptr target, const winrt::Windows::Foundation::Size parentSize) const; - // Function Description: // - Returns true if the given direction can be used with the given split // type. diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index e67ad7780e6..5048f8fd8bf 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -706,7 +706,6 @@ namespace winrt::TerminalApp::implementation control.ToggleReadOnly(); } } - return false; }); } @@ -986,15 +985,4 @@ namespace winrt::TerminalApp::implementation std::copy(begin(_tabs), end(_tabs), std::back_inserter(tabsToRemove)); _RemoveTabs(tabsToRemove); } - - void TerminalPage::_ResizeTabContent(const winrt::Windows::Foundation::Size& newSize) - { - for (auto tab : _tabs) - { - if (auto terminalTab = _GetTerminalTabImpl(tab)) - { - terminalTab->ResizeContent(newSize); - } - } - } } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 92f853d537c..9d795514cc7 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -241,8 +241,6 @@ namespace winrt::TerminalApp::implementation _UpdateTabWidthMode(); - _tabContent.SizeChanged({ this, &TerminalPage::_OnContentSizeChanged }); - // When the visibility of the command palette changes to "collapsed", // the palette has been closed. Toss focus back to the currently active // control. @@ -1648,20 +1646,14 @@ namespace winrt::TerminalApp::implementation const float contentHeight = ::base::saturated_cast(_tabContent.ActualHeight()); const winrt::Windows::Foundation::Size availableSpace{ contentWidth, contentHeight }; - auto realSplitType = splitDirection; - if (realSplitType == SplitDirection::Automatic) - { - realSplitType = tab.PreCalculateAutoSplit(availableSpace); - } - - const auto canSplit = tab.PreCalculateCanSplit(realSplitType, splitSize, availableSpace); - if (!canSplit) + const auto realSplitType = tab.PreCalculateCanSplit(splitDirection, splitSize, availableSpace); + if (!realSplitType) { return; } _UnZoomIfNeeded(); - tab.SplitPane(realSplitType, splitSize, newPane); + tab.SplitPane(*realSplitType, splitSize, newPane); // After GH#6586, the control will no longer focus itself // automatically when it's finished being laid out. Manually focus @@ -2214,20 +2206,6 @@ namespace winrt::TerminalApp::implementation } } - // Method Description: - // - Called when our tab content size changes. This updates each tab with - // the new size, so they have a chance to update each of their panes with - // the new size. - // Arguments: - // - e: the SizeChangedEventArgs with the new size of the tab content area. - // Return Value: - // - - void TerminalPage::_OnContentSizeChanged(const IInspectable& /*sender*/, Windows::UI::Xaml::SizeChangedEventArgs const& e) - { - const auto newSize = e.NewSize(); - _ResizeTabContent(newSize); - } - // Method Description: // - Responds to the TabView control's Tab Closing event by removing // the indicated tab from the set and focusing another one. @@ -2400,7 +2378,6 @@ namespace winrt::TerminalApp::implementation pane->UpdateSettings(pair.second, pair.first); } } - return false; }); // Update the icon of the tab for the currently focused profile in that tab. diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index f08eb775db2..2cbd93e97b5 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -264,7 +264,6 @@ namespace winrt::TerminalApp::implementation void _FocusCurrentTab(const bool focusAlways); bool _HasMultipleTabs() const; void _RemoveAllTabs(); - void _ResizeTabContent(const winrt::Windows::Foundation::Size& newSize); void _SelectNextTab(const bool bMoveRight, const Windows::Foundation::IReference& customTabSwitcherMode); bool _SelectTab(uint32_t tabIndex); @@ -344,7 +343,6 @@ namespace winrt::TerminalApp::implementation void _OnTabClick(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs); void _OnTabSelectionChanged(const IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& eventArgs); void _OnTabItemsChanged(const IInspectable& sender, const Windows::Foundation::Collections::IVectorChangedEventArgs& eventArgs); - void _OnContentSizeChanged(const IInspectable& /*sender*/, Windows::UI::Xaml::SizeChangedEventArgs const& e); void _OnTabCloseRequested(const IInspectable& sender, const Microsoft::UI::Xaml::Controls::TabViewTabCloseRequestedEventArgs& eventArgs); void _OnFirstLayout(const IInspectable& sender, const IInspectable& eventArgs); void _UpdatedSelectedTab(const winrt::TerminalApp::TabBase& tab); diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index d8115936cac..fc5203d81fc 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -44,8 +44,6 @@ namespace winrt::TerminalApp::implementation { _activePane = pane; } - - return false; }); // In case none of the panes were already marked as the focus, just @@ -206,7 +204,6 @@ namespace winrt::TerminalApp::implementation { _AttachEventHandlersToControl(pane->Id().value(), control); } - return false; }); } @@ -584,7 +581,6 @@ namespace winrt::TerminalApp::implementation auto p = _rootPane; p->WalkTree([](auto pane) { pane->_DetachedHandlers(pane); - return false; }); // Clean up references and close the tab @@ -612,13 +608,9 @@ namespace winrt::TerminalApp::implementation if (p->_IsLeaf()) { p->Id(_nextPaneId); + _AttachEventHandlersToControl(p->Id().value(), p->_control); _nextPaneId++; } - if (auto control = p->GetTerminalControl()) - { - _AttachEventHandlersToControl(p->Id().value(), control); - } - return false; }); // pass the old id to the new child @@ -639,14 +631,10 @@ namespace winrt::TerminalApp::implementation _AttachEventHandlersToPane(first); // Make sure that we have the right pane set as the active pane - pane->WalkTree([&](auto p) { - if (p->_lastActive) - { - _UpdateActivePane(p); - return true; - } - return false; - }); + if (const auto focus = pane->GetActivePane()) + { + _UpdateActivePane(focus); + } } // Method Description: @@ -666,20 +654,6 @@ namespace winrt::TerminalApp::implementation return _rootPane->CalcSnappedDimension(widthOrHeight, dimension); } - // Method Description: - // - Update the size of our panes to fill the new given size. This happens when - // the window is resized. - // Arguments: - // - newSize: the amount of space that the panes have to fill now. - // Return Value: - // - - void TerminalTab::ResizeContent(const winrt::Windows::Foundation::Size& newSize) - { - // NOTE: This _must_ be called on the root pane, so that it can propagate - // throughout the entire tree. - _rootPane->ResizeContent(newSize); - } - // Method Description: // - Attempt to move a separator between panes, as to resize each child on // either size of the separator. See Pane::ResizePane for details. @@ -833,7 +807,6 @@ namespace winrt::TerminalApp::implementation auto& events = it->second; control.TitleChanged(events.titleToken); - control.FontSizeChanged(events.fontToken); control.TabColorChanged(events.colorToken); control.SetTaskbarProgress(events.taskbarToken); control.ReadOnlyChanged(events.readOnlyToken); @@ -870,20 +843,6 @@ namespace winrt::TerminalApp::implementation } }); - // This is called when the terminal changes its font size or sets it for the first - // time (because when we just create terminal via its ctor it has invalid font size). - // On the latter event, we tell the root pane to resize itself so that its descendants - // (including ourself) can properly snap to character grids. In future, we may also - // want to do that on regular font changes. - events.fontToken = control.FontSizeChanged([this](const int /* fontWidth */, - const int /* fontHeight */, - const bool isInitialChange) { - if (isInitialChange) - { - _rootPane->Relayout(); - } - }); - events.colorToken = control.TabColorChanged([weakThis](auto&&, auto&&) { if (auto tab{ weakThis.get() }) { @@ -1582,25 +1541,20 @@ namespace winrt::TerminalApp::implementation } // Method Description: - // - This is a helper to determine which direction an "Automatic" split should - // happen in for the active pane of this tab, but without using the ActualWidth() and - // ActualHeight() methods. - // - See Pane::PreCalculateAutoSplit + // - Calculate if a split is possible with the given direction and size. + // - Converts Automatic splits to an appropriate direction depending on space. // Arguments: - // - availableSpace: The theoretical space that's available for this Tab's content - // Return Value: - // - The SplitDirection that we should use for an `Automatic` split given - // `availableSpace` - SplitDirection TerminalTab::PreCalculateAutoSplit(winrt::Windows::Foundation::Size availableSpace) const - { - return _rootPane->PreCalculateAutoSplit(_activePane, availableSpace).value_or(SplitDirection::Right); - } - - bool TerminalTab::PreCalculateCanSplit(SplitDirection splitType, - const float splitSize, - winrt::Windows::Foundation::Size availableSpace) const + // - splitType: what direction to split. + // - splitSize: how big the new split should be. + // - availableSpace: how much space there is to work with. + // Return value: + // - This will return nullopt if a split of the given size/direction was not possible, + // or it will return the split direction with automatic converted to a cardinal direction. + std::optional TerminalTab::PreCalculateCanSplit(SplitDirection splitType, + const float splitSize, + winrt::Windows::Foundation::Size availableSpace) const { - return _rootPane->PreCalculateCanSplit(_activePane, splitType, splitSize, availableSpace).value_or(false); + return _rootPane->PreCalculateCanSplit(_activePane, splitType, splitSize, availableSpace).value_or(std::nullopt); } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index 701c2a1efd0..82f9f23210c 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -49,12 +49,10 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget ActivateBellIndicatorTimer(); float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const; - winrt::Microsoft::Terminal::Settings::Model::SplitDirection PreCalculateAutoSplit(winrt::Windows::Foundation::Size rootSize) const; - bool PreCalculateCanSplit(winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType, - const float splitSize, - winrt::Windows::Foundation::Size availableSpace) const; + std::optional PreCalculateCanSplit(winrt::Microsoft::Terminal::Settings::Model::SplitDirection splitType, + const float splitSize, + winrt::Windows::Foundation::Size availableSpace) const; - void ResizeContent(const winrt::Windows::Foundation::Size& newSize); void ResizePane(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction); bool NavigateFocus(const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction); bool SwapPane(const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction); @@ -122,7 +120,6 @@ namespace winrt::TerminalApp::implementation struct ControlEventTokens { winrt::event_token titleToken; - winrt::event_token fontToken; winrt::event_token colorToken; winrt::event_token taskbarToken; winrt::event_token readOnlyToken;