mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Editor focus based on activeCell, create text in edit, scroll to active (#3725)
This commit is contained in:
@@ -128,6 +128,7 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange
|
|||||||
let uri = this.createUri();
|
let uri = this.createUri();
|
||||||
this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, this.cellModel.language, '', '');
|
this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, this.cellModel.language, '', '');
|
||||||
this._editor.setInput(this._editorInput, undefined);
|
this._editor.setInput(this._editorInput, undefined);
|
||||||
|
this.setFocusAndScroll();
|
||||||
this._editorInput.resolve().then(model => {
|
this._editorInput.resolve().then(model => {
|
||||||
this._editorModel = model.textEditorModel;
|
this._editorModel = model.textEditorModel;
|
||||||
this._modelService.updateModel(this._editorModel, this.cellModel.source);
|
this._modelService.updateModel(this._editorModel, this.cellModel.source);
|
||||||
@@ -193,4 +194,10 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange
|
|||||||
moreActionsEl.style.borderRightColor = theme.getColor(themeColors.SIDE_BAR_BACKGROUND, true).toString();
|
moreActionsEl.style.borderRightColor = theme.getColor(themeColors.SIDE_BAR_BACKGROUND, true).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setFocusAndScroll(): void {
|
||||||
|
if (this.cellModel.id === this._activeCellId) {
|
||||||
|
this._editor.focus();
|
||||||
|
this._editor.getContainer().scrollIntoView();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
@Inject(IOpenerService) private readonly openerService: IOpenerService,
|
@Inject(IOpenerService) private readonly openerService: IOpenerService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.isEditMode = false;
|
this.isEditMode = true;
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this._cellToggleMoreActions = this._instantiationService.createInstance(CellToggleMoreActions);
|
this._cellToggleMoreActions = this._instantiationService.createInstance(CellToggleMoreActions);
|
||||||
}
|
}
|
||||||
@@ -87,10 +87,10 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.updatePreview();
|
|
||||||
this.setLoading(false);
|
this.setLoading(false);
|
||||||
this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this));
|
this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this));
|
||||||
this.updateTheme(this.themeService.getColorTheme());
|
this.updateTheme(this.themeService.getColorTheme());
|
||||||
|
this.setFocusAndScroll();
|
||||||
this._register(this.cellModel.onOutputsChanged(e => {
|
this._register(this.cellModel.onOutputsChanged(e => {
|
||||||
this.updatePreview();
|
this.updatePreview();
|
||||||
}));
|
}));
|
||||||
@@ -101,7 +101,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
if (propName === 'activeCellId') {
|
if (propName === 'activeCellId') {
|
||||||
let changedProp = changes[propName];
|
let changedProp = changes[propName];
|
||||||
this._activeCellId = changedProp.currentValue;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,4 +167,15 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
this.updatePreview();
|
this.updatePreview();
|
||||||
this._changeRef.detectChanges();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
private _defaultKernel: nb.IKernelSpec;
|
private _defaultKernel: nb.IKernelSpec;
|
||||||
private _activeCell: ICellModel;
|
private _activeCell: ICellModel;
|
||||||
private _providerId: string;
|
private _providerId: string;
|
||||||
|
private _isNewNotebook: boolean = true;
|
||||||
|
|
||||||
constructor(private notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, private connectionProfile?: IConnectionProfile) {
|
constructor(private notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, private connectionProfile?: IConnectionProfile) {
|
||||||
super();
|
super();
|
||||||
@@ -170,6 +171,10 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
return this._trustedMode;
|
return this._trustedMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get isNewNotebook(): boolean {
|
||||||
|
return this._isNewNotebook;
|
||||||
|
}
|
||||||
|
|
||||||
public get providerId(): string {
|
public get providerId(): string {
|
||||||
return this._providerId;
|
return this._providerId;
|
||||||
}
|
}
|
||||||
@@ -218,6 +223,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
version: ''
|
version: ''
|
||||||
};
|
};
|
||||||
if (contents) {
|
if (contents) {
|
||||||
|
this._isNewNotebook = false;
|
||||||
this._defaultLanguageInfo = this.getDefaultLanguageInfo(contents);
|
this._defaultLanguageInfo = this.getDefaultLanguageInfo(contents);
|
||||||
this._savedKernelInfo = this.getSavedKernelInfo(contents);
|
this._savedKernelInfo = this.getSavedKernelInfo(contents);
|
||||||
if (contents.cells && contents.cells.length > 0) {
|
if (contents.cells && contents.cells.length > 0) {
|
||||||
@@ -250,7 +256,9 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
index = undefined;
|
index = undefined;
|
||||||
}
|
}
|
||||||
// Set newly created cell as active cell
|
// Set newly created cell as active cell
|
||||||
this._activeCell.active = false;
|
if (this._activeCell) {
|
||||||
|
this._activeCell.active = false;
|
||||||
|
}
|
||||||
this._activeCell = cell;
|
this._activeCell = cell;
|
||||||
this._activeCell.active = true;
|
this._activeCell.active = true;
|
||||||
|
|
||||||
|
|||||||
@@ -250,8 +250,9 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
this.updateToolbarComponents(this._model.trustedMode);
|
this.updateToolbarComponents(this._model.trustedMode);
|
||||||
this._modelRegisteredDeferred.resolve(this._model);
|
this._modelRegisteredDeferred.resolve(this._model);
|
||||||
model.backgroundStartSession();
|
model.backgroundStartSession();
|
||||||
// Set first cell as default active cell
|
// Set first cell as default active cell if user creates new notebook
|
||||||
if (this._model && this._model.cells && this._model.cells[0]) {
|
// Otherwise, don't select any cells by default
|
||||||
|
if (this._model && this._model.cells && this._model.cells[0] && this._model.isNewNotebook) {
|
||||||
this.selectCell(model.cells[0]);
|
this.selectCell(model.cells[0]);
|
||||||
}
|
}
|
||||||
this._changeRef.detectChanges();
|
this._changeRef.detectChanges();
|
||||||
|
|||||||
Reference in New Issue
Block a user