From 5ec7c0325e4efe6453986af4fdfca7b0db2f0a47 Mon Sep 17 00:00:00 2001 From: Juris Bogusevs Date: Thu, 23 May 2019 14:24:40 +0100 Subject: [PATCH] Closing the tab shifts focus to the right (#767) * On closing the tab - the focus is shifted to the right. --- src/cascadia/TerminalApp/App.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/cascadia/TerminalApp/App.cpp b/src/cascadia/TerminalApp/App.cpp index e5846810b..a0dbb9557 100644 --- a/src/cascadia/TerminalApp/App.cpp +++ b/src/cascadia/TerminalApp/App.cpp @@ -874,18 +874,26 @@ namespace winrt::TerminalApp::implementation } uint32_t tabIndexFromControl = 0; _tabView.Items().IndexOf(tabViewItem, tabIndexFromControl); - - if (tabIndexFromControl == _GetFocusedTabIndex()) - { - _tabView.SelectedIndex((tabIndexFromControl > 0) ? tabIndexFromControl - 1 : 1); - } + auto focusedTabIndex = _GetFocusedTabIndex(); // Removing the tab from the collection will destroy its control and disconnect its connection. _tabs.erase(_tabs.begin() + tabIndexFromControl); _tabView.Items().RemoveAt(tabIndexFromControl); - // ensure tabs and focus is sync - _tabView.SelectedIndex(tabIndexFromControl > 0 ? tabIndexFromControl - 1 : 0); + if (tabIndexFromControl == focusedTabIndex) + { + if (focusedTabIndex >= _tabs.size()) + { + focusedTabIndex = _tabs.size() - 1; + } + + if (focusedTabIndex < 0) + { + focusedTabIndex = 0; + } + + _SelectTab(focusedTabIndex); + } } // Method Description: