Skip to content

Commit

Permalink
vscode: support WebviewOptions.enableCommandUris: string[] (#12091)
Browse files Browse the repository at this point in the history
Add support for the `string[]` variant of the `WebviewOptions.enableCommandUris` option.

See https://github.com/microsoft/vscode/blob/1.73.0/src/vscode-dts/vscode.d.ts#L8408-L8415.

Contributed on behalf of STMicroelectronics.

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder authored Jan 25, 2023
1 parent 678e335 commit 866d2ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)

## v1.34.0 - 01/26/2023

- [plugin] Fixed some API inconsistencies related to web views [#12087](https://github.com/eclipse-theia/theia/issues/12087) - Contributed on behalf of STMicroelectronics
- [plugin] added support for `isTransient` of `TerminalOptions` and `ExternalTerminalOptions` VS Code API [#12055](https://github.com/eclipse-theia/theia/pull/12055) - Contributed on behalf of STMicroelectronics
- [terminal] added support for preference `terminal.integrated.enablePersistentSessions` to allow disabling restoring terminals on reload [#12055](https://github.com/eclipse-theia/theia/pull/12055) - Contributed on behalf of STMicroelectronics
- [variable-resolver] fixed evaluations of `pickString` variables [#12100](https://github.com/eclipse-theia/theia/pull/12100) - Contributed on behalf of STMicroelectronics
Expand Down
10 changes: 7 additions & 3 deletions packages/plugin-ext/src/main/browser/webview/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface WebviewContentOptions {
readonly allowForms?: boolean;
readonly localResourceRoots?: ReadonlyArray<string>;
readonly portMapping?: ReadonlyArray<WebviewPortMapping>;
readonly enableCommandUris?: boolean;
readonly enableCommandUris?: boolean | readonly string[];
}

@injectable()
Expand Down Expand Up @@ -450,8 +450,12 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract
}
return link;
}
if (!!this.contentOptions.enableCommandUris && link.scheme === Schemes.command) {
return link;
if (link.scheme === Schemes.command) {
if (Array.isArray(this.contentOptions.enableCommandUris) && this.contentOptions.enableCommandUris.some(value => value === link.path.toString())) {
return link;
} else if (this.contentOptions.enableCommandUris === true) {
return link;
}
}
return undefined;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3900,9 +3900,11 @@ export module '@theia/plugin' {
/**
* Controls whether command uris are enabled in webview content or not.
*
* Defaults to false.
* Defaults to `false` (command uris are disabled).
*
* If you pass in an array, only the commands in the array are allowed.
*/
readonly enableCommandUris?: boolean;
readonly enableCommandUris?: boolean | readonly string[];

/**
* Root paths from which the webview can load local (filesystem) resources using the `theia-resource:` scheme.
Expand Down Expand Up @@ -5055,7 +5057,7 @@ export module '@theia/plugin' {
*
* @return New webview panel.
*/
export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | WebviewPanelShowOptions,
export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | { readonly viewColumn: ViewColumn; readonly preserveFocus?: boolean },
options?: WebviewPanelOptions & WebviewOptions): WebviewPanel;

/**
Expand Down

0 comments on commit 866d2ec

Please sign in to comment.