@@ -1586,54 +1586,59 @@ export class SCMHistoryViewPane extends ViewPane {
1586
1586
// If there are any history item references we have to add a submenu item for each orignal action,
1587
1587
// and a menu item for each history item ref that matches the `when` clause of the original action.
1588
1588
if ( historyItemRefMenuItems . length > 0 && element . historyItemViewModel . historyItem . references ?. length ) {
1589
- const submenuIds = new Map < string , MenuId > ( ) ;
1589
+ const historyItemRefActions = new Map < string , ISCMHistoryItemRef [ ] > ( ) ;
1590
1590
1591
1591
for ( const ref of element . historyItemViewModel . historyItem . references ) {
1592
1592
const contextKeyService = this . scopedContextKeyService . createOverlay ( [
1593
1593
[ 'scmHistoryItemRef' , ref . id ]
1594
1594
] ) ;
1595
1595
1596
- for ( const [ , actions ] of this . _menuService . getMenuActions ( MenuId . SCMHistoryItemRefContext , contextKeyService ) ) {
1597
- for ( const action of actions ) {
1598
- let subMenuId = submenuIds . get ( action . id ) ;
1596
+ const menuActions = this . _menuService . getMenuActions (
1597
+ MenuId . SCMHistoryItemRefContext , contextKeyService ) ;
1599
1598
1600
- if ( ! subMenuId ) {
1601
- subMenuId = MenuId . for ( action . id ) ;
1599
+ for ( const action of menuActions . flatMap ( a => a [ 1 ] ) ) {
1600
+ if ( ! historyItemRefActions . has ( action . id ) ) {
1601
+ historyItemRefActions . set ( action . id , [ ] ) ;
1602
+ }
1602
1603
1603
- // Get the menu item for the original action so that
1604
- // we can create a submenu with the same group, order
1605
- const historyItemRefMenuItem = historyItemRefMenuItems
1606
- . find ( item => item . command . id === action . id ) ;
1604
+ historyItemRefActions . get ( action . id ) ! . push ( ref ) ;
1605
+ }
1606
+ }
1607
1607
1608
- // Register the submenu for the original action
1609
- this . _contextMenuDisposables . value . add ( MenuRegistry . appendMenuItem ( MenuId . SCMChangesContext , {
1610
- title : action . label ,
1611
- submenu : subMenuId ,
1612
- group : historyItemRefMenuItem ?. group ,
1613
- order : historyItemRefMenuItem ?. order
1614
- } ) ) ;
1608
+ // Register submenu, menu items
1609
+ for ( const historyItemRefMenuItem of historyItemRefMenuItems ) {
1610
+ const actionId = historyItemRefMenuItem . command . id ;
1615
1611
1616
- submenuIds . set ( action . id , subMenuId ) ;
1617
- }
1612
+ if ( ! historyItemRefActions . has ( actionId ) ) {
1613
+ continue ;
1614
+ }
1618
1615
1619
- // Register a new action for the history item ref
1620
- this . _contextMenuDisposables . value . add ( registerAction2 ( class extends Action2 {
1621
- constructor ( ) {
1622
- super ( {
1623
- id : `${ action . id } .${ ref . id } ` ,
1624
- title : ref . name ,
1625
- menu : {
1626
- id : subMenuId ! ,
1627
- group : ref . category
1628
- }
1629
- } ) ;
1630
- }
1631
- override run ( accessor : ServicesAccessor , ...args : any [ ] ) : void {
1632
- const commandService = accessor . get ( ICommandService ) ;
1633
- commandService . executeCommand ( action . id , ...args , ref . id ) ;
1634
- }
1635
- } ) ) ;
1636
- }
1616
+ // Register the submenu for the original action
1617
+ this . _contextMenuDisposables . value . add ( MenuRegistry . appendMenuItem ( MenuId . SCMChangesContext , {
1618
+ title : historyItemRefMenuItem . command . title ,
1619
+ submenu : MenuId . for ( actionId ) ,
1620
+ group : historyItemRefMenuItem ?. group ,
1621
+ order : historyItemRefMenuItem ?. order
1622
+ } ) ) ;
1623
+
1624
+ // Register the action for the history item ref
1625
+ for ( const historyItemRef of historyItemRefActions . get ( actionId ) ?? [ ] ) {
1626
+ this . _contextMenuDisposables . value . add ( registerAction2 ( class extends Action2 {
1627
+ constructor ( ) {
1628
+ super ( {
1629
+ id : `${ actionId } .${ historyItemRef . id } ` ,
1630
+ title : historyItemRef . name ,
1631
+ menu : {
1632
+ id : MenuId . for ( actionId ) ,
1633
+ group : historyItemRef . category
1634
+ }
1635
+ } ) ;
1636
+ }
1637
+ override run ( accessor : ServicesAccessor , ...args : any [ ] ) : void {
1638
+ const commandService = accessor . get ( ICommandService ) ;
1639
+ commandService . executeCommand ( actionId , ...args , historyItemRef . id ) ;
1640
+ }
1641
+ } ) ) ;
1637
1642
}
1638
1643
}
1639
1644
}
0 commit comments