Skip to content

Commit

Permalink
co-authored from @amunger via #24451
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Nov 18, 2024
1 parent 79a1478 commit 140771b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/client/repl/nativeRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class NativeRepl implements Disposable {
/**
* Function that opens interactive repl, selects kernel, and send/execute code to the native repl.
*/
public async sendToNativeRepl(code?: string): Promise<void> {
public async sendToNativeRepl(code?: string | undefined, preserveFocus: boolean = true): Promise<void> {
const mementoValue = (await this.context.globalState.get(NATIVE_REPL_URI_MEMENTO)) as string | undefined;
let mementoUri = mementoValue ? Uri.parse(mementoValue) : undefined;
const openNotebookDocuments = workspace.notebookDocuments.map((doc) => doc.uri);
Expand All @@ -177,7 +177,12 @@ export class NativeRepl implements Disposable {
await this.cleanRepl();
}

const notebookEditor = await openInteractiveREPL(this.replController, this.notebookDocument, mementoUri);
const notebookEditor = await openInteractiveREPL(
this.replController,
this.notebookDocument,
mementoUri,
preserveFocus,
);

this.notebookDocument = notebookEditor.notebook;
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.notebookDocument.uri.toString());
Expand Down
3 changes: 2 additions & 1 deletion src/client/repl/replCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function openInteractiveREPL(
notebookController: NotebookController,
notebookDocument: NotebookDocument | undefined,
mementoValue: Uri | undefined,
preserveFocus: boolean = true,
): Promise<NotebookEditor> {
let viewColumn = ViewColumn.Beside;
if (mementoValue) {
Expand All @@ -40,7 +41,7 @@ export async function openInteractiveREPL(
const editor = window.showNotebookDocument(notebookDocument!, {
viewColumn,
asRepl: 'Python REPL',
preserveFocus: true,
preserveFocus,
});
await commands.executeCommand('notebook.selectKernel', {
editor,
Expand Down
2 changes: 1 addition & 1 deletion src/client/repl/replCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function registerStartNativeReplCommand(
if (interpreter) {
if (interpreter) {
const nativeRepl = await getNativeRepl(interpreter, disposables, context);
await nativeRepl.sendToNativeRepl();
await nativeRepl.sendToNativeRepl(undefined, false);
}
}
}),
Expand Down

0 comments on commit 140771b

Please sign in to comment.