Skip to content

Commit

Permalink
getActiveInteractiveWindow to getActiveOrAssociatedInteractiveWindow (#…
Browse files Browse the repository at this point in the history
…10160)

* getActiveOrAssociatedInteractiveWindow

* fix prettier
  • Loading branch information
rebornix authored Jun 3, 2022
1 parent 8de113e commit 453f25d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/interactive-window/commands/exportCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ExportCommands implements IExportCommands, IDisposable {
// so we need to get the active editor
sourceDocument =
this.notebooks.activeNotebookEditor?.notebook ||
this.interactiveProvider?.getActiveInteractiveWindow()?.notebookDocument;
this.interactiveProvider?.getActiveOrAssociatedInteractiveWindow()?.notebookDocument;
if (!sourceDocument) {
traceInfo('Export called without a valid exportable document active');
return;
Expand Down
4 changes: 2 additions & 2 deletions src/interactive-window/interactiveWindowCommandListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class InteractiveWindowCommandListener implements IDataScienceCommandList
}

private async removeCellInInteractiveWindow(context?: NotebookCell) {
const interactiveWindow = this.interactiveWindowProvider.getActiveInteractiveWindow();
const interactiveWindow = this.interactiveWindowProvider.getActiveOrAssociatedInteractiveWindow();
const ranges =
context === undefined
? interactiveWindow?.notebookEditor?.selections
Expand Down Expand Up @@ -496,7 +496,7 @@ export class InteractiveWindowCommandListener implements IDataScienceCommandList
(w) => w.notebookUri?.toString() === notebookUri.toString()
);
} else {
targetInteractiveWindow = this.interactiveWindowProvider.getActiveInteractiveWindow();
targetInteractiveWindow = this.interactiveWindowProvider.getActiveOrAssociatedInteractiveWindow();
}
return targetInteractiveWindow;
}
Expand Down
6 changes: 4 additions & 2 deletions src/interactive-window/interactiveWindowProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class InteractiveWindowProvider
this.raiseOnDidChangeActiveInteractiveWindow();
}

public getActiveInteractiveWindow(): IInteractiveWindow | undefined {
public getActiveOrAssociatedInteractiveWindow(): IInteractiveWindow | undefined {
if (this.activeWindow) {
return this.activeWindow;
}
Expand All @@ -339,7 +339,9 @@ export class InteractiveWindowProvider
const targetInteractiveNotebookEditor =
resource && getResourceType(resource) === 'interactive' ? this.get(resource)?.notebookEditor : undefined;
const activeInteractiveNotebookEditor =
getResourceType(resource) === 'interactive' ? this.getActiveInteractiveWindow()?.notebookEditor : undefined;
getResourceType(resource) === 'interactive'
? this.getActiveOrAssociatedInteractiveWindow()?.notebookEditor
: undefined;

return targetInteractiveNotebookEditor || activeInteractiveNotebookEditor;
}
Expand Down
5 changes: 4 additions & 1 deletion src/interactive-window/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export interface IInteractiveWindowProvider {
* @param owner The URI of a text document which may be associated with an interactive window.
*/
get(owner: Uri): IInteractiveWindow | undefined;
getActiveInteractiveWindow(): IInteractiveWindow | undefined;
/**
* The active interactive window if it has the focus, or the interactive window associated with current active text editor
*/
getActiveOrAssociatedInteractiveWindow(): IInteractiveWindow | undefined;
}

export interface IInteractiveBase extends Disposable {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/common/activeEditorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ export class ActiveEditorContextService implements IExtensionSingleActivationSer
private updateSelectedKernelContext() {
const document =
this.vscNotebook.activeNotebookEditor?.notebook ||
this.interactiveProvider?.getActiveInteractiveWindow()?.notebookEditor?.notebook;
this.interactiveProvider?.getActiveOrAssociatedInteractiveWindow()?.notebookEditor?.notebook;
if (document && isJupyterNotebook(document) && this.controllers.getSelectedNotebookController(document)) {
this.isJupyterKernelSelected.set(true).catch(noop);
} else {
this.isJupyterKernelSelected.set(false).catch(noop);
}
}
private updateContextOfActiveInteractiveWindowKernel() {
const notebook = this.interactiveProvider?.getActiveInteractiveWindow()?.notebookEditor?.notebook;
const notebook = this.interactiveProvider?.getActiveOrAssociatedInteractiveWindow()?.notebookEditor?.notebook;
const kernel = notebook ? this.kernelProvider.get(notebook.uri) : undefined;
if (kernel) {
const canStart = kernel.status !== 'unknown';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class NotebookWatcher implements INotebookWatcher {
);
}
private getActiveInteractiveWindowDocument() {
const interactiveWindow = this.interactiveWindowProvider.getActiveInteractiveWindow();
const interactiveWindow = this.interactiveWindowProvider.getActiveOrAssociatedInteractiveWindow();
if (!interactiveWindow) {
return;
}
Expand Down

0 comments on commit 453f25d

Please sign in to comment.