Skip to content

Commit 7bb56c0

Browse files
committed
Fix order of cells inserted
1 parent 4685573 commit 7bb56c0

File tree

1 file changed

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

1 file changed

+5
-12
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ export namespace Creation {
3232
return cellVM;
3333
}
3434

35-
function findFirstCodeCellAbove(cellVMs: ICellViewModel[], start: number): string | undefined {
36-
for (let index = start; index >= 0; index -= 1) {
37-
if (cellVMs[index].cell.data.cell_type === 'code') {
38-
return cellVMs[index].cell.id;
39-
}
40-
}
41-
}
42-
4335
export function addAndFocusCell(arg: NativeEditorReducerArg<IAddCellAction>): IMainState {
4436
queueIncomingActionWithPayload(arg, CommonActionType.ADD_NEW_CELL, { newCellId: arg.payload.data.newCellId });
4537
queueIncomingActionWithPayload(arg, CommonActionType.FOCUS_CELL, { cellId: arg.payload.data.newCellId, cursorPos: CursorPos.Current });
@@ -84,7 +76,7 @@ export namespace Creation {
8476
};
8577

8678
// Send a messsage that we inserted a cell
87-
Transfer.postModelInsert(arg, position, newVM.cell, findFirstCodeCellAbove(newList, position));
79+
Transfer.postModelInsert(arg, position, newVM.cell, arg.payload.data.cellId);
8880

8981
return result;
9082
}
@@ -96,10 +88,11 @@ export namespace Creation {
9688
// Find the position where we want to insert
9789
let position = arg.prevState.cellVMs.findIndex(c => c.cell.id === arg.payload.data.cellId);
9890
if (position >= 0) {
99-
newList.splice(position + 1, 0, newVM);
91+
position += 1;
92+
newList.splice(position, 0, newVM);
10093
} else {
10194
newList.push(newVM);
102-
position = newList.length - 2;
95+
position = newList.length;
10396
}
10497

10598
const result = {
@@ -109,7 +102,7 @@ export namespace Creation {
109102
};
110103

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

114107
return result;
115108
}

0 commit comments

Comments
 (0)