@@ -839,6 +839,7 @@ class GitGraphView {
839839 this . selectedCommits . clear ( ) ;
840840 }
841841
842+
842843 private selectCommitRange ( fromHash : string , toHash : string ) {
843844 const fromIndex = this . commitLookup [ fromHash ] ;
844845 const toIndex = this . commitLookup [ toHash ] ;
@@ -887,7 +888,9 @@ class GitGraphView {
887888 }
888889
889890 private areSelectedCommitsOnCurrentBranch ( ) : boolean {
890- if ( this . selectedCommits . size === 0 || ! this . gitBranchHead ) return false ;
891+ if ( this . selectedCommits . size === 0 || ! this . gitBranchHead ) {
892+ return false ;
893+ }
891894
892895 // Find the commit that the current branch points to
893896 let currentBranchCommitIndex = - 1 ;
@@ -898,18 +901,39 @@ class GitGraphView {
898901 }
899902 }
900903
901- if ( currentBranchCommitIndex === - 1 ) return false ;
904+ if ( currentBranchCommitIndex === - 1 ) {
905+ return false ;
906+ }
902907
903- for ( const hash of Array . from ( this . selectedCommits ) ) {
904- const index = this . commitLookup [ hash ] ;
905- if ( index < currentBranchCommitIndex ) {
906- const commit = this . commits [ index ] ;
907- if ( ! commit . heads || ! commit . heads . includes ( this . gitBranchHead ) ) {
908- return false ;
908+ // Build a set of all commits that are ancestors of the current branch head
909+ const branchCommits = new Set < string > ( ) ;
910+ const queue = [ currentBranchCommitIndex ] ;
911+ const visited = new Set < number > ( ) ;
912+
913+ while ( queue . length > 0 ) {
914+ const index = queue . shift ( ) ! ;
915+ if ( visited . has ( index ) ) continue ;
916+ visited . add ( index ) ;
917+
918+ const commit = this . commits [ index ] ;
919+ branchCommits . add ( commit . hash ) ;
920+
921+ // Add parent commits to the queue
922+ for ( const parentHash of commit . parents ) {
923+ const parentIndex = this . commitLookup [ parentHash ] ;
924+ if ( parentIndex !== undefined && ! visited . has ( parentIndex ) ) {
925+ queue . push ( parentIndex ) ;
909926 }
910927 }
911928 }
912929
930+ // Check if all selected commits are in the branch
931+ for ( const hash of Array . from ( this . selectedCommits ) ) {
932+ if ( ! branchCommits . has ( hash ) ) {
933+ return false ;
934+ }
935+ }
936+
913937 return true ;
914938 }
915939
@@ -1489,7 +1513,7 @@ class GitGraphView {
14891513 }
14901514 } , {
14911515 title : 'Edit Message' + ELLIPSIS ,
1492- visible : visibility . editMessage ,
1516+ visible : visibility . editMessage && this . areSelectedCommitsOnCurrentBranch ( ) ,
14931517 onClick : ( ) => this . editCommitMessageAction ( target )
14941518 } , {
14951519 title : 'Reset Last Commit' + ELLIPSIS ,
@@ -2612,7 +2636,9 @@ class GitGraphView {
26122636 if ( this . expandedCommit . commitHash === commit . hash ) {
26132637 this . closeCommitDetails ( true ) ;
26142638 } else {
2639+ // Regular click with details open: select only this commit and load details
26152640 this . clearCommitSelection ( ) ;
2641+ this . toggleCommitSelection ( commit . hash , eventElem ) ;
26162642 this . loadCommitDetails ( eventElem ) ;
26172643 }
26182644 } else {
@@ -2711,6 +2737,19 @@ class GitGraphView {
27112737 const commit = this . getCommitOfElem ( eventElem ) ;
27122738 if ( commit === null ) return ;
27132739
2740+ // Close any open commit details to avoid visual confusion
2741+ // The commitDetailsOpen class can make commits appear selected
2742+ if ( this . expandedCommit !== null && this . expandedCommit . commitHash !== commit . hash ) {
2743+ this . closeCommitDetails ( false ) ;
2744+ }
2745+
2746+ // Only clear and select if the commit is not already selected
2747+ if ( ! this . selectedCommits . has ( commit . hash ) ) {
2748+ this . clearCommitSelection ( ) ;
2749+ this . toggleCommitSelection ( commit . hash , eventElem ) ;
2750+ }
2751+
2752+ // If the commit is already selected, keep the current selection for multi-select context menu
27142753 const target : ContextMenuTarget & DialogTarget & CommitTarget = {
27152754 type : TargetType . Commit ,
27162755 hash : commit . hash ,
0 commit comments