Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove notebookDecoration API usage #10048

Merged
merged 1 commit into from
May 16, 2022
Merged
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
28 changes: 5 additions & 23 deletions src/interactive-window/interactiveWindow.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import {
Range,
workspace,
WorkspaceEdit,
notebooks,
NotebookEditor,
Disposable,
window,
ThemeColor,
NotebookController
} from 'vscode';
import { IPythonExtensionChecker } from '../platform/api/types';
Expand Down Expand Up @@ -558,7 +556,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
// Scroll if the initial placement of this cell was scrolled as well
const settings = this.configuration.getSettings(this.owningResource);
if (settings.alwaysScrollOnNewCell || wasScrolled) {
this.revealCell(cell, false);
this.revealCell(cell);
}

let detachKernel = async () => noop();
Expand Down Expand Up @@ -600,7 +598,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {

// After execution see if we need to scroll to this cell or not.
if (settings.alwaysScrollOnNewCell || wasScrolled) {
this.revealCell(cell, false);
this.revealCell(cell);
}
} finally {
await detachKernel();
Expand Down Expand Up @@ -659,35 +657,19 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
.getCells()
.find((cell) => getInteractiveCellMetadata(cell)?.id === id);
if (matchingCell) {
this.revealCell(matchingCell, true);
this.revealCell(matchingCell);
}
}

private revealCell(notebookCell: NotebookCell, useDecoration: boolean) {
private revealCell(notebookCell: NotebookCell) {
const notebookRange = new NotebookRange(notebookCell.index, notebookCell.index + 1);
this.pendingNotebookScrolls.push(notebookRange);
const decorationType = useDecoration
? notebooks.createNotebookEditorDecorationType({
backgroundColor: new ThemeColor('peekViewEditor.background'),
top: {}
})
: undefined;
// This will always try to reveal the whole cell--input + output combined
setTimeout(() => {
this.notebookEditor.revealRange(notebookRange, NotebookEditorRevealType.Default);

// No longer pending
this.pendingNotebookScrolls.shift();

// Also add a decoration to make it look highlighted (peek background color)
if (decorationType) {
this.notebookEditor.setDecorations(decorationType, notebookRange);

// Fire another timeout to dispose of the decoration
setTimeout(() => {
decorationType.dispose();
}, 2000);
}
}, 200); // Rendering output is async so the output is not guaranteed to immediately exist
}

Expand Down Expand Up @@ -795,7 +777,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
// of the history. The jupyter.alwaysScrollOnNewCell setting overrides this to always scroll
// to newly-inserted cells.
if (settings.alwaysScrollOnNewCell || shouldScroll) {
this.revealCell(cell, false);
this.revealCell(cell);
}

return { cell, wasScrolled: shouldScroll };
Expand Down