Skip to content

Add --position argument to wt new-tab command#20082

Open
Jotanune wants to merge 1 commit intomicrosoft:mainfrom
Jotanune:feature/new-tab-position-14687
Open

Add --position argument to wt new-tab command#20082
Jotanune wants to merge 1 commit intomicrosoft:mainfrom
Jotanune:feature/new-tab-position-14687

Conversation

@Jotanune
Copy link
Copy Markdown

@Jotanune Jotanune commented Apr 6, 2026

Summary of the Pull Request

Adds a --position argument to the wt new-tab subcommand, allowing users to control where new tabs are inserted without changing the global newTabPosition setting.

This addresses #14687.

References and Relevant Issues

Closes #14687

Detailed Description of the Pull Request / Additional comments

Changes:

  • ActionArgs.idl / ActionArgs.h: Added Position property (IReference<NewTabPosition>) to NewTabArgs, with full JSON serialization, equality, copy, and hash support.
  • GlobalAppSettings.idl / ActionArgs.idl: Moved NewTabPosition enum from GlobalAppSettings.idl to ActionArgs.idl to avoid circular IDL import dependencies. The enum remains accessible to GlobalAppSettings through the transitive import chain.
  • AppCommandlineArgs.h/.cpp: Registered --position CLI option in _buildNewTabParser(), accepting afterCurrentTab and afterLastTab string values.
  • AppActionHandlers.cpp: Modified _HandleNewTab to extract the position from NewTabArgs, calculate the insert index, and pass it to _OpenNewTab.
  • TerminalPage.h / TabManagement.cpp: Updated _OpenNewTab signature to accept an insertPosition parameter, forwarded to _CreateNewTabFromPane.
  • Resources.resw: Added CmdTabPositionArgDesc localization resource string.
  • profiles.schema.json: Added position property to NewTabAction schema.
  • CommandlineTest.cpp: Added ParseNewTabWithPosition test method with 4 test cases.

Usage:

# Open a new tab after the current tab
wt new-tab --position afterCurrentTab

# Open a new tab at the end (default)
wt new-tab --position afterLastTab

# Combined with other arguments
wt new-tab --position afterCurrentTab --profile cmd

Validation Steps Performed

  • Code compiles without errors (x64 Debug)
  • All modified files verified for correctness
  • Unit test ParseNewTabWithPosition added with 4 test cases
  • JSON schema updated

Adds a --position argument to the wt new-tab subcommand, allowing users to control where new tabs are inserted without changing the global newTabPosition setting.

- Add Position property (IReference<NewTabPosition>) to NewTabArgs
- Move NewTabPosition enum from GlobalAppSettings.idl to ActionArgs.idl to avoid circular IDL imports
- Register --position CLI option in _buildNewTabParser() accepting afterCurrentTab and afterLastTab
- Calculate insert position in _HandleNewTab and pass through _OpenNewTab to _CreateNewTabFromPane
- Add JSON schema support for the position property in NewTabAction
- Add CmdTabPositionArgDesc localization resource string
- Add ParseNewTabWithPosition test covering all cases

Closes microsoft#14687
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Task It's a feature request, but it doesn't really need a major design. Area-Commandline wt.exe's commandline arguments Product-Terminal The new Windows Terminal. labels Apr 6, 2026
@Jotanune
Copy link
Copy Markdown
Author

Jotanune commented Apr 6, 2026

@Jotanune please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@Jotanune Jotanune marked this pull request as ready for review April 6, 2026 20:37
{
if (position.Value() == NewTabPosition::AfterCurrentTab)
{
auto currentTabIndex = _GetFocusedTabIndex();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this get the index of the tab in which the wt command was run? From the function name, I'd assume it doesn't.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are absolutely right. _GetFocusedTabIndex() grabs the currently active tab, which completely fails the sleep 10 edge-case if the user switches tabs during execution. I'll look into the proper way to resolve the origin tab and update the PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm gonna tell you it's not possible in the general case to do so. :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Haha, thanks for the reality check @DHowett that definitely saves me from going down an impossible rabbit hole with WT_SESSION and IPC messages. 😅
​Given that tracking the exact originating tab asynchronously isn't technically feasible in the general architecture, would using the currently focused tab (as currently implemented via _GetFocusedTabIndex()) be an acceptable compromise for this feature? It solves the immediate UX need for synchronous commands like your vspwsh alias mentioned in the issue, even if it falls short on the sleep 10 edge-case.
​Let me know if you guys are happy with this trade-off, or if I should add a specific comment in the code/docs about this limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Commandline wt.exe's commandline arguments Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wt new-tab open near current tab

3 participants