提交 11597a29 编写于 作者: M Matt Bierner

Move find state tracking into webview overlay

上级 da59b139
...@@ -8,14 +8,16 @@ import { memoize } from 'vs/base/common/decorators'; ...@@ -8,14 +8,16 @@ import { memoize } from 'vs/base/common/decorators';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IWebviewService, Webview, WebviewContentOptions, WebviewOverlay, WebviewElement, WebviewOptions, WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview'; import { IWebviewService, Webview, WebviewContentOptions, WebviewOverlay, WebviewElement, WebviewOptions, WebviewExtensionDescription, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from 'vs/workbench/contrib/webview/browser/webview';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService'; import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { Dimension } from 'vs/base/browser/dom'; import { Dimension } from 'vs/base/browser/dom';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
/** /**
* Webview editor overlay that creates and destroys the underlying webview as needed. * Webview editor overlay that creates and destroys the underlying webview as needed.
*/ */
export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOverlay { export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOverlay {
private readonly _onDidWheel = this._register(new Emitter<IMouseWheelEvent>()); private readonly _onDidWheel = this._register(new Emitter<IMouseWheelEvent>());
public readonly onDidWheel = this._onDidWheel.event; public readonly onDidWheel = this._onDidWheel.event;
...@@ -33,18 +35,24 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv ...@@ -33,18 +35,24 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
private _owner: any = undefined; private _owner: any = undefined;
private readonly _scopedContextKeyService = this._register(new MutableDisposable<IContextKeyService>());
private _findWidgetVisible: IContextKey<boolean>;
public constructor( public constructor(
private readonly id: string, private readonly id: string,
initialOptions: WebviewOptions, initialOptions: WebviewOptions,
initialContentOptions: WebviewContentOptions, initialContentOptions: WebviewContentOptions,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService, @IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService,
@IWebviewService private readonly _webviewService: IWebviewService @IWebviewService private readonly _webviewService: IWebviewService,
) { ) {
super(); super();
this._options = initialOptions; this._options = initialOptions;
this._contentOptions = initialContentOptions; this._contentOptions = initialContentOptions;
this._findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(_contextKeyService);
this._register(toDisposable(() => this.container.remove())); this._register(toDisposable(() => this.container.remove()));
} }
...@@ -101,7 +109,10 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv ...@@ -101,7 +109,10 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
if (this._options.tryRestoreScrollPosition) { if (this._options.tryRestoreScrollPosition) {
webview.initialScrollProgress = this._initialScrollProgress; webview.initialScrollProgress = this._initialScrollProgress;
} }
webview.mountTo(this.container); webview.mountTo(this.container);
this._scopedContextKeyService.value = this._contextKeyService.createScoped(this.container);
this._findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(this._scopedContextKeyService.value);
// Forward events from inner webview to outer listeners // Forward events from inner webview to outer listeners
this._webviewEvents.clear(); this._webviewEvents.clear();
...@@ -188,11 +199,22 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv ...@@ -188,11 +199,22 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
focus(): void { this.withWebview(webview => webview.focus()); } focus(): void { this.withWebview(webview => webview.focus()); }
reload(): void { this.withWebview(webview => webview.reload()); } reload(): void { this.withWebview(webview => webview.reload()); }
showFind(): void { this.withWebview(webview => webview.showFind()); }
hideFind(): void { this.withWebview(webview => webview.hideFind()); }
runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); }
selectAll(): void { this.withWebview(webview => webview.selectAll()); } selectAll(): void { this.withWebview(webview => webview.selectAll()); }
showFind() {
if (this._webview.value) {
this._webview.value.showFind();
this._findWidgetVisible.set(true);
}
}
hideFind() {
this._findWidgetVisible.reset();
this._webview.value?.hideFind();
}
runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); }
public getInnerWebview() { public getInnerWebview() {
return this._webview.value; return this._webview.value;
} }
......
...@@ -101,10 +101,16 @@ export interface Webview extends IDisposable { ...@@ -101,10 +101,16 @@ export interface Webview extends IDisposable {
windowDidDragEnd(): void; windowDidDragEnd(): void;
} }
/**
* Basic webview rendered in the dom
*/
export interface WebviewElement extends Webview { export interface WebviewElement extends Webview {
mountTo(parent: HTMLElement): void; mountTo(parent: HTMLElement): void;
} }
/**
* Dynamically created webview drawn over another element.
*/
export interface WebviewOverlay extends Webview { export interface WebviewOverlay extends Webview {
readonly container: HTMLElement; readonly container: HTMLElement;
options: WebviewOptions; options: WebviewOptions;
......
...@@ -8,12 +8,12 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; ...@@ -8,12 +8,12 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { Action2 } from 'vs/platform/actions/common/actions'; import { Action2 } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from 'vs/workbench/contrib/webview/browser/webview'; import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor'; import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
export class ShowWebViewEditorFindWidgetAction extends Action2 { export class ShowWebViewEditorFindWidgetAction extends Action2 {
public static readonly ID = 'editor.action.webvieweditor.showFind'; public static readonly ID = 'editor.action.webvieweditor.showFind';
...@@ -74,7 +74,7 @@ export class WebViewEditorFindNextCommand extends Action2 { ...@@ -74,7 +74,7 @@ export class WebViewEditorFindNextCommand extends Action2 {
} }
public run(accessor: ServicesAccessor): void { public run(accessor: ServicesAccessor): void {
getActiveWebviewEditor(accessor)?.find(false); getActiveWebviewEditor(accessor)?.runFindAction(false);
} }
} }
...@@ -95,7 +95,7 @@ export class WebViewEditorFindPreviousCommand extends Action2 { ...@@ -95,7 +95,7 @@ export class WebViewEditorFindPreviousCommand extends Action2 {
} }
public run(accessor: ServicesAccessor): void { public run(accessor: ServicesAccessor): void {
getActiveWebviewEditor(accessor)?.find(true); getActiveWebviewEditor(accessor)?.runFindAction(true);
} }
} }
...@@ -135,7 +135,7 @@ export class ReloadWebviewAction extends Action { ...@@ -135,7 +135,7 @@ export class ReloadWebviewAction extends Action {
public run(): Promise<any> { public run(): Promise<any> {
for (const webview of this.getVisibleWebviews()) { for (const webview of this.getVisibleWebviews()) {
webview.reload(); webview.webview?.reload();
} }
return Promise.resolve(true); return Promise.resolve(true);
} }
...@@ -147,8 +147,8 @@ export class ReloadWebviewAction extends Action { ...@@ -147,8 +147,8 @@ export class ReloadWebviewAction extends Action {
} }
} }
export function getActiveWebviewEditor(accessor: ServicesAccessor): WebviewEditor | undefined { export function getActiveWebviewEditor(accessor: ServicesAccessor): Webview | undefined {
const editorService = accessor.get(IEditorService); const editorService = accessor.get(IEditorService);
const activeEditorPane = editorService.activeEditorPane as WebviewEditor | undefined; const activeEditorPane = editorService.activeEditorPane as WebviewEditor | undefined;
return activeEditorPane?.isWebviewEditor ? activeEditorPane : undefined; return activeEditorPane?.isWebviewEditor ? activeEditorPane.webview : undefined;
} }
...@@ -8,14 +8,13 @@ import { CancellationToken } from 'vs/base/common/cancellation'; ...@@ -8,14 +8,13 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle'; import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { isWeb } from 'vs/base/common/platform'; import { isWeb } from 'vs/base/common/platform';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IStorageService } from 'vs/platform/storage/common/storage'; import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IThemeService } from 'vs/platform/theme/common/themeService';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart'; import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor'; import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, WebviewOverlay } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewOverlay } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput'; import { WebviewInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
...@@ -25,8 +24,6 @@ export class WebviewEditor extends BaseEditor { ...@@ -25,8 +24,6 @@ export class WebviewEditor extends BaseEditor {
public static readonly ID = 'WebviewEditor'; public static readonly ID = 'WebviewEditor';
private readonly _scopedContextKeyService = this._register(new MutableDisposable<IContextKeyService>());
private _findWidgetVisible: IContextKey<boolean>;
private _editorFrame?: HTMLElement; private _editorFrame?: HTMLElement;
private _content?: HTMLElement; private _content?: HTMLElement;
private _dimension?: DOM.Dimension; private _dimension?: DOM.Dimension;
...@@ -41,14 +38,11 @@ export class WebviewEditor extends BaseEditor { ...@@ -41,14 +38,11 @@ export class WebviewEditor extends BaseEditor {
@ITelemetryService telemetryService: ITelemetryService, @ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService, @IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService, @IStorageService storageService: IStorageService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IEditorService private readonly _editorService: IEditorService, @IEditorService private readonly _editorService: IEditorService,
@IEditorGroupsService private readonly _editorGroupsService: IEditorGroupsService, @IEditorGroupsService private readonly _editorGroupsService: IEditorGroupsService,
@IHostService private readonly _hostService: IHostService, @IHostService private readonly _hostService: IHostService,
) { ) {
super(WebviewEditor.ID, telemetryService, themeService, storageService); super(WebviewEditor.ID, telemetryService, themeService, storageService);
this._findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(_contextKeyService);
} }
public get isWebviewEditor() { public get isWebviewEditor() {
...@@ -70,30 +64,6 @@ export class WebviewEditor extends BaseEditor { ...@@ -70,30 +64,6 @@ export class WebviewEditor extends BaseEditor {
super.dispose(); super.dispose();
} }
public showFind() {
if (this.webview) {
this.webview.showFind();
this._findWidgetVisible.set(true);
}
}
public hideFind() {
this._findWidgetVisible.reset();
this.webview?.hideFind();
}
public find(previous: boolean) {
this.webview?.runFindAction(previous);
}
public selectAll() {
this.webview?.selectAll();
}
public reload() {
this.webview?.reload();
}
public layout(dimension: DOM.Dimension): void { public layout(dimension: DOM.Dimension): void {
this._dimension = dimension; this._dimension = dimension;
if (this.webview) { if (this.webview) {
...@@ -169,11 +139,6 @@ export class WebviewEditor extends BaseEditor { ...@@ -169,11 +139,6 @@ export class WebviewEditor extends BaseEditor {
private claimWebview(input: WebviewInput): void { private claimWebview(input: WebviewInput): void {
input.webview.claim(this); input.webview.claim(this);
if (input.webview.options.enableFindWidget) {
this._scopedContextKeyService.value = this._contextKeyService.createScoped(input.webview.container);
this._findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(this._scopedContextKeyService.value);
}
if (this._content) { if (this._content) {
this._content.setAttribute('aria-flowto', input.webview.container.id); this._content.setAttribute('aria-flowto', input.webview.container.id);
} }
......
...@@ -146,7 +146,7 @@ export class RedoWebviewEditorCommand extends Action2 { ...@@ -146,7 +146,7 @@ export class RedoWebviewEditorCommand extends Action2 {
} }
function getActiveWebviewBasedWebview(accessor: ServicesAccessor): ElectronWebviewBasedWebview | undefined { function getActiveWebviewBasedWebview(accessor: ServicesAccessor): ElectronWebviewBasedWebview | undefined {
const webview = getActiveWebviewEditor(accessor)?.webview; const webview = getActiveWebviewEditor(accessor);
if (!webview) { if (!webview) {
return undefined; return undefined;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册