@@ -32,14 +32,6 @@ export namespace Creation {
32
32
return cellVM ;
33
33
}
34
34
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
-
43
35
export function addAndFocusCell ( arg : NativeEditorReducerArg < IAddCellAction > ) : IMainState {
44
36
queueIncomingActionWithPayload ( arg , CommonActionType . ADD_NEW_CELL , { newCellId : arg . payload . data . newCellId } ) ;
45
37
queueIncomingActionWithPayload ( arg , CommonActionType . FOCUS_CELL , { cellId : arg . payload . data . newCellId , cursorPos : CursorPos . Current } ) ;
@@ -84,7 +76,7 @@ export namespace Creation {
84
76
} ;
85
77
86
78
// 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 ) ;
88
80
89
81
return result ;
90
82
}
@@ -96,10 +88,11 @@ export namespace Creation {
96
88
// Find the position where we want to insert
97
89
let position = arg . prevState . cellVMs . findIndex ( c => c . cell . id === arg . payload . data . cellId ) ;
98
90
if ( position >= 0 ) {
99
- newList . splice ( position + 1 , 0 , newVM ) ;
91
+ position += 1 ;
92
+ newList . splice ( position , 0 , newVM ) ;
100
93
} else {
101
94
newList . push ( newVM ) ;
102
- position = newList . length - 2 ;
95
+ position = newList . length ;
103
96
}
104
97
105
98
const result = {
@@ -109,7 +102,7 @@ export namespace Creation {
109
102
} ;
110
103
111
104
// 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 ) ;
113
106
114
107
return result ;
115
108
}
0 commit comments