Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Resolve issues with Notebook Handler #163

Merged
merged 5 commits into from
Nov 11, 2019
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
11 changes: 9 additions & 2 deletions src/handlers/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export class CellManager implements IDisposable {
});

this.breakpointsModel.changed.connect(async () => {
if (!this.activeCell || this.activeCell.isDisposed) {
if (
!this.activeCell ||
!this.activeCell.isVisible ||
this.activeCell.isDisposed
) {
return;
}
this.addBreakpointsToEditor(this.activeCell);
Expand All @@ -69,7 +73,7 @@ export class CellManager implements IDisposable {

// TODO: call when the debugger stops
private cleanupHighlight() {
if (!this.activeCell) {
if (!this.activeCell || this.activeCell.isDisposed) {
return;
}
const editor = this.activeCell.editor as CodeMirrorEditor;
Expand Down Expand Up @@ -165,6 +169,9 @@ export class CellManager implements IDisposable {
}

protected removeListener(cell: CodeCell) {
if (cell.isDisposed) {
return;
}
const editor = cell.editor as CodeMirrorEditor;
editor.editor.off('gutterClick', this.onGutterClick);
editor.editor.off('renderLine', this.onNewRenderLine);
Expand Down
15 changes: 10 additions & 5 deletions src/handlers/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class NotebookHandler implements IDisposable {
this.debuggerModel = options.debuggerService.model;
this.debuggerService = options.debuggerService;
this.notebookTracker = options.tracker;
this.id = options.id;
this.breakpoints = this.debuggerModel.breakpointsModel;

this.cellManager = new CellManager({
Expand All @@ -46,30 +47,34 @@ export class NotebookHandler implements IDisposable {
}
this.isDisposed = true;
this.cellManager.dispose();
this.notebookTracker.activeCellChanged.disconnect(
this.onActiveCellChanged,
this
);
Signal.clearData(this);
}

protected onActiveCellChanged(
notebookTracker: NotebookTracker,
codeCell: CodeCell
) {
this.cellManager.activeCell = codeCell;
if (notebookTracker.currentWidget.id !== this.id) {
return;
}
// TODO: do we need this requestAnimationFrame?
requestAnimationFrame(() => {
this.cellManager.activeCell = codeCell;
});
}

private notebookTracker: INotebookTracker;
private debuggerModel: Debugger.Model;
private debuggerService: IDebugger;
private breakpoints: Breakpoints.Model;
private cellManager: CellManager;
private id: string;
}

export namespace NotebookHandler {
export interface IOptions {
debuggerService: IDebugger;
tracker: INotebookTracker;
id?: string;
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class DebuggerHandler<H extends ConsoleHandler | NotebookHandler> {
if (debug.model && !this.handlers[widget.id]) {
const handler = new this.builder({
tracker: tracker,
debuggerService: debug
debuggerService: debug,
id: widget.id
});
this.handlers[widget.id] = handler;
widget.disposed.connect(() => {
Expand Down
4 changes: 3 additions & 1 deletion style/breakpoints.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
}

.jp-CodeCell.jp-mod-selected .CodeMirror-gutter-wrapper:hover::after,
.jp-Editor.jp-mod-focused .CodeMirror-gutter-wrapper:hover::after {
.jp-Editor.jp-mod-focused
.CodeMirror:not(.jp-mod-readOnly)
.CodeMirror-gutter-wrapper:hover::after {
opacity: 0.5;
}