blob: e7bad42e2527d82ffa86edd4188cc7122d70c26c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { SimpleFindWidget } from 'vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/webview/browser/webview';
export interface WebviewFindDelegate {
readonly hasFindResult: Event<boolean>;
readonly onDidStopFind: Event<void>;
readonly checkImeCompletionState: boolean;
find(value: string, previous: boolean): void;
updateFind(value: string): void;
stopFind(keepSelection?: boolean): void;
focus(): void;
}
export class WebviewFindWidget extends SimpleFindWidget {
protected async _getResultCount(dataChanged?: boolean): Promise<{ resultIndex: number; resultCount: number } | undefined> {
return undefined;
}
protected readonly _findWidgetFocused: IContextKey<boolean>;
constructor(
private readonly _delegate: WebviewFindDelegate,
@IContextViewService contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(contextViewService, contextKeyService, undefined, { showOptionButtons: false, checkImeCompletionState: _delegate.checkImeCompletionState });
this._findWidgetFocused = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED.bindTo(contextKeyService);
this._register(_delegate.hasFindResult(hasResult => {
this.updateButtons(hasResult);
this.focusFindBox();
}));
this._register(_delegate.onDidStopFind(() => {
this.updateButtons(false);
}));
}
public find(previous: boolean) {
const val = this.inputValue;
if (val) {
this._delegate.find(val, previous);
}
}
public override hide() {
super.hide();
this._delegate.stopFind(true);
this._delegate.focus();
}
protected _onInputChanged(): boolean {
const val = this.inputValue;
if (val) {
this._delegate.updateFind(val);
} else {
this._delegate.stopFind(false);
}
return false;
}
protected _onFocusTrackerFocus() {
this._findWidgetFocused.set(true);
}
protected _onFocusTrackerBlur() {
this._findWidgetFocused.reset();
}
protected _onFindInputFocusTrackerFocus() { }
protected _onFindInputFocusTrackerBlur() { }
protected findFirst() { }
}
|