@@ -10,7 +10,7 @@ import { IAction } from 'vs/base/common/actions';
1010import { ThrottledDelayer } from 'vs/base/common/async' ;
1111import { streamToBuffer } from 'vs/base/common/buffer' ;
1212import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
13- import { Emitter } from 'vs/base/common/event' ;
13+ import { Emitter , Event } from 'vs/base/common/event' ;
1414import { Disposable , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
1515import { Schemas } from 'vs/base/common/network' ;
1616import { URI } from 'vs/base/common/uri' ;
@@ -22,6 +22,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2222import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
2323import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
2424import { IFileService } from 'vs/platform/files/common/files' ;
25+ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
2526import { ILogService } from 'vs/platform/log/common/log' ;
2627import { INotificationService } from 'vs/platform/notification/common/notification' ;
2728import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver' ;
@@ -32,6 +33,7 @@ import { asWebviewUri, decodeAuthority, webviewGenericCspSource, webviewRootReso
3233import { loadLocalResource , WebviewResourceResponse } from 'vs/workbench/contrib/webview/browser/resourceLoading' ;
3334import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/browser/themeing' ;
3435import { areWebviewContentOptionsEqual , Webview , WebviewContentOptions , WebviewExtensionDescription , WebviewMessageReceivedEvent , WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview' ;
36+ import { WebviewFindDelegate , WebviewFindWidget } from 'vs/workbench/contrib/webview/browser/webviewFindWidget' ;
3537import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
3638
3739export const enum WebviewMessageChannels {
@@ -41,6 +43,7 @@ export const enum WebviewMessageChannels {
4143 didFocus = 'did-focus' ,
4244 didBlur = 'did-blur' ,
4345 didLoad = 'did-load' ,
46+ didFind = 'did-find' ,
4447 doUpdateState = 'do-update-state' ,
4548 doReload = 'do-reload' ,
4649 setConfirmBeforeClose = 'set-confirm-before-close' ,
@@ -88,7 +91,7 @@ namespace WebviewState {
8891 export type State = typeof Ready | Initializing ;
8992}
9093
91- export class IFrameWebview extends Disposable implements Webview {
94+ export class IFrameWebview extends Disposable implements Webview , WebviewFindDelegate {
9295
9396 protected get platform ( ) : string { return 'browser' ; }
9497
@@ -129,6 +132,9 @@ export class IFrameWebview extends Disposable implements Webview {
129132
130133 private readonly _messageHandlers = new Map < string , Set < ( data : any ) => void > > ( ) ;
131134
135+ protected readonly _webviewFindWidget : WebviewFindWidget | undefined ;
136+ public readonly checkImeCompletionState = true ;
137+
132138 constructor (
133139 public readonly id : string ,
134140 private readonly options : WebviewOptions ,
@@ -145,6 +151,7 @@ export class IFrameWebview extends Disposable implements Webview {
145151 @IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService : IRemoteAuthorityResolverService ,
146152 @ITelemetryService private readonly _telemetryService : ITelemetryService ,
147153 @ITunnelService private readonly _tunnelService : ITunnelService ,
154+ @IInstantiationService instantiationService : IInstantiationService ,
148155 ) {
149156 super ( ) ;
150157
@@ -215,6 +222,10 @@ export class IFrameWebview extends Disposable implements Webview {
215222 this . handleFocusChange ( false ) ;
216223 } ) ) ;
217224
225+ this . _register ( this . on ( WebviewMessageChannels . didFind , ( didFind : boolean ) => {
226+ this . _hasFindResult . fire ( didFind ) ;
227+ } ) ) ;
228+
218229 this . _register ( this . on < { message : string } > ( WebviewMessageChannels . fatalError , ( e ) => {
219230 notificationService . error ( localize ( 'fatalErrorMessage' , "Error loading webview: {0}" , e . message ) ) ;
220231 } ) ) ;
@@ -312,6 +323,11 @@ export class IFrameWebview extends Disposable implements Webview {
312323 }
313324 } ) ) ;
314325
326+ if ( options . enableFindWidget ) {
327+ this . _webviewFindWidget = this . _register ( instantiationService . createInstance ( WebviewFindWidget , this ) ) ;
328+ this . styledFindWidget ( ) ;
329+ }
330+
315331 this . initElement ( extension , options ) ;
316332 }
317333
@@ -416,9 +432,14 @@ export class IFrameWebview extends Disposable implements Webview {
416432 }
417433
418434 public mountTo ( parent : HTMLElement ) {
419- if ( this . element ) {
420- parent . appendChild ( this . element ) ;
435+ if ( ! this . element ) {
436+ return ;
421437 }
438+
439+ if ( this . _webviewFindWidget ) {
440+ parent . appendChild ( this . _webviewFindWidget . getDomNode ( ) ! ) ;
441+ }
442+ parent . appendChild ( this . element ) ;
422443 }
423444
424445 protected get webviewContentEndpoint ( ) : string {
@@ -584,6 +605,12 @@ export class IFrameWebview extends Disposable implements Webview {
584605 }
585606
586607 this . _send ( 'styles' , { styles, activeTheme, themeName : themeLabel } ) ;
608+
609+ this . styledFindWidget ( ) ;
610+ }
611+
612+ private styledFindWidget ( ) {
613+ this . _webviewFindWidget ?. updateTheme ( this . webviewThemeDataProvider . getTheme ( ) ) ;
587614 }
588615
589616 private handleFocusChange ( isFocused : boolean ) : void {
@@ -755,15 +782,51 @@ export class IFrameWebview extends Disposable implements Webview {
755782 } ) ;
756783 }
757784
758- public showFind ( ) : void {
759- // noop
785+ protected readonly _hasFindResult = this . _register ( new Emitter < boolean > ( ) ) ;
786+ public readonly hasFindResult : Event < boolean > = this . _hasFindResult . event ;
787+
788+ protected readonly _onDidStopFind = this . _register ( new Emitter < void > ( ) ) ;
789+ public readonly onDidStopFind : Event < void > = this . _onDidStopFind . event ;
790+
791+ /**
792+ * Webviews expose a stateful find API.
793+ * Successive calls to find will move forward or backward through onFindResults
794+ * depending on the supplied options.
795+ *
796+ * @param value The string to search for. Empty strings are ignored.
797+ */
798+ public find ( value : string , previous : boolean ) : void {
799+ if ( ! this . element ) {
800+ return ;
801+ }
802+
803+ this . _send ( 'find' , { value, previous } ) ;
804+ }
805+
806+ public startFind ( value : string ) {
807+ if ( ! value || ! this . element ) {
808+ return ;
809+ }
810+ this . _send ( 'find' , { value } ) ;
811+ }
812+
813+ public stopFind ( keepSelection ?: boolean ) : void {
814+ if ( ! this . element ) {
815+ return ;
816+ }
817+ this . _send ( 'find-stop' , { keepSelection } ) ;
818+ this . _onDidStopFind . fire ( ) ;
819+ }
820+
821+ public showFind ( ) {
822+ this . _webviewFindWidget ?. reveal ( ) ;
760823 }
761824
762- public hideFind ( ) : void {
763- // noop
825+ public hideFind ( ) {
826+ this . _webviewFindWidget ?. hide ( ) ;
764827 }
765828
766- public runFindAction ( previous : boolean ) : void {
767- // noop
829+ public runFindAction ( previous : boolean ) {
830+ this . _webviewFindWidget ?. find ( previous ) ;
768831 }
769832}
0 commit comments