关闭electron打开webview的查找功能,临时解决为能够查找到结果,但是不能高亮.

This commit is contained in:
wangpenglong 2023-05-18 10:10:40 +08:00 committed by chriswang521
parent 7bfa47c31a
commit 8b07c19524
1 changed files with 49 additions and 49 deletions

View File

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * 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 { VSBuffer, VSBufferReadableStream } from 'vs/base/common/buffer';
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
import { consumeStream } from 'vs/base/common/stream'; import { consumeStream } from 'vs/base/common/stream';
@ -21,7 +21,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITunnelService } from 'vs/platform/tunnel/common/tunnel'; 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 { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/browser/themeing';
import { WebviewElement, WebviewInitInfo, WebviewMessageChannels } from 'vs/workbench/contrib/webview/browser/webviewElement'; import { WebviewElement, WebviewInitInfo, WebviewMessageChannels } from 'vs/workbench/contrib/webview/browser/webviewElement';
import { WindowIgnoreMenuShortcutsManager } from 'vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager'; import { WindowIgnoreMenuShortcutsManager } from 'vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager';
@ -38,7 +38,7 @@ export class ElectronWebviewElement extends WebviewElement {
private _cachedHtmlContent: string | undefined; private _cachedHtmlContent: string | undefined;
private readonly _webviewMainService: IWebviewManagerService; private readonly _webviewMainService: IWebviewManagerService;
private readonly _iframeDelayer = this._register(new Delayer<void>(200)); // private readonly _iframeDelayer = this._register(new Delayer<void>(200));
protected override get platform() { return 'electron'; } protected override get platform() { return 'electron'; }
@ -64,7 +64,7 @@ export class ElectronWebviewElement extends WebviewElement {
configurationService, contextMenuService, menuService, notificationService, environmentService, configurationService, contextMenuService, menuService, notificationService, environmentService,
fileService, logService, remoteAuthorityResolverService, telemetryService, tunnelService, instantiationService, accessibilityService); 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<IWebviewManagerService>(mainProcessService.getChannel('webview')); this._webviewMainService = ProxyChannel.toService<IWebviewManagerService>(mainProcessService.getChannel('webview'));
@ -110,54 +110,54 @@ export class ElectronWebviewElement extends WebviewElement {
}); });
} }
/** // /**
* Webviews expose a stateful find API. // * Webviews expose a stateful find API.
* Successive calls to find will move forward or backward through onFindResults // * Successive calls to find will move forward or backward through onFindResults
* depending on the supplied options. // * depending on the supplied options.
* // *
* @param value The string to search for. Empty strings are ignored. // * @param value The string to search for. Empty strings are ignored.
*/ // */
public override find(value: string, previous: boolean): void { // public override find(value: string, previous: boolean): void {
if (!this.element) { // if (!this.element) {
return; // return;
} // }
if (!this._findStarted) { // if (!this._findStarted) {
this.updateFind(value); // this.updateFind(value);
} else { // } else {
// continuing the find, so set findNext to false // // continuing the find, so set findNext to false
const options: FindInFrameOptions = { forward: !previous, findNext: false, matchCase: false }; // const options: FindInFrameOptions = { forward: !previous, findNext: false, matchCase: false };
this._webviewMainService.findInFrame({ windowId: this.nativeHostService.windowId }, this.id, value, options); // this._webviewMainService.findInFrame({ windowId: this.nativeHostService.windowId }, this.id, value, options);
} // }
} // }
public override updateFind(value: string) { // public override updateFind(value: string) {
if (!value || !this.element) { // if (!value || !this.element) {
return; // return;
} // }
// FindNext must be true for a first request // // FindNext must be true for a first request
const options: FindInFrameOptions = { // const options: FindInFrameOptions = {
forward: true, // forward: true,
findNext: true, // findNext: true,
matchCase: false // matchCase: false
}; // };
this._iframeDelayer.trigger(() => { // this._iframeDelayer.trigger(() => {
this._findStarted = true; // this._findStarted = true;
this._webviewMainService.findInFrame({ windowId: this.nativeHostService.windowId }, this.id, value, options); // this._webviewMainService.findInFrame({ windowId: this.nativeHostService.windowId }, this.id, value, options);
}); // });
} // }
public override stopFind(keepSelection?: boolean): void { // public override stopFind(keepSelection?: boolean): void {
if (!this.element) { // if (!this.element) {
return; // return;
} // }
this._iframeDelayer.cancel(); // this._iframeDelayer.cancel();
this._findStarted = false; // this._findStarted = false;
this._webviewMainService.stopFindInFrame({ windowId: this.nativeHostService.windowId }, this.id, { // this._webviewMainService.stopFindInFrame({ windowId: this.nativeHostService.windowId }, this.id, {
keepSelection // keepSelection
}); // });
this._onDidStopFind.fire(); // this._onDidStopFind.fire();
} // }
} }