diff --git a/src/client/repl/replCommandHandler.ts b/src/client/repl/replCommandHandler.ts index 630eddfdd565..4c856734c2ca 100644 --- a/src/client/repl/replCommandHandler.ts +++ b/src/client/repl/replCommandHandler.ts @@ -7,12 +7,18 @@ import { NotebookEdit, WorkspaceEdit, Uri, + window, + TabGroup, } from 'vscode'; import { getExistingReplViewColumn, getTabNameForUri } from './replUtils'; import { showNotebookDocument } from '../common/vscodeApis/windowApis'; import { openNotebookDocument, applyEdit } from '../common/vscodeApis/workspaceApis'; import { executeCommand } from '../common/vscodeApis/commandApis'; +export function getNewReplViewColumn(tabGroups: readonly TabGroup[]): ViewColumn { + return tabGroups.some((tabGroup) => tabGroup.tabs.length > 0) ? ViewColumn.Beside : ViewColumn.Active; +} + /** * Function that opens/show REPL using IW UI. */ @@ -20,7 +26,7 @@ export async function openInteractiveREPL( notebookDocument: NotebookDocument | Uri | undefined, preserveFocus: boolean = true, ): Promise<{ notebookEditor: NotebookEditor; documentCreated: boolean } | undefined> { - let viewColumn = ViewColumn.Beside; + let viewColumn = getNewReplViewColumn(window.tabGroups.all); let alreadyExists = false; if (notebookDocument instanceof Uri) { // Case where NotebookDocument is undefined, but workspace mementoURI exists. diff --git a/src/test/repl/replCommandHandler.unit.test.ts b/src/test/repl/replCommandHandler.unit.test.ts new file mode 100644 index 000000000000..b7eabac2e8b3 --- /dev/null +++ b/src/test/repl/replCommandHandler.unit.test.ts @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import { expect } from 'chai'; +import { TabGroup, ViewColumn } from 'vscode'; +import { getNewReplViewColumn } from '../../client/repl/replCommandHandler'; + +suite('REPL - command handler', () => { + test('opens a new REPL in the active group when no tabs are open', () => { + const emptyTabGroup = ({ tabs: [] } as unknown) as TabGroup; + + expect(getNewReplViewColumn([emptyTabGroup])).to.equal(ViewColumn.Active); + }); + + test('opens a new REPL beside existing tabs', () => { + const emptyTabGroup = ({ tabs: [] } as unknown) as TabGroup; + const tabGroupWithOpenTab = ({ tabs: [{}] } as unknown) as TabGroup; + + expect(getNewReplViewColumn([emptyTabGroup, tabGroupWithOpenTab])).to.equal(ViewColumn.Beside); + }); +});