Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test webview context menus proposal #156224

Closed
3 tasks done
mjbvz opened this issue Jul 26, 2022 · 0 comments
Closed
3 tasks done

Test webview context menus proposal #156224

mjbvz opened this issue Jul 26, 2022 · 0 comments

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 26, 2022

Test for #54285

Complexity: 5

Create Issue


Summary

#54285 introduces a new contribution point for context menus on webviews. These menus can also use when clauses that control when they are shown or hidden

"webview/context": [
	{
		"command": "gitlens.showSettingsPage",
		"when": "webview == 'gitlens.welcome'"
	}
],

The contents of the webview can change the when clauses by setting data-vscode-context with json values of the new context. For example, if I right click inside of nav with the following html:

<div class="menu" data-vscode-context='{"webviewSection": "menu", "countOfThing": 123}'>
    ...
    <div class="nav" data-vscode-context='{"webviewSection": "nav", "preventDefaultContextMenuItems": true}'>
        ...
    </div>
</div>

The set contexts would be:

  • webviewSection = "nav" (overrides the value from the . menu element)
  • countOfThing = 123 (inherited from the parent .menu element)
  • preventDefaultContextMenuItems = true

The preventDefaultContextMenuItems context should prevent the default context menu items from showing up (copy, paste, ...)

Testing

Using the webview extension sample, try testing:

  • Context menus only show up if you set:

    "enabledApiProposals": [
    	"contribWebviewContext"
    ],
    
  1. You can register webview context menu items and use webview == 'catCoding' to register a new menu. For example:

    "contributes": {
    	"menus": {
    		"webview/context": [
    			{
    				"command": "catCoding.doRefactor",
    				"when": "webview == 'catCoding'"
    			}
    		]
    	},
  2. Your html can suppress the default context menu items using preventDefaultContextMenuItems with data-vscode-context (see above)

  3. Your html can set custom context using data-vscode-context

  4. Any set contexts should override contexts set by parent element (the above example shows this for webviewSection)

@mjbvz mjbvz added this to the July 2022 milestone Jul 26, 2022
@aeschli aeschli removed their assignment Jul 27, 2022
@justschen justschen removed their assignment Jul 27, 2022
@karthiknadig karthiknadig removed their assignment Jul 27, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants