@@ -6,7 +6,7 @@ import { ifDefined } from 'lit/directives/if-defined.js';
6
6
import { when } from 'lit/directives/when.js' ;
7
7
import type { GitTrackingState } from '../../../../../git/models/branch' ;
8
8
import { createWebviewCommandLink } from '../../../../../system/webview' ;
9
- import type { GetOverviewBranch , OpenInGraphParams , State } from '../../../../home/protocol' ;
9
+ import type { BranchRef , GetOverviewBranch , OpenInGraphParams , State } from '../../../../home/protocol' ;
10
10
import { stateContext } from '../../../home/context' ;
11
11
import type { ActionList } from '../../../shared/components/actions/action-list' ;
12
12
import { ipcContext } from '../../../shared/context' ;
@@ -209,7 +209,30 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
209
209
` ;
210
210
}
211
211
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
+ }
213
236
214
237
private renderActions ( branch : GetOverviewBranch , repo : string ) {
215
238
const branchRefs = {
@@ -242,27 +265,7 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
242
265
return nothing ;
243
266
}
244
267
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 ) }
266
269
limit =${ 3 }
267
270
.items=${ actions }
268
271
class="branch-item__actions"
0 commit comments