Minor improvements in notebook edit mode handling (#21839)

* rename + remove duplicate calls

* only fire onCellEditModeChanged when changed
This commit is contained in:
Lucy Zhang
2023-02-06 10:42:19 -08:00
committed by GitHub
parent 2767ff819d
commit b3048213e8
8 changed files with 27 additions and 31 deletions

View File

@@ -298,8 +298,8 @@ export class CodeComponent extends CellView implements OnInit, OnChanges {
}
this._layoutEmitter.fire();
}));
this._register(this.cellModel.onCellModeChanged((isEditMode) => {
this.onCellModeChanged(isEditMode);
this._register(this.cellModel.onCellEditModeChanged((isEditMode) => {
this.onCellEditModeChanged(isEditMode);
}));
this.layout();
@@ -453,7 +453,7 @@ export class CodeComponent extends CellView implements OnInit, OnChanges {
this._editor.setHeightToScrollHeight(false, isCollapsed);
}
private onCellModeChanged(isEditMode: boolean): void {
private onCellEditModeChanged(isEditMode: boolean): void {
if (this.cellModel.id === this._activeCellId || this._activeCellId === '') {
if (isEditMode) {
this._editor.getControl().focus();

View File

@@ -53,7 +53,7 @@ export class CodeCellComponent extends CellView implements OnInit, OnChanges {
this._register(this.cellModel.onOutputsChanged(() => {
this._changeRef.detectChanges();
}));
this._register(this.cellModel.onCellModeChanged(mode => {
this._register(this.cellModel.onCellEditModeChanged(mode => {
if (mode !== this.cellModel.isEditMode) {
this._changeRef.detectChanges();
}

View File

@@ -209,11 +209,10 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
this._register(this.cellModel.onOutputsChanged(e => {
this.updatePreview();
}));
this._register(this.cellModel.onCellModeChanged(mode => {
this._register(this.cellModel.onCellEditModeChanged(mode => {
if (mode !== this.isEditMode) {
this.toggleEditMode(mode);
}
this._changeRef.detectChanges();
}));
this._register(this.cellModel.onCurrentEditModeChanged(editMode => {
let markdown: boolean = editMode !== CellEditModes.WYSIWYG;
@@ -268,11 +267,6 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
let changedProp = changes[propName];
this._activeCellId = changedProp.currentValue;
this.toggleUserSelect(this.isActive());
// 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;
}
}

View File

@@ -374,8 +374,8 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle
filters: false
};
this._notebookModel.cells?.forEach(cell => {
this._register(cell.onCellModeChanged((state) => {
if (state) {
this._register(cell.onCellEditModeChanged((isEditMode) => {
if (isEditMode) {
this._onFindStateChange(changeEvent).catch(onUnexpectedError);
}
}));

View File

@@ -463,7 +463,7 @@ suite('Test class NotebookEditor:', () => {
const notebookModel = <NotebookModelStub>await notebookEditor.getNotebookModel();
notebookModel['_cells'] = [new CellModel({ cell_type: 'code', source: '' }, { isTrusted: true, notebook: notebookModel })];
notebookEditor['registerModelChanges']();
notebookModel.cells[0]['_onCellModeChanged'].fire(true); //fire cellModeChanged event on the first sell of our test notebookModel
notebookModel.cells[0]['_onCellEditModeChanged'].fire(true); //fire cellEditModeChanged event on the first sell of our test notebookModel
notebookModel.contentChangedEmitter.fire({ changeType: NotebookChangeType.Saved });
(<NotebookService>notebookService)['_onNotebookEditorAdd'].fire(<INotebookEditor>{});
notebookFindModelMock.verify(x => x.find(

View File

@@ -998,7 +998,7 @@ suite('Cell Model', function (): void {
let createCellModePromise = () => {
return new Promise((resolve, reject) => {
setTimeout((error) => reject(error), 2000);
model.onCellModeChanged(isEditMode => {
model.onCellEditModeChanged(isEditMode => {
resolve(isEditMode);
});
});