Skip to main content

tabAPI

MS Code Extension API


MS Code Extension API / core/extensionAPI/modules/window/tabAPI

core/extensionAPI/modules/window/tabAPI

Functions

createTabAPI()

createTabAPI(): object

Defined in: core/extensionAPI/modules/window/tabAPI.ts:11

Factory function to create the Tab API for extensions. Provides methods to manage the editor tab system and subscribe to tab-related events.

Returns

closeAllTabs

closeAllTabs: () => void

Closes all currently open tabs at once.

Returns

void

closeTab

closeTab: (tabId) => void

Closes a specific tab by its unique identifier.

Parameters
tabId

string

The unique ID of the tab to be closed.

Returns

void

focusTab

focusTab: (tabId) => void

Programmatically switches focus to a specific tab.

Parameters
tabId

string

The unique ID of the tab to focus.

Returns

void

onDidChangeActiveTab

onDidChangeActiveTab: (handler) => object

Fired when the user switches between tabs or when the active tab changes.

Parameters
handler

(tab) => void

Callback function receiving the new active Tab or undefined if all tabs are closed.

Returns

object

An object with a dispose method to unsubscribe.

dispose

dispose: () => void

Returns

void

onDidCloseTab

onDidCloseTab: (handler) => object

Fired when a tab is closed.

Parameters
handler

(tabId) => void

Callback function receiving the ID of the closed tab.

Returns

object

An object with a dispose method to unsubscribe.

dispose

dispose: () => void

Returns

void

onDidOpenTab

onDidOpenTab: (handler) => object

Fired immediately after a new tab is opened.

Parameters
handler

(tab) => void

Callback function receiving the opened Tab object.

Returns

object

An object with a dispose method to unsubscribe.

dispose

dispose: () => void

Returns

void

openTab

openTab: (tabOptions) => void

Opens a new tab or switches focus to it if it is already open.

Parameters
tabOptions

Partial<Tab> & object

Configuration for the tab. Must include unique 'id', 'title', and 'type'.

Returns

void

Example
mscode.window.openTab({
id: '/path/file.js',
title: 'file.js',
type: 'code',
filePath: '/path/file.js'
});
activeTab
Get Signature

get activeTab(): Tab | undefined

Retrieves the currently active (focused) tab.

Returns

Tab | undefined

The active Tab object or undefined if no tabs are open.

tabs
Get Signature

get tabs(): Tab[]

Retrieves a list of all currently open tabs.

Returns

Tab[]

An array of Tab objects.