@@ -775,16 +775,31 @@ const isEdgeSelectionAction = (action: UnknownAction): action is EdgeSelectionAc
775
775
return false ;
776
776
} ;
777
777
778
- type NodePositionOrDimensionAction = {
778
+ type NodeDimensionChangeAction = {
779
+ type : ReturnType < typeof nodesChanged > [ 'type' ] ;
780
+ payload : NodeDimensionChange [ ] ;
781
+ } ;
782
+
783
+ const isDimensionsChangeAction = ( action : UnknownAction ) : action is NodeDimensionChangeAction => {
784
+ if ( ! nodesChanged . match ( action ) ) {
785
+ return false ;
786
+ }
787
+ if ( action . payload . every ( ( change ) => change . type === 'dimensions' ) ) {
788
+ return true ;
789
+ }
790
+ return false ;
791
+ } ;
792
+
793
+ type NodePositionChangeAction = {
779
794
type : ReturnType < typeof nodesChanged > [ 'type' ] ;
780
795
payload : ( NodeDimensionChange | NodePositionChange ) [ ] ;
781
796
} ;
782
797
783
- const isDimensionsOrPositionAction = ( action : UnknownAction ) : action is NodePositionOrDimensionAction => {
798
+ const isPositionChangeAction = ( action : UnknownAction ) : action is NodePositionChangeAction => {
784
799
if ( ! nodesChanged . match ( action ) ) {
785
800
return false ;
786
801
}
787
- if ( action . payload . every ( ( change ) => change . type === 'dimensions' || change . type === ' position') ) {
802
+ if ( action . payload . every ( ( change ) => change . type === 'position' ) ) {
788
803
return true ;
789
804
}
790
805
return false ;
@@ -837,18 +852,14 @@ export const nodesUndoableConfig: UndoableOptions<NodesState, UnknownAction> = {
837
852
limit : 64 ,
838
853
undoType : nodesSlice . actions . undo . type ,
839
854
redoType : nodesSlice . actions . redo . type ,
840
- groupBy : ( action , state , history ) => {
841
- if ( isNodeSelectionAction ( action ) || isEdgeSelectionAction ( action ) ) {
842
- // Changes to selection should never be recorded on their own
843
- return history . group ;
844
- }
855
+ groupBy : ( action , _state , _history ) => {
845
856
if ( isHighFrequencyFieldChangeAction ( action ) ) {
846
857
// Group by type, node id and field name
847
858
const { type, payload } = action ;
848
859
const { nodeId, fieldName } = payload ;
849
860
return `${ type } -${ nodeId } -${ fieldName } ` ;
850
861
}
851
- if ( isDimensionsOrPositionAction ( action ) ) {
862
+ if ( isPositionChangeAction ( action ) ) {
852
863
const ids = action . payload . map ( ( change ) => change . id ) . join ( ',' ) ;
853
864
// Group by type and node ids
854
865
return `dimensions-or-position-${ ids } ` ;
@@ -875,6 +886,14 @@ export const nodesUndoableConfig: UndoableOptions<NodesState, UnknownAction> = {
875
886
if ( ! action . type . startsWith ( nodesSlice . name ) ) {
876
887
return false ;
877
888
}
889
+ // Ignore actions that only select or deselect nodes and edges
890
+ if ( isNodeSelectionAction ( action ) || isEdgeSelectionAction ( action ) ) {
891
+ return false ;
892
+ }
893
+ if ( isDimensionsChangeAction ( action ) ) {
894
+ // Ignore actions that only change the dimensions of nodes - these are internal to reactflow
895
+ return false ;
896
+ }
878
897
return true ;
879
898
} ,
880
899
} ;
0 commit comments