webview:show find widget with argument

This commit is contained in:
chriswang521 2024-05-16 11:06:33 +08:00 committed by wangpenglong
parent 8801172d07
commit f6cdb061a1
6 changed files with 39 additions and 1 deletions

View File

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

View File

@ -359,6 +359,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(animated = true) { hideFind(animated = true) {
this._findWidgetVisible?.reset(); this._findWidgetVisible?.reset();
this._webview.value?.hideFind(animated); this._webview.value?.hideFind(animated);

View File

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

View File

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

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 { export class HideWebViewEditorFindCommand extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.hideFind'; public static readonly ID = 'editor.action.webvieweditor.hideFind';
public static readonly LABEL = nls.localize('editor.action.webvieweditor.hideFind', "Stop find"); 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 { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; 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 { WebviewEditor } from './webviewEditor';
import { WebviewInput } from './webviewEditorInput'; import { WebviewInput } from './webviewEditorInput';
import { WebviewEditorInputSerializer } from './webviewEditorInputSerializer'; import { WebviewEditorInputSerializer } from './webviewEditorInputSerializer';
@ -91,6 +91,7 @@ Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEdit
registerSingleton(IWebviewWorkbenchService, WebviewEditorService, InstantiationType.Delayed); registerSingleton(IWebviewWorkbenchService, WebviewEditorService, InstantiationType.Delayed);
registerAction2(ShowWebViewEditorFindWidgetAction); registerAction2(ShowWebViewEditorFindWidgetAction);
registerAction2(ShowWebViewEditorFindWidgetWithArgAction);
registerAction2(HideWebViewEditorFindCommand); registerAction2(HideWebViewEditorFindCommand);
registerAction2(WebViewEditorFindNextCommand); registerAction2(WebViewEditorFindNextCommand);
registerAction2(WebViewEditorFindPreviousCommand); registerAction2(WebViewEditorFindPreviousCommand);