Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/cascadia/LocalTests_TerminalApp/TabTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace TerminalAppLocalTests
TEST_METHOD(CreateTerminalPage);

TEST_METHOD(TryDuplicateBadTab);
TEST_METHOD(DuplicateTabAlwaysOpensAfterCurrent);
TEST_METHOD(TryDuplicateBadPane);

TEST_METHOD(TryZoomPane);
Expand Down Expand Up @@ -442,6 +443,32 @@ namespace TerminalAppLocalTests
VERIFY_SUCCEEDED(result);
}

void TabTests::DuplicateTabAlwaysOpensAfterCurrent()
{
auto page = _commonSetup();
VERIFY_IS_NOT_NULL(page);

Log::Comment(L"Create three tabs with new tabs opening at the end");
TestOnUIThread([&page]() {
page->_settings.WindowSettingsDefaults().NewTabPosition(NewTabPosition::AfterLastTab);

NewTerminalArgs newTerminalArgs{ 1 };
page->_OpenNewTab(newTerminalArgs);
page->_OpenNewTab(newTerminalArgs);

VERIFY_ARE_EQUAL(3u, page->_tabs.Size());
});

Log::Comment(L"Duplicate the middle tab");
TestOnUIThread([&page]() {
page->_SelectTab(1);
page->_DuplicateFocusedTab();

VERIFY_ARE_EQUAL(4u, page->_tabs.Size());
VERIFY_ARE_EQUAL(2u, page->_GetFocusedTabIndex().value(), L"Duplicated tabs should open next to their source tab.");
});
}

void TabTests::TryDuplicateBadPane()
{
// * Create a tab with a profile with GUID 1
Expand Down
7 changes: 2 additions & 5 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,8 @@ namespace winrt::TerminalApp::implementation
// In the future, it may be preferable to just duplicate the
// current control's live settings (which will include changes
// made through VT).
uint32_t insertPosition = _tabs.Size();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least this change gets rid of this initialize-then-modify antipattern.

if (_currentWindowSettings().NewTabPosition() == NewTabPosition::AfterCurrentTab)
{
insertPosition = tab.TabViewIndex() + 1;
}
// Duplicate tabs intentionally ignore NewTabPosition() and always open next to the source tab.
const auto insertPosition = tab.TabViewIndex() + 1;
Comment thread
OmarMashal0 marked this conversation as resolved.
_CreateNewTabFromPane(_MakePane(nullptr, tab, nullptr), insertPosition);

const auto runtimeTabText{ tab.GetTabText() };
Expand Down