Skip to content

Commit c93e430

Browse files
authored
Fix deleting last cell (#27)
1 parent 05d0b6d commit c93e430

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

packages/base/src/localSuggestionsManager/localSuggestionsManager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ export class LocalSuggestionsManager
5858
const data: IDict<ISuggestionData> = {};
5959
Object.entries(serializedCellSuggestions).forEach(
6060
([id, serializedData]) => {
61-
data[id] = this._deserializedSuggestion(
61+
const newCellModel = this._deserializedSuggestion(
6262
serializedData,
6363
cellMap
6464
);
65+
if (newCellModel) {
66+
data[id] = newCellModel;
67+
}
6568
}
6669
);
6770
currentSuggestion.set(cellID, data);
@@ -112,7 +115,7 @@ export class LocalSuggestionsManager
112115

113116
const suggestionContent: ISuggestionData = {
114117
originalCellId: cellId,
115-
cellModel: cloneCellModel(cell.model),
118+
cellModel: cloneCellModel(cell.model)!,
116119
metadata: { author },
117120
type: options.type
118121
};
@@ -320,10 +323,13 @@ export class LocalSuggestionsManager
320323
private _deserializedSuggestion(
321324
serializedData: ISerializedSuggessionData,
322325
cellMap: IDict<ICellModel>
323-
): ISuggestionData {
326+
): ISuggestionData | undefined {
324327
const { originalCellId, newSource, metadata, type } = serializedData;
325328
const originalCellModel = cellMap[serializedData.originalCellId];
326329
const newCellModel = cloneCellModel(originalCellModel, newSource);
330+
if (!newCellModel) {
331+
return;
332+
}
327333
return {
328334
originalCellId,
329335
cellModel: newCellModel,

packages/base/src/suggestionsPanel/model.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class SuggestionsModel implements ISuggestionsModel {
271271
if (type === SuggestionType.delete || cellModel === null) {
272272
// if `cellModel` is null, it's a cell deletion suggestion,
273273
// we just use the origianl model to render the suggestion widget
274-
newCellModel = cloneCellModel(it);
274+
newCellModel = cloneCellModel(it)!;
275275
} else {
276276
newCellModel = cellModel;
277277
}
@@ -351,8 +351,11 @@ export class SuggestionsModel implements ISuggestionsModel {
351351
el => !cellInNotebook.has(el)
352352
);
353353
for (const removed of removedElements) {
354-
const suggestions = this._allSuggestions?.get(removed) ?? {};
355-
for (const suggestionId in suggestions) {
354+
const suggestions = Object.keys(
355+
this._allSuggestions?.get(removed) ?? {}
356+
);
357+
358+
for (const suggestionId of suggestions) {
356359
await this.deleteSuggestion({ cellId: removed, suggestionId });
357360
}
358361
}

packages/base/src/tools.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,12 @@ export async function deleteCellById(options: {
207207
}
208208

209209
export function cloneCellModel(
210-
cellModel: ICellModel,
210+
cellModel?: ICellModel,
211211
newSource?: string
212-
): ICellModel {
212+
): ICellModel | undefined {
213+
if (!cellModel) {
214+
return;
215+
}
213216
let copiedCellModel: CellModel | undefined;
214217
const mimeType = cellModel.mimeType;
215218
switch (cellModel.type) {

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10332,7 +10332,7 @@ __metadata:
1033210332

1033310333
"typescript@patch:typescript@>=3 < 6#~builtin<compat/typescript>, typescript@patch:typescript@^5#~builtin<compat/typescript>":
1033410334
version: 5.7.2
10335-
resolution: "typescript@patch:typescript@npm%3A5.7.2#~builtin<compat/typescript>::version=5.7.2&hash=e012d7"
10335+
resolution: "typescript@patch:typescript@npm%3A5.7.2#~builtin<compat/typescript>::version=5.7.2&hash=85af82"
1033610336
bin:
1033710337
tsc: bin/tsc
1033810338
tsserver: bin/tsserver
@@ -10342,11 +10342,11 @@ __metadata:
1034210342

1034310343
"typescript@patch:typescript@~5.0.2#~builtin<compat/typescript>":
1034410344
version: 5.0.4
10345-
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=b5f058"
10345+
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=85af82"
1034610346
bin:
1034710347
tsc: bin/tsc
1034810348
tsserver: bin/tsserver
10349-
checksum: d26b6ba97b6d163c55dbdffd9bbb4c211667ebebc743accfeb2c8c0154aace7afd097b51165a72a5bad2cf65a4612259344ff60f8e642362aa1695c760d303ac
10349+
checksum: bb309d320c59a26565fb3793dba550576ab861018ff3fd1b7fccabbe46ae4a35546bc45f342c0a0b6f265c801ccdf64ffd68f548f117ceb7f0eac4b805cd52a9
1035010350
languageName: node
1035110351
linkType: hard
1035210352

0 commit comments

Comments
 (0)