fix tab control and tabs is not synced after focused tab is removed (#737)
* trim duplicated github627 * fix tab control and tabs is not synced after focused tab is removed
This commit is contained in:
parent
8c177fab4f
commit
ef8e20af51
|
@ -631,8 +631,7 @@ namespace winrt::TerminalApp::implementation
|
|||
// reloading settings)
|
||||
const auto* const p = _settings->FindProfile(tabProfile);
|
||||
|
||||
// TODO: GitHub:627: Need a better story for what should happen when the last tab is closed.
|
||||
if (p != nullptr && p->GetCloseOnExit() && _tabs.size() > 1)
|
||||
if (p != nullptr && p->GetCloseOnExit())
|
||||
{
|
||||
_RemoveTabViewItem(tabViewItem);
|
||||
}
|
||||
|
@ -668,19 +667,9 @@ namespace winrt::TerminalApp::implementation
|
|||
// - Close the currently focused tab. Focus will move to the left, if possible.
|
||||
void App::_CloseFocusedTab()
|
||||
{
|
||||
// TODO: GitHub:627: Need a better story for what should happen when the last tab is closed.
|
||||
if (_tabs.size() > 1)
|
||||
{
|
||||
int focusedTabIndex = _GetFocusedTabIndex();
|
||||
std::shared_ptr<Tab> focusedTab{ _tabs[focusedTabIndex] };
|
||||
|
||||
// We're not calling _FocusTab here because it makes an async dispatch
|
||||
// that is practically guaranteed to not happen before we delete the tab.
|
||||
_tabView.SelectedIndex((focusedTabIndex > 0) ? focusedTabIndex - 1 : 1);
|
||||
_tabView.Items().RemoveAt(focusedTabIndex);
|
||||
_tabs.erase(_tabs.begin() + focusedTabIndex);
|
||||
_UpdateTabView();
|
||||
}
|
||||
int focusedTabIndex = _GetFocusedTabIndex();
|
||||
std::shared_ptr<Tab> focusedTab{ _tabs[focusedTabIndex] };
|
||||
_RemoveTabViewItem(focusedTab->GetTabViewItem());
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
@ -777,14 +766,9 @@ namespace winrt::TerminalApp::implementation
|
|||
// - eventArgs: the event's constituent arguments
|
||||
void App::_OnTabClosing(const IInspectable& sender, const MUX::Controls::TabViewTabClosingEventArgs& eventArgs)
|
||||
{
|
||||
// TODO: GitHub:627: Need a better story for what should happen when the last tab is closed.
|
||||
// Don't allow the user to close the last tab ..
|
||||
// .. yet.
|
||||
if (_tabs.size() > 1)
|
||||
{
|
||||
const auto tabViewItem = eventArgs.Item();
|
||||
_RemoveTabViewItem(tabViewItem);
|
||||
}
|
||||
const auto tabViewItem = eventArgs.Item();
|
||||
_RemoveTabViewItem(tabViewItem);
|
||||
|
||||
// If we don't cancel the event, the TabView will remove the item itself.
|
||||
eventArgs.Cancel(true);
|
||||
}
|
||||
|
@ -834,11 +818,7 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
if (eventArgs.GetCurrentPoint(_root).Properties().IsMiddleButtonPressed())
|
||||
{
|
||||
// TODO: GitHub:627: Need a better story for what should happen when the last tab is closed.
|
||||
if (_tabs.size() > 1)
|
||||
{
|
||||
_RemoveTabViewItem(sender);
|
||||
}
|
||||
_RemoveTabViewItem(sender);
|
||||
eventArgs.Handled(true);
|
||||
}
|
||||
}
|
||||
|
@ -849,6 +829,12 @@ namespace winrt::TerminalApp::implementation
|
|||
// - tabViewItem: the TabViewItem in the TabView that is being removed.
|
||||
void App::_RemoveTabViewItem(const IInspectable& tabViewItem)
|
||||
{
|
||||
// TODO: GitHub:627: Need a better story for what should happen when the last tab is closed.
|
||||
if (_tabs.size() <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t tabIndexFromControl = 0;
|
||||
_tabView.Items().IndexOf(tabViewItem, tabIndexFromControl);
|
||||
|
||||
|
@ -860,6 +846,9 @@ namespace winrt::TerminalApp::implementation
|
|||
// 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);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
|
Loading…
Reference in a new issue