mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Revert "Revert "Merge from vscode ada4bddb8edc69eea6ebaaa0e88c5f903cbd43d8 (#5529)" (#5553)" (#5562)
This reverts commit c9a4f8f664.
This commit is contained in:
@@ -153,7 +153,7 @@ module.exports = function createWebviewManager(host) {
|
||||
scrollTarget.scrollIntoView();
|
||||
}
|
||||
} else {
|
||||
host.postMessage('did-click-link', node.href);
|
||||
host.postMessage('did-click-link', node.href.baseVal || node.href);
|
||||
}
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
@@ -170,7 +170,7 @@ export class WebviewEditorInput extends EditorInput {
|
||||
this._html = value;
|
||||
|
||||
if (this._webview) {
|
||||
this._webview.contents = value;
|
||||
this._webview.html = value;
|
||||
this._currentWebviewHtml = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export interface WebviewContentOptions {
|
||||
|
||||
export interface Webview {
|
||||
|
||||
contents: string;
|
||||
html: string;
|
||||
options: WebviewContentOptions;
|
||||
initialScrollProgress: number;
|
||||
state: string | undefined;
|
||||
|
||||
@@ -354,6 +354,11 @@ class WebviewKeyboardHandler extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
interface WebviewContent {
|
||||
readonly html: string;
|
||||
readonly options: WebviewContentOptions;
|
||||
readonly state: string | undefined;
|
||||
}
|
||||
|
||||
export class WebviewElement extends Disposable implements Webview {
|
||||
private _webview: Electron.WebviewTag;
|
||||
@@ -361,8 +366,8 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
|
||||
private _webviewFindWidget: WebviewFindWidget;
|
||||
private _findStarted: boolean = false;
|
||||
private _contents: string = '';
|
||||
private _state: string | undefined = undefined;
|
||||
private content: WebviewContent;
|
||||
|
||||
private _focused = false;
|
||||
|
||||
private readonly _onDidFocus = this._register(new Emitter<void>());
|
||||
@@ -370,7 +375,7 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
|
||||
constructor(
|
||||
private readonly _options: WebviewOptions,
|
||||
private _contentOptions: WebviewContentOptions,
|
||||
contentOptions: WebviewContentOptions,
|
||||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
@IEnvironmentService environmentService: IEnvironmentService,
|
||||
@@ -380,9 +385,14 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||
) {
|
||||
super();
|
||||
this.content = {
|
||||
html: '',
|
||||
options: contentOptions,
|
||||
state: undefined
|
||||
};
|
||||
|
||||
this._webview = document.createElement('webview');
|
||||
this._webview.setAttribute('partition', `webview${Date.now()}`);
|
||||
|
||||
this._webview.setAttribute('webpreferences', 'contextIsolation=yes');
|
||||
|
||||
this._webview.style.flex = '0 1';
|
||||
@@ -410,21 +420,21 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
this._register(new WebviewProtocolProvider(
|
||||
this._webview,
|
||||
this._options.extension ? this._options.extension.location : undefined,
|
||||
() => (this._contentOptions.localResourceRoots || []),
|
||||
() => (this.content.options.localResourceRoots || []),
|
||||
environmentService,
|
||||
textFileService));
|
||||
|
||||
this._register(new WebviewPortMappingProvider(
|
||||
session,
|
||||
_options.extension ? _options.extension.location : undefined,
|
||||
() => (this._contentOptions.portMappings || []),
|
||||
() => (this.content.options.portMappings || []),
|
||||
tunnelService,
|
||||
_options.extension ? _options.extension.id : undefined,
|
||||
telemetryService
|
||||
));
|
||||
|
||||
if (!this._options.allowSvgs) {
|
||||
const svgBlocker = this._register(new SvgBlocker(session, this._contentOptions));
|
||||
const svgBlocker = this._register(new SvgBlocker(session, this.content.options));
|
||||
svgBlocker.onDidBlockSvg(() => this.onDidBlockSvg());
|
||||
}
|
||||
|
||||
@@ -476,8 +486,9 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
return;
|
||||
|
||||
case 'do-update-state':
|
||||
this._state = event.args[0];
|
||||
this._onDidUpdateState.fire(this._state);
|
||||
const state = event.args[0];
|
||||
this.state = state;
|
||||
this._onDidUpdateState.fire(state);
|
||||
return;
|
||||
|
||||
case 'did-focus':
|
||||
@@ -542,42 +553,53 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
this._send('initial-scroll-position', value);
|
||||
}
|
||||
|
||||
public set state(value: string | undefined) {
|
||||
this._state = value;
|
||||
public set state(state: string | undefined) {
|
||||
this.content = {
|
||||
html: this.content.html,
|
||||
options: this.content.options,
|
||||
state,
|
||||
};
|
||||
}
|
||||
|
||||
public set options(value: WebviewContentOptions) {
|
||||
if (this._contentOptions && areWebviewInputOptionsEqual(value, this._contentOptions)) {
|
||||
public set options(options: WebviewContentOptions) {
|
||||
if (areWebviewInputOptionsEqual(options, this.content.options)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._contentOptions = value;
|
||||
this._send('content', {
|
||||
contents: this._contents,
|
||||
options: this._contentOptions,
|
||||
state: this._state
|
||||
});
|
||||
this.content = {
|
||||
html: this.content.html,
|
||||
options: options,
|
||||
state: this.content.state,
|
||||
};
|
||||
this.doUpdateContent();
|
||||
}
|
||||
|
||||
public set contents(value: string) {
|
||||
this._contents = value;
|
||||
this._send('content', {
|
||||
contents: value,
|
||||
options: this._contentOptions,
|
||||
state: this._state
|
||||
});
|
||||
public set html(value: string) {
|
||||
this.content = {
|
||||
html: value,
|
||||
options: this.content.options,
|
||||
state: this.content.state,
|
||||
};
|
||||
this.doUpdateContent();
|
||||
}
|
||||
|
||||
public update(value: string, options: WebviewContentOptions, retainContextWhenHidden: boolean) {
|
||||
if (retainContextWhenHidden && value === this._contents && this._contentOptions && areWebviewInputOptionsEqual(options, this._contentOptions)) {
|
||||
public update(html: string, options: WebviewContentOptions, retainContextWhenHidden: boolean) {
|
||||
if (retainContextWhenHidden && html === this.content.html && areWebviewInputOptionsEqual(options, this.content.options)) {
|
||||
return;
|
||||
}
|
||||
this._contents = value;
|
||||
this._contentOptions = options;
|
||||
this.content = {
|
||||
html: html,
|
||||
options: options,
|
||||
state: this.content.state,
|
||||
};
|
||||
this.doUpdateContent();
|
||||
}
|
||||
|
||||
private doUpdateContent() {
|
||||
this._send('content', {
|
||||
contents: this._contents,
|
||||
options: this._contentOptions,
|
||||
state: this._state
|
||||
contents: this.content.html,
|
||||
options: this.content.options,
|
||||
state: this.content.state
|
||||
});
|
||||
}
|
||||
|
||||
@@ -620,7 +642,6 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
return colors;
|
||||
}, {} as { [key: string]: string });
|
||||
|
||||
|
||||
const styles = {
|
||||
'vscode-font-family': '-apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif',
|
||||
'vscode-font-weight': 'normal',
|
||||
@@ -717,7 +738,7 @@ export class WebviewElement extends Disposable implements Webview {
|
||||
}
|
||||
|
||||
public reload() {
|
||||
this.contents = this._contents;
|
||||
this.doUpdateContent();
|
||||
}
|
||||
|
||||
public selectAll() {
|
||||
|
||||
Reference in New Issue
Block a user