Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/client/repl/replCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ 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.
*/
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.
Expand Down
21 changes: 21 additions & 0 deletions src/test/repl/replCommandHandler.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading