@@ -54,6 +54,7 @@ export function useSelectionStateApi() {
5454 */
5555 function dispatcher ( evt ) {
5656 const next = reducer ( state . value , evt ) ;
57+ next . lastAction = evt . kind ;
5758 state . value = next ;
5859 }
5960 const dispatch = useCallback ( dispatcher , [ state , selected ] ) ;
@@ -70,7 +71,6 @@ export function reducer(prev, evt) {
7071 case 'reset' : {
7172 return {
7273 ...defaultState ,
73- lastAction : evt . kind ,
7474 } ;
7575 }
7676 case 'move-selection' : {
@@ -82,21 +82,21 @@ export function reducer(prev, evt) {
8282 const newIndex = Math . max ( 0 , max ) ;
8383 const newSelected = new Set ( [ newIndex ] ) ;
8484 return {
85+ ...prev ,
8586 anchorIndex : newIndex ,
8687 focusedIndex : newIndex ,
8788 lastShiftRange : { start : null , end : null } ,
8889 selected : newSelected ,
89- lastAction : evt . kind ,
9090 } ;
9191 }
9292 case 'select-index' : {
9393 const newSelected = new Set ( [ evt . index ] ) ;
9494 return {
95+ ...prev ,
9596 anchorIndex : evt . index ,
9697 focusedIndex : evt . index ,
9798 lastShiftRange : { start : null , end : null } ,
9899 selected : newSelected ,
99- lastAction : evt . kind ,
100100 } ;
101101 }
102102 case 'toggle-index' : {
@@ -107,11 +107,11 @@ export function reducer(prev, evt) {
107107 newSelected . add ( evt . index ) ;
108108 }
109109 return {
110+ ...prev ,
110111 anchorIndex : evt . index ,
111112 lastShiftRange : { start : null , end : null } ,
112113 focusedIndex : evt . index ,
113114 selected : newSelected ,
114- lastAction : evt . kind ,
115115 } ;
116116 }
117117 case 'expand-selected-to-index' : {
@@ -139,7 +139,6 @@ export function reducer(prev, evt) {
139139 lastShiftRange : { start, end } ,
140140 focusedIndex : evt . index ,
141141 selected : newSelected ,
142- lastAction : evt . kind ,
143142 } ;
144143 }
145144 case 'inc-or-dec-selected' : {
@@ -163,11 +162,11 @@ export function reducer(prev, evt) {
163162 newSelected . add ( i ) ;
164163 }
165164 return {
165+ ...prev ,
166166 focusedIndex : evt . nextIndex ,
167167 lastShiftRange : { start, end } ,
168168 anchorIndex : anchorIndex === null ? evt . nextIndex : anchorIndex ,
169169 selected : newSelected ,
170- lastAction : evt . kind ,
171170 } ;
172171 }
173172 case 'increment-selection' : {
@@ -195,11 +194,11 @@ export function reducer(prev, evt) {
195194 newSelected . add ( i ) ;
196195 }
197196 return {
197+ ...prev ,
198198 focusedIndex : newIndex ,
199199 lastShiftRange : { start, end } ,
200200 anchorIndex : anchorIndex === null ? newIndex : anchorIndex ,
201201 selected : newSelected ,
202- lastAction : evt . kind ,
203202 } ;
204203 }
205204 default :
0 commit comments