Skip to content

Fix order of cells inserted #10229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions src/datascience-ui/native-editor/redux/reducers/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ export namespace Creation {
return cellVM;
}

function findFirstCodeCellAbove(cellVMs: ICellViewModel[], start: number): string | undefined {
for (let index = start; index >= 0; index -= 1) {
if (cellVMs[index].cell.data.cell_type === 'code') {
return cellVMs[index].cell.id;
}
}
}

export function addAndFocusCell(arg: NativeEditorReducerArg<IAddCellAction>): IMainState {
queueIncomingActionWithPayload(arg, CommonActionType.ADD_NEW_CELL, { newCellId: arg.payload.data.newCellId });
queueIncomingActionWithPayload(arg, CommonActionType.FOCUS_CELL, {
Expand Down Expand Up @@ -116,7 +108,7 @@ export namespace Creation {
};

// Send a messsage that we inserted a cell
Transfer.postModelInsert(arg, position, newVM.cell, findFirstCodeCellAbove(newList, position));
Transfer.postModelInsert(arg, position, newVM.cell, arg.payload.data.cellId);

return result;
}
Expand All @@ -128,10 +120,11 @@ export namespace Creation {
// Find the position where we want to insert
let position = arg.prevState.cellVMs.findIndex(c => c.cell.id === arg.payload.data.cellId);
if (position >= 0) {
newList.splice(position + 1, 0, newVM);
position += 1;
newList.splice(position, 0, newVM);
} else {
newList.push(newVM);
position = newList.length - 2;
position = newList.length;
}

const result = {
Expand All @@ -141,12 +134,7 @@ export namespace Creation {
};

// Send a messsage that we inserted a cell
Transfer.postModelInsert(
arg,
arg.prevState.cellVMs.length,
newVM.cell,
findFirstCodeCellAbove(newList, position)
);
Transfer.postModelInsert(arg, position, newVM.cell, arg.payload.data.cellId);

return result;
}
Expand Down