@@ -6,7 +6,7 @@ import { ifDefined } from 'lit/directives/if-defined.js';
66import { when } from 'lit/directives/when.js' ;
77import type { GitTrackingState } from '../../../../../git/models/branch' ;
88import { createWebviewCommandLink } from '../../../../../system/webview' ;
9- import type { GetOverviewBranch , OpenInGraphParams , State } from '../../../../home/protocol' ;
9+ import type { BranchRef , GetOverviewBranch , OpenInGraphParams , State } from '../../../../home/protocol' ;
1010import { stateContext } from '../../../home/context' ;
1111import type { ActionList } from '../../../shared/components/actions/action-list' ;
1212import { ipcContext } from '../../../shared/context' ;
@@ -209,7 +209,30 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
209209 ` ;
210210 }
211211
212- private prevAttr = JSON . parse ( document . body . getAttribute ( 'data-vscode-context' ) ?? '{}' ) ;
212+ private applyContext ( context : object ) {
213+ const prevContext = JSON . parse ( document . body . getAttribute ( 'data-vscode-context' ) ?? '{}' ) ;
214+ document . body . setAttribute (
215+ 'data-vscode-context' ,
216+ JSON . stringify ( {
217+ ...prevContext ,
218+ ...context ,
219+ } ) ,
220+ ) ;
221+ setTimeout ( ( ) => {
222+ document . body . setAttribute ( 'data-vscode-context' , JSON . stringify ( prevContext ) ) ;
223+ } ) ;
224+ }
225+
226+ private handleBranchContext ( branchRefs : BranchRef , e : typeof ActionList . OpenContextMenuEvent ) {
227+ let context = 'gitlens:home' ;
228+ e . detail . items . forEach ( x => {
229+ if ( x . href ) {
230+ context += `+${ x . href } ` ;
231+ }
232+ } ) ;
233+ // clear context immediatelly after the contextmenu is opened to avoid randomly clicked contextmenu being filled
234+ this . applyContext ( { webviewItem : context , ...branchRefs , type : 'branch' } ) ;
235+ }
213236
214237 private renderActions ( branch : GetOverviewBranch , repo : string ) {
215238 const branchRefs = {
@@ -242,27 +265,7 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
242265 return nothing ;
243266 }
244267 return html `< action-list
245- @open-actions-menu =${ ( e : typeof ActionList . OpenContextMenuEvent ) => {
246- this . prevAttr = JSON . parse ( document . body . getAttribute ( 'data-vscode-context' ) ?? '{}' ) ;
247- let context = 'gitlens:home' ;
248- e . detail . items . forEach ( x => {
249- if ( x . href ) {
250- context += `+${ x . href } ` ;
251- }
252- } ) ;
253- document . body . setAttribute (
254- 'data-vscode-context' ,
255- JSON . stringify ( {
256- ...this . prevAttr ,
257- webviewItem : context ,
258- ...branchRefs ,
259- type : 'branch' ,
260- } ) ,
261- ) ;
262- } }
263- @close-actions-menu =${ ( ) => {
264- document . body . setAttribute ( 'data-vscode-context' , JSON . stringify ( this . prevAttr ) ) ;
265- } }
268+ @open-actions-menu =${ this . handleBranchContext . bind ( this , branchRefs ) }
266269 limit =${ 3 }
267270 .items=${ actions }
268271 class="branch-item__actions"
0 commit comments