Editor focus based on activeCell, create text in edit, scroll to active (#3725)

This commit is contained in:
Chris LaFreniere
2019-01-14 16:39:36 -08:00
committed by GitHub
parent 1fa03b5c74
commit 6dc4096299
4 changed files with 37 additions and 6 deletions

View File

@@ -60,7 +60,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
@Inject(IOpenerService) private readonly openerService: IOpenerService,
) {
super();
this.isEditMode = false;
this.isEditMode = true;
this.isLoading = true;
this._cellToggleMoreActions = this._instantiationService.createInstance(CellToggleMoreActions);
}
@@ -87,10 +87,10 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
}
ngOnInit() {
this.updatePreview();
this.setLoading(false);
this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this));
this.updateTheme(this.themeService.getColorTheme());
this.setFocusAndScroll();
this._register(this.cellModel.onOutputsChanged(e => {
this.updatePreview();
}));
@@ -101,7 +101,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
if (propName === 'activeCellId') {
let changedProp = changes[propName];
this._activeCellId = changedProp.currentValue;
this.toggleEditMode(false);
// If the activeCellId is undefined (i.e. in an active cell update), don't unnecessarily set editMode to false;
// it will be set to true in a subsequent call to toggleEditMode()
if (changedProp.previousValue !== undefined) {
this.toggleEditMode(false);
}
break;
}
}
@@ -163,4 +167,15 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
this.updatePreview();
this._changeRef.detectChanges();
}
private setFocusAndScroll(): void {
if (this.cellModel.id === this._activeCellId) {
this.toggleEditMode(true);
} else {
this.toggleEditMode(false);
}
if (this.output && this.output.nativeElement) {
(<HTMLElement>this.output.nativeElement).scrollTo();
}
}
}