@@ -212,23 +212,20 @@ const advanceTodoState = (state, action) => {
212
212
secondTimestamp : null ,
213
213
} ,
214
214
] ;
215
- state = state . updateIn (
216
- [ 'headers' , headerIndex , 'propertyListItems' ] ,
217
- propertyListItems =>
218
- propertyListItems . some ( item => item . get ( 'property' ) === 'LAST_REPEAT' )
219
- ? propertyListItems . map (
220
- item =>
221
- item . get ( 'property' ) === 'LAST_REPEAT'
222
- ? item . set ( 'value' , fromJS ( newLastRepeatValue ) )
223
- : item
224
- )
225
- : propertyListItems . push (
226
- fromJS ( {
227
- property : 'LAST_REPEAT' ,
228
- value : newLastRepeatValue ,
229
- id : generateId ( ) ,
230
- } )
231
- )
215
+ state = state . updateIn ( [ 'headers' , headerIndex , 'propertyListItems' ] , propertyListItems =>
216
+ propertyListItems . some ( item => item . get ( 'property' ) === 'LAST_REPEAT' )
217
+ ? propertyListItems . map ( item =>
218
+ item . get ( 'property' ) === 'LAST_REPEAT'
219
+ ? item . set ( 'value' , fromJS ( newLastRepeatValue ) )
220
+ : item
221
+ )
222
+ : propertyListItems . push (
223
+ fromJS ( {
224
+ property : 'LAST_REPEAT' ,
225
+ value : newLastRepeatValue ,
226
+ id : generateId ( ) ,
227
+ } )
228
+ )
232
229
) ;
233
230
234
231
state = state . updateIn ( [ 'headers' , headerIndex ] , header => {
@@ -671,14 +668,12 @@ const moveTableColumnLeft = (state, action) => {
671
668
columnIndex === 0
672
669
? rows
673
670
: rows . map ( row =>
674
- row . update (
675
- 'contents' ,
676
- contents =>
677
- contents . size === 0
678
- ? contents
679
- : contents
680
- . insert ( columnIndex - 1 , contents . get ( columnIndex ) )
681
- . delete ( columnIndex + 1 )
671
+ row . update ( 'contents' , contents =>
672
+ contents . size === 0
673
+ ? contents
674
+ : contents
675
+ . insert ( columnIndex - 1 , contents . get ( columnIndex ) )
676
+ . delete ( columnIndex + 1 )
682
677
)
683
678
)
684
679
)
@@ -698,14 +693,12 @@ const moveTableColumnRight = (state, action) => {
698
693
columnIndex + 1 >= rows . getIn ( [ 0 , 'contents' ] ) . size
699
694
? rows
700
695
: rows . map ( row =>
701
- row . update (
702
- 'contents' ,
703
- contents =>
704
- contents . size === 0
705
- ? contents
706
- : contents
707
- . insert ( columnIndex , contents . get ( columnIndex + 1 ) )
708
- . delete ( columnIndex + 2 )
696
+ row . update ( 'contents' , contents =>
697
+ contents . size === 0
698
+ ? contents
699
+ : contents
700
+ . insert ( columnIndex , contents . get ( columnIndex + 1 ) )
701
+ . delete ( columnIndex + 2 )
709
702
)
710
703
)
711
704
)
@@ -732,25 +725,33 @@ const insertCapture = (state, action) => {
732
725
const headers = state . get ( 'headers' ) ;
733
726
const { template, content, shouldPrepend } = action ;
734
727
735
- const parentHeader = headerWithPath ( headers , template . get ( 'headerPaths' ) ) ;
736
- if ( ! parentHeader ) {
728
+ const isTopLevelTarget = template . get ( 'headerPaths' ) . filter ( path => path . length !== 0 ) . size === 0 ;
729
+
730
+ const parentHeader = isTopLevelTarget
731
+ ? null
732
+ : headerWithPath ( headers , template . get ( 'headerPaths' ) ) ;
733
+ if ( ! parentHeader && ! isTopLevelTarget ) {
737
734
return state ;
738
735
}
739
736
740
737
const newHeader = newHeaderFromText ( content , state . get ( 'todoKeywordSets' ) ) . set (
741
738
'nestingLevel' ,
742
- parentHeader . get ( 'nestingLevel' ) + 1
739
+ isTopLevelTarget ? 1 : parentHeader . get ( 'nestingLevel' ) + 1
743
740
) ;
744
741
745
- const parentHeaderIndex = indexOfHeaderWithId ( headers , parentHeader . get ( 'id' ) ) ;
746
- const numSubheaders = numSubheadersOfHeaderWithId ( headers , parentHeader . get ( 'id' ) ) ;
747
- const newIndex = parentHeaderIndex + 1 + ( shouldPrepend ? 0 : numSubheaders ) ;
742
+ if ( isTopLevelTarget ) {
743
+ return state . update ( 'headers' , headers => headers . push ( newHeader ) ) ;
744
+ } else {
745
+ const parentHeaderIndex = indexOfHeaderWithId ( headers , parentHeader . get ( 'id' ) ) ;
746
+ const numSubheaders = numSubheadersOfHeaderWithId ( headers , parentHeader . get ( 'id' ) ) ;
747
+ const newIndex = parentHeaderIndex + 1 + ( shouldPrepend ? 0 : numSubheaders ) ;
748
748
749
- state = state . update ( 'headers' , headers => headers . insert ( newIndex , newHeader ) ) ;
749
+ state = state . update ( 'headers' , headers => headers . insert ( newIndex , newHeader ) ) ;
750
750
751
- state = updateCookiesOfHeaderWithId ( state , parentHeader . get ( 'id' ) ) ;
751
+ state = updateCookiesOfHeaderWithId ( state , parentHeader . get ( 'id' ) ) ;
752
752
753
- return state ;
753
+ return state ;
754
+ }
754
755
} ;
755
756
756
757
const clearPendingCapture = state => state . set ( 'pendingCapture' , null ) ;
@@ -918,10 +919,8 @@ const addNewPlanningItem = (state, action) => {
918
919
timestamp : getCurrentTimestamp ( ) ,
919
920
} ) ;
920
921
921
- return state . updateIn (
922
- [ 'headers' , headerIndex , 'planningItems' ] ,
923
- planningItems =>
924
- ! ! planningItems ? planningItems . push ( newPlanningItem ) : List ( [ newPlanningItem ] )
922
+ return state . updateIn ( [ 'headers' , headerIndex , 'planningItems' ] , planningItems =>
923
+ ! ! planningItems ? planningItems . push ( newPlanningItem ) : List ( [ newPlanningItem ] )
925
924
) ;
926
925
} ;
927
926
0 commit comments