Skip to content

Commit

Permalink
Fix deleting last cell (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc authored Dec 19, 2024
1 parent 05d0b6d commit c93e430
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ export class LocalSuggestionsManager
const data: IDict<ISuggestionData> = {};
Object.entries(serializedCellSuggestions).forEach(
([id, serializedData]) => {
data[id] = this._deserializedSuggestion(
const newCellModel = this._deserializedSuggestion(
serializedData,
cellMap
);
if (newCellModel) {
data[id] = newCellModel;
}
}
);
currentSuggestion.set(cellID, data);
Expand Down Expand Up @@ -112,7 +115,7 @@ export class LocalSuggestionsManager

const suggestionContent: ISuggestionData = {
originalCellId: cellId,
cellModel: cloneCellModel(cell.model),
cellModel: cloneCellModel(cell.model)!,
metadata: { author },
type: options.type
};
Expand Down Expand Up @@ -320,10 +323,13 @@ export class LocalSuggestionsManager
private _deserializedSuggestion(
serializedData: ISerializedSuggessionData,
cellMap: IDict<ICellModel>
): ISuggestionData {
): ISuggestionData | undefined {
const { originalCellId, newSource, metadata, type } = serializedData;
const originalCellModel = cellMap[serializedData.originalCellId];
const newCellModel = cloneCellModel(originalCellModel, newSource);
if (!newCellModel) {
return;
}
return {
originalCellId,
cellModel: newCellModel,
Expand Down
9 changes: 6 additions & 3 deletions packages/base/src/suggestionsPanel/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class SuggestionsModel implements ISuggestionsModel {
if (type === SuggestionType.delete || cellModel === null) {
// if `cellModel` is null, it's a cell deletion suggestion,
// we just use the origianl model to render the suggestion widget
newCellModel = cloneCellModel(it);
newCellModel = cloneCellModel(it)!;
} else {
newCellModel = cellModel;
}
Expand Down Expand Up @@ -351,8 +351,11 @@ export class SuggestionsModel implements ISuggestionsModel {
el => !cellInNotebook.has(el)
);
for (const removed of removedElements) {
const suggestions = this._allSuggestions?.get(removed) ?? {};
for (const suggestionId in suggestions) {
const suggestions = Object.keys(
this._allSuggestions?.get(removed) ?? {}
);

for (const suggestionId of suggestions) {
await this.deleteSuggestion({ cellId: removed, suggestionId });
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/base/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ export async function deleteCellById(options: {
}

export function cloneCellModel(
cellModel: ICellModel,
cellModel?: ICellModel,
newSource?: string
): ICellModel {
): ICellModel | undefined {
if (!cellModel) {
return;
}
let copiedCellModel: CellModel | undefined;
const mimeType = cellModel.mimeType;
switch (cellModel.type) {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10332,7 +10332,7 @@ __metadata:

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

"typescript@patch:typescript@~5.0.2#~builtin<compat/typescript>":
version: 5.0.4
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=b5f058"
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=85af82"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: d26b6ba97b6d163c55dbdffd9bbb4c211667ebebc743accfeb2c8c0154aace7afd097b51165a72a5bad2cf65a4612259344ff60f8e642362aa1695c760d303ac
checksum: bb309d320c59a26565fb3793dba550576ab861018ff3fd1b7fccabbe46ae4a35546bc45f342c0a0b6f265c801ccdf64ffd68f548f117ceb7f0eac4b805cd52a9
languageName: node
linkType: hard

Expand Down

0 comments on commit c93e430

Please sign in to comment.