From bcf20d226e3e3a526be7e08964fa703d993affb0 Mon Sep 17 00:00:00 2001 From: wangpenglong Date: Fri, 2 Aug 2024 11:14:55 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20webview=E7=9A=84=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD,=E4=B8=B4=E6=97=B6=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E4=B8=BA=E8=83=BD=E5=A4=9F=E6=9F=A5=E6=89=BE=E5=88=B0=E7=BB=93?= =?UTF-8?q?=E6=9E=9C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I775019555576815246898b7d7c14c1511477223a --- .../contrib/webview/browser/webviewElement.ts | 3 +- .../electron-sandbox/webviewElement.ts | 115 +++++++++--------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/src/vs/workbench/contrib/webview/browser/webviewElement.ts b/src/vs/workbench/contrib/webview/browser/webviewElement.ts index 4ad13ada..fb48b46b 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewElement.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewElement.ts @@ -257,7 +257,8 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD })); this._register(this.on('did-find', ({ didFind }) => { - this._hasFindResult.fire(didFind); + // force enable prevBtn and nextBtn + this._hasFindResult.fire(true); })); this._register(this.on('fatal-error', (e) => { diff --git a/src/vs/workbench/contrib/webview/electron-sandbox/webviewElement.ts b/src/vs/workbench/contrib/webview/electron-sandbox/webviewElement.ts index e10b2a65..646620d0 100644 --- a/src/vs/workbench/contrib/webview/electron-sandbox/webviewElement.ts +++ b/src/vs/workbench/contrib/webview/electron-sandbox/webviewElement.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Delayer } from 'vs/base/common/async'; +// import { Delayer } from 'vs/base/common/async'; import { VSBuffer, VSBufferReadableStream } from 'vs/base/common/buffer'; import { Schemas } from 'vs/base/common/network'; import { consumeStream } from 'vs/base/common/stream'; @@ -20,7 +20,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITunnelService } from 'vs/platform/tunnel/common/tunnel'; -import { FindInFrameOptions, IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService'; +import { IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService'; import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/browser/themeing'; import { WebviewInitInfo } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewElement } from 'vs/workbench/contrib/webview/browser/webviewElement'; @@ -38,7 +38,7 @@ export class ElectronWebviewElement extends WebviewElement { private _cachedHtmlContent: string | undefined; private readonly _webviewMainService: IWebviewManagerService; - private readonly _iframeDelayer = this._register(new Delayer(200)); + // private readonly _iframeDelayer = this._register(new Delayer(200)); protected override get platform() { return 'electron'; } @@ -63,7 +63,7 @@ export class ElectronWebviewElement extends WebviewElement { configurationService, contextMenuService, notificationService, environmentService, fileService, logService, remoteAuthorityResolverService, telemetryService, tunnelService, instantiationService, accessibilityService); - this._webviewKeyboardHandler = new WindowIgnoreMenuShortcutsManager(configurationService, mainProcessService, _nativeHostService); + this._webviewKeyboardHandler = new WindowIgnoreMenuShortcutsManager(configurationService, mainProcessService, this._nativeHostService); this._webviewMainService = ProxyChannel.toService(mainProcessService.getChannel('webview')); @@ -76,6 +76,7 @@ export class ElectronWebviewElement extends WebviewElement { })); this._register(this._webviewMainService.onFoundInFrame((result) => { + console.log('found in frame', result.matches); this._hasFindResult.fire(result.matches > 0); })); } @@ -108,63 +109,63 @@ export class ElectronWebviewElement extends WebviewElement { }); } - /** - * Webviews expose a stateful find API. - * Successive calls to find will move forward or backward through onFindResults - * depending on the supplied options. - * - * @param value The string to search for. Empty strings are ignored. - */ - public override find(value: string, previous: boolean): void { - if (!this.element) { - return; - } + // /** + // * Webviews expose a stateful find API. + // * Successive calls to find will move forward or backward through onFindResults + // * depending on the supplied options. + // * + // * @param value The string to search for. Empty strings are ignored. + // */ + // public override find(value: string, previous: boolean): void { + // if (!this.element) { + // return; + // } - if (!this._findStarted) { - this.updateFind(value); - } else { - // continuing the find, so set findNext to false - const options: FindInFrameOptions = { forward: !previous, findNext: false, matchCase: false }; - this._webviewMainService.findInFrame({ windowId: this._nativeHostService.windowId }, this.id, value, options); - } - } + // if (!this._findStarted) { + // this.updateFind(value); + // } else { + // // continuing the find, so set findNext to false + // const options: FindInFrameOptions = { forward: !previous, findNext: false, matchCase: false }; + // this._webviewMainService.findInFrame({ windowId: this._nativeHostService.windowId }, this.id, value, options); + // } + // } - public override updateFind(value: string) { - if (!value || !this.element) { - return; - } + // public override updateFind(value: string) { + // if (!value || !this.element) { + // return; + // } - // FindNext must be true for a first request - const options: FindInFrameOptions = { - forward: true, - findNext: true, - matchCase: false - }; + // // FindNext must be true for a first request + // const options: FindInFrameOptions = { + // forward: true, + // findNext: true, + // matchCase: false + // }; - this._iframeDelayer.trigger(() => { - this._findStarted = true; - this._webviewMainService.findInFrame({ windowId: this._nativeHostService.windowId }, this.id, value, options); - }); - } + // this._iframeDelayer.trigger(() => { + // this._findStarted = true; + // this._webviewMainService.findInFrame({ windowId: this._nativeHostService.windowId }, this.id, value, options); + // }); + // } - public override stopFind(keepSelection?: boolean): void { - if (!this.element) { - return; - } - this._iframeDelayer.cancel(); - this._findStarted = false; - this._webviewMainService.stopFindInFrame({ windowId: this._nativeHostService.windowId }, this.id, { - keepSelection - }); - this._onDidStopFind.fire(); - } + // public override stopFind(keepSelection?: boolean): void { + // if (!this.element) { + // return; + // } + // this._iframeDelayer.cancel(); + // this._findStarted = false; + // this._webviewMainService.stopFindInFrame({ windowId: this._nativeHostService.windowId }, this.id, { + // keepSelection + // }); + // this._onDidStopFind.fire(); + // } - protected override handleFocusChange(isFocused: boolean): void { - super.handleFocusChange(isFocused); - if (isFocused) { - this._webviewKeyboardHandler.didFocus(); - } else { - this._webviewKeyboardHandler.didBlur(); - } - } + // protected override handleFocusChange(isFocused: boolean): void { + // super.handleFocusChange(isFocused); + // if (isFocused) { + // this._webviewKeyboardHandler.didFocus(); + // } else { + // this._webviewKeyboardHandler.didBlur(); + // } + // } }