Skip to content

Commit 68827af

Browse files
authored
Open native REPL in active group when no tabs are open (#26210)
## Summary - open a new native REPL in the active editor group when no tabs are open - preserve side-by-side placement when another tab is open and preserve the column of an existing REPL - add regression coverage for empty and non-empty editor layouts ## Testing - `npx tsc -p . --pretty false` - `npm run test:unittests -- --grep "REPL - command handler"` - `npx eslint src/client/repl/replCommandHandler.ts src/test/repl/replCommandHandler.unit.test.ts` - `npx prettier --check src/client/repl/replCommandHandler.ts src/test/repl/replCommandHandler.unit.test.ts` Fixes #24010
1 parent 6a49757 commit 68827af

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎src/client/repl/replCommandHandler.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ import {
77
NotebookEdit,
88
WorkspaceEdit,
99
Uri,
10+
window,
11+
TabGroup,
1012
} from 'vscode';
1113
import { getExistingReplViewColumn, getTabNameForUri } from './replUtils';
1214
import { showNotebookDocument } from '../common/vscodeApis/windowApis';
1315
import { openNotebookDocument, applyEdit } from '../common/vscodeApis/workspaceApis';
1416
import { executeCommand } from '../common/vscodeApis/commandApis';
1517

18+
export function getNewReplViewColumn(tabGroups: readonly TabGroup[]): ViewColumn {
19+
return tabGroups.some((tabGroup) => tabGroup.tabs.length > 0) ? ViewColumn.Beside : ViewColumn.Active;
20+
}
21+
1622
/**
1723
* Function that opens/show REPL using IW UI.
1824
*/
1925
export async function openInteractiveREPL(
2026
notebookDocument: NotebookDocument | Uri | undefined,
2127
preserveFocus: boolean = true,
2228
): Promise<{ notebookEditor: NotebookEditor; documentCreated: boolean } | undefined> {
23-
let viewColumn = ViewColumn.Beside;
29+
let viewColumn = getNewReplViewColumn(window.tabGroups.all);
2430
let alreadyExists = false;
2531
if (notebookDocument instanceof Uri) {
2632
// Case where NotebookDocument is undefined, but workspace mementoURI exists.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import { expect } from 'chai';
5+
import { TabGroup, ViewColumn } from 'vscode';
6+
import { getNewReplViewColumn } from '../../client/repl/replCommandHandler';
7+
8+
suite('REPL - command handler', () => {
9+
test('opens a new REPL in the active group when no tabs are open', () => {
10+
const emptyTabGroup = ({ tabs: [] } as unknown) as TabGroup;
11+
12+
expect(getNewReplViewColumn([emptyTabGroup])).to.equal(ViewColumn.Active);
13+
});
14+
15+
test('opens a new REPL beside existing tabs', () => {
16+
const emptyTabGroup = ({ tabs: [] } as unknown) as TabGroup;
17+
const tabGroupWithOpenTab = ({ tabs: [{}] } as unknown) as TabGroup;
18+
19+
expect(getNewReplViewColumn([emptyTabGroup, tabGroupWithOpenTab])).to.equal(ViewColumn.Beside);
20+
});
21+
});

0 commit comments

Comments
 (0)