diff --git a/src/vs/platform/browserView/common/browserView.ts b/src/vs/platform/browserView/common/browserView.ts index 335147600e69e..135b921814468 100644 --- a/src/vs/platform/browserView/common/browserView.ts +++ b/src/vs/platform/browserView/common/browserView.ts @@ -203,6 +203,42 @@ export interface IBrowserViewService { */ focus(id: string): Promise; + /** + * Undo the last editing action + * @param id The browser view identifier + */ + undo(id: string): Promise; + + /** + * Redo the last undone action + * @param id The browser view identifier + */ + redo(id: string): Promise; + + /** + * Select all content + * @param id The browser view identifier + */ + selectAll(id: string): Promise; + + /** + * Copy selected content to clipboard + * @param id The browser view identifier + */ + copy(id: string): Promise; + + /** + * Paste content from clipboard + * @param id The browser view identifier + */ + paste(id: string): Promise; + + /** + * Cut selected content to clipboard + * @param id The browser view identifier + */ + cut(id: string): Promise; + /** * Clear all storage data for the global browser session */ diff --git a/src/vs/platform/browserView/electron-main/browserView.ts b/src/vs/platform/browserView/electron-main/browserView.ts index 7498771656006..bf94e69f52667 100644 --- a/src/vs/platform/browserView/electron-main/browserView.ts +++ b/src/vs/platform/browserView/electron-main/browserView.ts @@ -428,6 +428,48 @@ export class BrowserView extends Disposable { this._view.webContents.focus(); } + /** + * Undo the last editing action + */ + async undo(): Promise { + this._view.webContents.undo(); + } + + /** + * Redo the last undone action + */ + async redo(): Promise { + this._view.webContents.redo(); + } + + /** + * Select all content + */ + async selectAll(): Promise { + this._view.webContents.selectAll(); + } + + /** + * Copy selected content to clipboard + */ + async copy(): Promise { + this._view.webContents.copy(); + } + + /** + * Paste content from clipboard + */ + async paste(): Promise { + this._view.webContents.paste(); + } + + /** + * Cut selected content to clipboard + */ + async cut(): Promise { + this._view.webContents.cut(); + } + /** * Get the underlying WebContentsView */ diff --git a/src/vs/platform/browserView/electron-main/browserViewMainService.ts b/src/vs/platform/browserView/electron-main/browserViewMainService.ts index 403ebc74399b8..325d9f27f688c 100644 --- a/src/vs/platform/browserView/electron-main/browserViewMainService.ts +++ b/src/vs/platform/browserView/electron-main/browserViewMainService.ts @@ -203,6 +203,30 @@ export class BrowserViewMainService extends Disposable implements IBrowserViewMa return this._getBrowserView(id).focus(); } + async undo(id: string): Promise { + return this._getBrowserView(id).undo(); + } + + async redo(id: string): Promise { + return this._getBrowserView(id).redo(); + } + + async selectAll(id: string): Promise { + return this._getBrowserView(id).selectAll(); + } + + async copy(id: string): Promise { + return this._getBrowserView(id).copy(); + } + + async paste(id: string): Promise { + return this._getBrowserView(id).paste(); + } + + async cut(id: string): Promise { + return this._getBrowserView(id).cut(); + } + async clearGlobalStorage(): Promise { const { session, resolvedScope } = this.getSession(BrowserViewStorageScope.Global); if (resolvedScope !== BrowserViewStorageScope.Global) { diff --git a/src/vs/workbench/contrib/browserView/common/browserView.ts b/src/vs/workbench/contrib/browserView/common/browserView.ts index cb312c7d5a895..6441f6d08ed1d 100644 --- a/src/vs/workbench/contrib/browserView/common/browserView.ts +++ b/src/vs/workbench/contrib/browserView/common/browserView.ts @@ -109,6 +109,12 @@ export interface IBrowserViewModel extends IDisposable { captureScreenshot(options?: IBrowserViewCaptureScreenshotOptions): Promise; dispatchKeyEvent(keyEvent: IBrowserViewKeyDownEvent): Promise; focus(): Promise; + undo(): Promise; + redo(): Promise; + selectAll(): Promise; + copy(): Promise; + paste(): Promise; + cut(): Promise; } export class BrowserViewModel extends Disposable implements IBrowserViewModel { @@ -294,6 +300,30 @@ export class BrowserViewModel extends Disposable implements IBrowserViewModel { return this.browserViewService.focus(this.id); } + async undo(): Promise { + return this.browserViewService.undo(this.id); + } + + async redo(): Promise { + return this.browserViewService.redo(this.id); + } + + async selectAll(): Promise { + return this.browserViewService.selectAll(this.id); + } + + async copy(): Promise { + return this.browserViewService.copy(this.id); + } + + async paste(): Promise { + return this.browserViewService.paste(this.id); + } + + async cut(): Promise { + return this.browserViewService.cut(this.id); + } + /** * Log navigation telemetry event */ diff --git a/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts b/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts index 590290854865a..801b182e1ec38 100644 --- a/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts +++ b/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts @@ -447,6 +447,30 @@ export class BrowserEditor extends EditorPane { return this._model?.toggleDevTools(); } + async undo(): Promise { + return this._model?.undo(); + } + + async redo(): Promise { + return this._model?.redo(); + } + + async selectAll(): Promise { + return this._model?.selectAll(); + } + + async copy(): Promise { + return this._model?.copy(); + } + + async paste(): Promise { + return this._model?.paste(); + } + + async cut(): Promise { + return this._model?.cut(); + } + /** * Update navigation state and context keys */ diff --git a/src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts b/src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts index 5e4f20ed9be44..d02fd99106932 100644 --- a/src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts +++ b/src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts @@ -124,24 +124,23 @@ Registry.as(ConfigurationExtensions.Configuration).regis const PRIORITY = 100; -function redirectCommandToBrowser(command: MultiCommand | undefined) { +function overrideCommandForBrowser(command: MultiCommand | undefined, f: (browserEditor: BrowserEditor) => void) { command?.addImplementation(PRIORITY, 'integratedBrowser', (accessor: ServicesAccessor) => { const editorService = accessor.get(IEditorService); const activeEditor = editorService.activeEditorPane; if (activeEditor instanceof BrowserEditor) { - // This will return false if there is no event to forward - // (i.e., the command was not triggered from the browser view) - return activeEditor.forwardCurrentEvent(); + f(activeEditor); + return true; } return false; }); } -redirectCommandToBrowser(UndoCommand); -redirectCommandToBrowser(RedoCommand); -redirectCommandToBrowser(SelectAllCommand); -redirectCommandToBrowser(CopyAction); -redirectCommandToBrowser(PasteAction); -redirectCommandToBrowser(CutAction); +overrideCommandForBrowser(UndoCommand, browserEditor => void browserEditor.undo()); +overrideCommandForBrowser(RedoCommand, browserEditor => void browserEditor.redo()); +overrideCommandForBrowser(SelectAllCommand, browserEditor => void browserEditor.selectAll()); +overrideCommandForBrowser(CopyAction, browserEditor => void browserEditor.copy()); +overrideCommandForBrowser(PasteAction, browserEditor => void browserEditor.paste()); +overrideCommandForBrowser(CutAction, browserEditor => void browserEditor.cut());