@@ -44,14 +44,6 @@ export namespace Creation {
44
44
return cellVM ;
45
45
}
46
46
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
-
55
47
export function addAndFocusCell ( arg : NativeEditorReducerArg < IAddCellAction > ) : IMainState {
56
48
queueIncomingActionWithPayload ( arg , CommonActionType . ADD_NEW_CELL , { newCellId : arg . payload . data . newCellId } ) ;
57
49
queueIncomingActionWithPayload ( arg , CommonActionType . FOCUS_CELL , {
@@ -116,7 +108,7 @@ export namespace Creation {
116
108
} ;
117
109
118
110
// 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 ) ;
120
112
121
113
return result ;
122
114
}
@@ -128,10 +120,11 @@ export namespace Creation {
128
120
// Find the position where we want to insert
129
121
let position = arg . prevState . cellVMs . findIndex ( c => c . cell . id === arg . payload . data . cellId ) ;
130
122
if ( position >= 0 ) {
131
- newList . splice ( position + 1 , 0 , newVM ) ;
123
+ position += 1 ;
124
+ newList . splice ( position , 0 , newVM ) ;
132
125
} else {
133
126
newList . push ( newVM ) ;
134
- position = newList . length - 2 ;
127
+ position = newList . length ;
135
128
}
136
129
137
130
const result = {
@@ -141,12 +134,7 @@ export namespace Creation {
141
134
} ;
142
135
143
136
// 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 ) ;
150
138
151
139
return result ;
152
140
}
0 commit comments