webview: show find widget with argument

This commit is contained in:
全卓 2023-06-19 15:39:50 +08:00 committed by chriswang521
parent 6ab3506e67
commit 818176248e
6 changed files with 39 additions and 1 deletions

View File

@ -196,6 +196,10 @@ export abstract class SimpleFindWidget extends Widget {
return this._findInput.getValue();
}
public setInputValue(value: string) {
this._findInput.setValue(value);
}
public get focusTracker(): dom.IFocusTracker {
return this._focusTracker;
}

View File

@ -340,6 +340,13 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
}
}
public showFindWithArg(arg: string) {
if (this._webview.value) {
this._webview.value.showFindWithArg!(arg);
this._findWidgetVisible?.set(true);
}
}
hideFind() {
this._findWidgetVisible?.reset();
this._webview.value?.hideFind();

View File

@ -188,6 +188,7 @@ export interface IWebview extends IDisposable {
reload(): void;
showFind(): void;
showFindWithArg?(value: string): void;
hideFind(): void;
runFindAction(previous: boolean): void;

View File

@ -929,6 +929,11 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this._webviewFindWidget?.reveal();
}
public showFindWithArg(arg: string) {
this.showFind();
this._webviewFindWidget?.setInputValue(arg);
}
public hideFind() {
this._webviewFindWidget?.hide();
}

View File

@ -39,6 +39,26 @@ export class ShowWebViewEditorFindWidgetAction extends Action2 {
}
}
export class ShowWebViewEditorFindWidgetWithArgAction extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.showFindWithArg';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.showFindWithArg', "Show find with argument");
constructor() {
super({
id: ShowWebViewEditorFindWidgetWithArgAction.ID,
title: ShowWebViewEditorFindWidgetWithArgAction.LABEL,
keybinding: {
when: ContextKeyExpr.and(webviewActiveContextKeyExpr, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_ENABLED),
weight: KeybindingWeight.EditorContrib
}
});
}
public run(accessor: ServicesAccessor, ...args: any[]): void {
getActiveWebviewEditor(accessor)?.showFindWithArg!(args[0] as string);
}
}
export class HideWebViewEditorFindCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.hideFind';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.hideFind', "Stop find");

View File

@ -16,7 +16,7 @@ import { EditorExtensions, IEditorFactoryRegistry } from 'vs/workbench/common/ed
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetAction, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand } from './webviewCommands';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindWidgetWithArgAction, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand } from './webviewCommands';
import { WebviewEditor } from './webviewEditor';
import { WebviewInput } from './webviewEditorInput';
import { WebviewEditorInputSerializer } from './webviewEditorInputSerializer';
@ -91,6 +91,7 @@ Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEdit
registerSingleton(IWebviewWorkbenchService, WebviewEditorService, true);
registerAction2(ShowWebViewEditorFindWidgetAction);
registerAction2(ShowWebViewEditorFindWidgetWithArgAction);
registerAction2(HideWebViewEditorFindCommand);
registerAction2(WebViewEditorFindNextCommand);
registerAction2(WebViewEditorFindPreviousCommand);