Skip to content

Commit c4b8fde

Browse files
committed
Fix order of cells inserted
1 parent ca10f93 commit c4b8fde

File tree

1 file changed

+5
-17
lines changed
  • src/datascience-ui/native-editor/redux/reducers

1 file changed

+5
-17
lines changed

src/datascience-ui/native-editor/redux/reducers/creation.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ export namespace Creation {
4444
return cellVM;
4545
}
4646

47-
function findFirstCodeCellAbove(cellVMs: ICellViewModel[], start: number): string | undefined {
48-
for (let index = start; index >= 0; index -= 1) {
49-
if (cellVMs[index].cell.data.cell_type === 'code') {
50-
return cellVMs[index].cell.id;
51-
}
52-
}
53-
}
54-
5547
export function addAndFocusCell(arg: NativeEditorReducerArg<IAddCellAction>): IMainState {
5648
queueIncomingActionWithPayload(arg, CommonActionType.ADD_NEW_CELL, { newCellId: arg.payload.data.newCellId });
5749
queueIncomingActionWithPayload(arg, CommonActionType.FOCUS_CELL, {
@@ -116,7 +108,7 @@ export namespace Creation {
116108
};
117109

118110
// Send a messsage that we inserted a cell
119-
Transfer.postModelInsert(arg, position, newVM.cell, findFirstCodeCellAbove(newList, position));
111+
Transfer.postModelInsert(arg, position, newVM.cell, arg.payload.data.cellId);
120112

121113
return result;
122114
}
@@ -128,10 +120,11 @@ export namespace Creation {
128120
// Find the position where we want to insert
129121
let position = arg.prevState.cellVMs.findIndex(c => c.cell.id === arg.payload.data.cellId);
130122
if (position >= 0) {
131-
newList.splice(position + 1, 0, newVM);
123+
position += 1;
124+
newList.splice(position, 0, newVM);
132125
} else {
133126
newList.push(newVM);
134-
position = newList.length - 2;
127+
position = newList.length;
135128
}
136129

137130
const result = {
@@ -141,12 +134,7 @@ export namespace Creation {
141134
};
142135

143136
// Send a messsage that we inserted a cell
144-
Transfer.postModelInsert(
145-
arg,
146-
arg.prevState.cellVMs.length,
147-
newVM.cell,
148-
findFirstCodeCellAbove(newList, position)
149-
);
137+
Transfer.postModelInsert(arg, position, newVM.cell, arg.payload.data.cellId);
150138

151139
return result;
152140
}

0 commit comments

Comments
 (0)