Fix on click edit mode states (#18321)

* fix click code cell

* modified editmode when updating active cell
This commit is contained in:
Barbara Valdez
2022-02-16 15:52:05 -08:00
committed by GitHub
parent 678f2e3878
commit 87d5da00bf
7 changed files with 47 additions and 40 deletions

View File

@@ -547,7 +547,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
return undefined;
}
let cell = this.createCell(cellType);
return this.insertCell(cell, index);
return this.insertCell(cell, index, true);
}
public splitCell(cellType: CellType, notebookService: INotebookService, index?: number, addToUndoStack: boolean = true): ICellModel | undefined {
@@ -662,9 +662,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
this.undoService.pushElement(new SplitCellEdit(this, splitCells));
}
//make new cell Active
this.updateActiveCell(activeCell);
activeCell.isEditMode = true;
this.updateActiveCell(activeCell, true);
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.CellsModified,
cells: [activeCell],
@@ -686,9 +684,8 @@ export class NotebookModel extends Disposable implements INotebookModel {
for (let i = 1; i < cells.length; i++) {
firstCell.source = cells[i].prefix ? [...firstCell.source, ...cells[i].prefix, ...cells[i].cell.source] : [...firstCell.source, ...cells[i].cell.source];
}
firstCell.isEditMode = true;
// Set newly created cell as active cell
this.updateActiveCell(firstCell);
this.updateActiveCell(firstCell, true);
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.CellsModified,
cells: [firstCell],
@@ -701,8 +698,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
public splitCells(cells: SplitCell[], firstCellOriginalSource: string | string[]): void {
cells[0].cell.source = firstCellOriginalSource;
cells[0].cell.isEditMode = true;
this.updateActiveCell(cells[0].cell);
this.updateActiveCell(cells[0].cell, true);
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.CellsModified,
cells: [cells[0].cell],
@@ -724,11 +720,10 @@ export class NotebookModel extends Disposable implements INotebookModel {
this._cells.push(cell);
index = undefined;
}
cell.isEditMode = true;
if (addToUndoStack) {
// Only make cell active when inserting the cell. If we update the active cell when undoing/redoing, the user would have to deselect the cell first
// and to undo multiple times.
this.updateActiveCell(cell);
this.updateActiveCell(cell, true);
this.undoService.pushElement(new AddCellEdit(this, cell, index));
}
@@ -804,13 +799,15 @@ export class NotebookModel extends Disposable implements INotebookModel {
});
}
public updateActiveCell(cell?: ICellModel): void {
public updateActiveCell(cell?: ICellModel, isEditMode: boolean = false): void {
if (this._activeCell) {
this._activeCell.active = false;
this._activeCell.isEditMode = false;
}
this._activeCell = cell;
if (this._activeCell) {
this._activeCell.active = true;
this._activeCell.isEditMode = isEditMode;
}
this._onActiveCellChanged.fire(cell);
}