diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index 7cebf63ea09..3ad4bdb73b8 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -882,7 +882,11 @@ Active pane moved to "{0}" tab in "{1}" window - {Locked="{0}"}{Locked="{1}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the tab the pane was moved to. {1} is the name of the window the pane was moved to. + {Locked="{0}"}{Locked="{1}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the tab the pane was moved to. {1} is the name of the window the pane was moved to. Replaced in 1.19 by TerminalPage_PaneMovedAnnouncement_ExistingWindow2 + + + Active pane moved to "{0}" window + {Locked="{0}"}This text is read out by screen readers upon a successful pane movement. {0} is the name of the window the pane was moved to. Active pane moved to new window diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 1f8552de39c..21521e2641f 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -498,7 +498,7 @@ namespace winrt::TerminalApp::implementation // * B (tabIndex=1): We'll want to focus tab A (now in index 0) // * C (tabIndex=2): We'll want to focus tab B (now in index 1) // * D (tabIndex=3): We'll want to focus tab C (now in index 2) - const auto newSelectedIndex = std::clamp(tabIndex - 1, 0, _tabs.Size()); + const auto newSelectedIndex = std::clamp(tabIndex - 1, 0, _tabs.Size() - 1); // _UpdatedSelectedTab will do the work of setting up the new tab as // the focused one, and unfocusing all the others. auto newSelectedTab{ _tabs.GetAt(newSelectedIndex) }; @@ -665,7 +665,7 @@ namespace winrt::TerminalApp::implementation { uint32_t tabIndexFromControl{}; const auto items{ _tabView.TabItems() }; - if (items.IndexOf(tabViewItem, tabIndexFromControl)) + if (items.IndexOf(tabViewItem, tabIndexFromControl) && tabIndexFromControl < _tabs.Size()) { // If IndexOf returns true, we've actually got an index return _tabs.GetAt(tabIndexFromControl); @@ -1022,7 +1022,8 @@ namespace winrt::TerminalApp::implementation // - suggestedNewTabIndex: the new index of the tab, might get clamped to fit int the tabs row boundaries // Return Value: // - - void TerminalPage::_TryMoveTab(const uint32_t currentTabIndex, const int32_t suggestedNewTabIndex) + void TerminalPage::_TryMoveTab(const uint32_t currentTabIndex, + const int32_t suggestedNewTabIndex) { auto newTabIndex = gsl::narrow_cast(std::clamp(suggestedNewTabIndex, 0, _tabs.Size() - 1)); if (currentTabIndex != newTabIndex) @@ -1064,16 +1065,21 @@ namespace winrt::TerminalApp::implementation if (from.has_value() && to.has_value() && to != from) { - auto& tabs{ _tabs }; - auto tab = tabs.GetAt(from.value()); - tabs.RemoveAt(from.value()); - tabs.InsertAt(to.value(), tab); - _UpdateTabIndices(); + try + { + auto& tabs{ _tabs }; + auto tab = tabs.GetAt(from.value()); + tabs.RemoveAt(from.value()); + tabs.InsertAt(to.value(), tab); + _UpdateTabIndices(); + } + CATCH_LOG(); } _rearranging = false; - if (to.has_value()) + if (to.has_value() && + *to < gsl::narrow_cast(TabRow().TabView().TabItems().Size())) { // Selecting the dropped tab TabRow().TabView().SelectedIndex(to.value()); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index f87ddc4ac87..a39d8863688 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -2026,9 +2026,6 @@ namespace winrt::TerminalApp::implementation { if (const auto pane{ terminalTab->GetActivePane() }) { - // Get the tab title _before_ moving things around in case the tabIdx doesn't point to the right one after the move - const auto tabTitle = _tabs.GetAt(tabIdx).Title(); - auto startupActions = pane->BuildStartupActions(0, 1, true, true); _DetachPaneFromWindow(pane); _MoveContent(std::move(startupActions.args), windowId, tabIdx); @@ -2047,7 +2044,7 @@ namespace winrt::TerminalApp::implementation { autoPeer.RaiseNotificationEvent(Automation::Peers::AutomationNotificationKind::ActionCompleted, Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, - fmt::format(std::wstring_view{ RS_(L"TerminalPage_PaneMovedAnnouncement_ExistingWindow") }, tabTitle, windowId), + fmt::format(std::wstring_view{ RS_(L"TerminalPage_PaneMovedAnnouncement_ExistingWindow2") }, windowId), L"TerminalPageMovePaneToExistingWindow" /* unique name for this notification category */); } } @@ -2064,7 +2061,7 @@ namespace winrt::TerminalApp::implementation // Moving the pane from the current tab might close it, so get the next // tab before its index changes. - if (_tabs.Size() > tabIdx) + if (tabIdx < _tabs.Size()) { auto targetTab = _GetTerminalTabImpl(_tabs.GetAt(tabIdx)); // if the selected tab is not a host of terminals (e.g. settings)