@@ -783,6 +783,84 @@ export function* pickBranchStep<
783783 return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
784784}
785785
786+ export function * pickOrResetBranchStep <
787+ State extends PartialStepState & { repo : Repository } ,
788+ Context extends { repos : Repository [ ] ; showTags ?: boolean ; title : string } ,
789+ > (
790+ state : State ,
791+ context : Context ,
792+ {
793+ filter,
794+ picked,
795+ placeholder,
796+ title,
797+ resetTitle,
798+ resetDescription,
799+ } : {
800+ filter ?: ( b : GitBranch ) => boolean ;
801+ picked ?: string | string [ ] ;
802+ placeholder : string ;
803+ title ?: string ;
804+ resetTitle : string ;
805+ resetDescription : string ;
806+ } ,
807+ ) : StepResultGenerator < GitBranchReference | undefined > {
808+ const items = getBranches ( state . repo , {
809+ buttons : [ RevealInSideBarQuickInputButton ] ,
810+ filter : filter ,
811+ picked : picked ,
812+ } ) . then ( branches =>
813+ branches . length === 0
814+ ? [ createDirectiveQuickPickItem ( Directive . Back , true ) , createDirectiveQuickPickItem ( Directive . Cancel ) ]
815+ : [
816+ createDirectiveQuickPickItem ( Directive . Reset , false , {
817+ label : resetTitle ,
818+ description : resetDescription ,
819+ } ) ,
820+ ...branches ,
821+ ] ,
822+ ) ;
823+
824+ const resetButton : QuickInputButton = {
825+ iconPath : new ThemeIcon ( 'notebook-revert' ) ,
826+ tooltip : resetDescription ,
827+ } ;
828+ let resetButtonClicked = false ;
829+ const step = createPickStep < BranchQuickPickItem > ( {
830+ title : appendReposToTitle ( title ?? context . title , state , context ) ,
831+ placeholder : count => ( ! count ? `No branches found in ${ state . repo . formattedName } ` : placeholder ) ,
832+ matchOnDetail : true ,
833+ items : items ,
834+ additionalButtons : [ resetButton ] ,
835+ onDidClickButton : ( _quickpick , button ) => {
836+ if ( button === resetButton ) {
837+ resetButtonClicked = true ;
838+ return true ;
839+ }
840+ return false ;
841+ } ,
842+ onDidClickItemButton : ( _quickpick , button , { item } ) => {
843+ if ( button === RevealInSideBarQuickInputButton ) {
844+ void BranchActions . reveal ( item , { select : true , focus : false , expand : true } ) ;
845+ }
846+ } ,
847+ keys : [ 'right' , 'alt+right' , 'ctrl+right' ] ,
848+ onDidPressKey : async ( _quickpick , _key , { item } ) => {
849+ await BranchActions . reveal ( item , {
850+ select : true ,
851+ focus : false ,
852+ expand : true ,
853+ } ) ;
854+ } ,
855+ } ) ;
856+
857+ const selection : StepSelection < typeof step > = yield step ;
858+ if ( resetButtonClicked ) {
859+ return undefined ;
860+ }
861+ return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
862+ }
863+
786864export function * pickBranchesStep <
787865 State extends PartialStepState & { repo : Repository } ,
788866 Context extends { repos : Repository [ ] ; showTags ?: boolean ; title : string } ,
0 commit comments