Provide workaround for _GetFocusedTabIndex (#1117)

Use tabview.SelectedIndex for setting focus tab

References
  Closes #1100, Closes #1039, Closes #1074
This commit is contained in:
Summon528 2019-06-05 04:18:23 +08:00 committed by Michael Niksa
parent 880272c748
commit d51ce7021c

View File

@ -631,6 +631,8 @@ namespace winrt::TerminalApp::implementation
void App::_SetFocusedTabIndex(int tabIndex)
{
// GH#1117: This is a workaround because _tabView.SelectedIndex(tabIndex)
// sometimes set focus to an incorrect tab after removing some tabs
auto tab = _tabs.at(tabIndex);
_tabView.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [tab, this](){
auto tabViewItem = tab->GetTabViewItem();
@ -815,7 +817,14 @@ namespace winrt::TerminalApp::implementation
// - the index of the currently focused tab if there is one, else -1
int App::_GetFocusedTabIndex() const
{
return _tabView.SelectedIndex();
// GH#1117: This is a workaround because _tabView.SelectedIndex()
// sometimes return incorrect result after removing some tabs
uint32_t focusedIndex;
if (_tabView.Items().IndexOf(_tabView.SelectedItem(), focusedIndex))
{
return focusedIndex;
}
return -1;
}
void App::_OpenSettings()