Fixed bug: Execute cell should scroll to its results (#5861)

This commit is contained in:
Gene Lee
2019-06-04 16:03:55 -07:00
committed by GitHub
parent eda96c046a
commit bf643cc85f

View File

@@ -43,7 +43,7 @@ export class OutputComponent extends AngularDisposable implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.renderOutput(); this.renderOutput(true);
this._initialized = true; this._initialized = true;
this._register(Event.debounce(this.cellModel.notebookModel.layoutChanged, (l, e) => e, 50, /*leading=*/false) this._register(Event.debounce(this.cellModel.notebookModel.layoutChanged, (l, e) => e, 50, /*leading=*/false)
(() => this.renderOutput())); (() => this.renderOutput()));
@@ -70,11 +70,21 @@ export class OutputComponent extends AngularDisposable implements OnInit {
} }
} }
private renderOutput() { private renderOutput(focusAndScroll: boolean = false): void {
let options = outputProcessor.getBundleOptions({ value: this.cellOutput, trusted: this.trustedMode }); let options = outputProcessor.getBundleOptions({ value: this.cellOutput, trusted: this.trustedMode });
options.themeService = this._themeService; options.themeService = this._themeService;
// TODO handle safe/unsafe mapping // TODO handle safe/unsafe mapping
this.createRenderedMimetype(options, this.outputElement.nativeElement); this.createRenderedMimetype(options, this.outputElement.nativeElement);
if (focusAndScroll) {
this.setFocusAndScroll(this.outputElement.nativeElement);
}
}
private setFocusAndScroll(node: HTMLElement): void {
if (node) {
node.focus();
node.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
} }
public layout(): void { public layout(): void {