Fix iframe search, fixes #127507, fixes #127458

Subscribe to HTML change instead of state update
This commit is contained in:
Raymond Zhao 2021-06-30 13:20:21 -07:00
parent 16ed03a205
commit 578eb5caff
No known key found for this signature in database
GPG key ID: D36E5FCE46B63B58
2 changed files with 9 additions and 8 deletions

View file

@ -109,6 +109,9 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
private readonly _focusDelayer = this._register(new ThrottledDelayer(50));
private readonly _onDidHtmlChange: Emitter<string> = this._register(new Emitter<string>());
protected readonly onDidHtmlChange = this._onDidHtmlChange.event;
constructor(
public readonly id: string,
private readonly options: WebviewOptions,
@ -375,6 +378,7 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
options: this.content.options,
state: this.content.state,
});
this._onDidHtmlChange.fire(value);
}
protected get webviewRootResourceAuthority(): string {

View file

@ -5,7 +5,6 @@
import { Schemas } from 'vs/base/common/network';
import { IMenuService } from 'vs/platform/actions/common/actions';
import { addDisposableListener } from 'vs/base/browser/dom';
import { Emitter, Event } from 'vs/base/common/event';
import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@ -38,6 +37,7 @@ export class ElectronIframeWebview extends IFrameWebview implements WebviewFindD
private _webviewFindWidget: WebviewFindWidget | undefined;
private _findStarted: boolean = false;
private _cachedHtmlContent: string | undefined;
private readonly _webviewMainService: IWebviewManagerService;
private readonly _iframeDelayer = this._register(new Delayer<void>(200));
@ -62,7 +62,7 @@ export class ElectronIframeWebview extends IFrameWebview implements WebviewFindD
@IMainProcessService mainProcessService: IMainProcessService,
@INotificationService notificationService: INotificationService,
@INativeHostService private readonly nativeHostService: INativeHostService,
@IInstantiationService instantiationService: IInstantiationService,
@IInstantiationService instantiationService: IInstantiationService
) {
super(id, options, contentOptions, extension, webviewThemeDataProvider,
contextMenuService,
@ -83,13 +83,10 @@ export class ElectronIframeWebview extends IFrameWebview implements WebviewFindD
if (options.enableFindWidget) {
this._webviewFindWidget = this._register(instantiationService.createInstance(WebviewFindWidget, this));
this._register(addDisposableListener(this.element!, 'found-in-page', e => {
this._hasFindResult.fire(e.result.matches > 0);
}));
this._register(this.on(WebviewMessageChannels.doUpdateState, () => {
if (this._findStarted) {
this._register(this.onDidHtmlChange((newContent) => {
if (this._findStarted && this._cachedHtmlContent !== newContent) {
this.stopFind(false);
this._cachedHtmlContent = newContent;
}
}));