diff --git a/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts b/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts index 7c336c2670c..d7f5dd88388 100644 --- a/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts +++ b/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts @@ -109,6 +109,9 @@ export abstract class BaseWebview extends Disposable { private readonly _focusDelayer = this._register(new ThrottledDelayer(50)); + private readonly _onDidHtmlChange: Emitter = this._register(new Emitter()); + protected readonly onDidHtmlChange = this._onDidHtmlChange.event; + constructor( public readonly id: string, private readonly options: WebviewOptions, @@ -375,6 +378,7 @@ export abstract class BaseWebview extends Disposable { options: this.content.options, state: this.content.state, }); + this._onDidHtmlChange.fire(value); } protected get webviewRootResourceAuthority(): string { diff --git a/src/vs/workbench/contrib/webview/electron-sandbox/iframeWebviewElement.ts b/src/vs/workbench/contrib/webview/electron-sandbox/iframeWebviewElement.ts index f4b2cb2af6d..4602a305d38 100644 --- a/src/vs/workbench/contrib/webview/electron-sandbox/iframeWebviewElement.ts +++ b/src/vs/workbench/contrib/webview/electron-sandbox/iframeWebviewElement.ts @@ -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(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; } }));