Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/vs/platform/browserView/common/browserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ export interface IBrowserViewService {
*/
focus(id: string): Promise<void>;

/**
* Copy selected content to clipboard
* @param id The browser view identifier
*/
copy(id: string): Promise<void>;

/**
* Paste content from clipboard
* @param id The browser view identifier
*/
paste(id: string): Promise<void>;

/**
* Cut selected content to clipboard
* @param id The browser view identifier
*/
cut(id: string): Promise<void>;

/**
* Clear all storage data for the global browser session
*/
Expand Down
21 changes: 21 additions & 0 deletions src/vs/platform/browserView/electron-main/browserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,27 @@ export class BrowserView extends Disposable {
this._view.webContents.focus();
}

/**
* Copy selected content to clipboard
*/
async copy(): Promise<void> {
this._view.webContents.copy();
}

/**
* Paste content from clipboard
*/
async paste(): Promise<void> {
this._view.webContents.paste();
}

/**
* Cut selected content to clipboard
*/
async cut(): Promise<void> {
this._view.webContents.cut();
}

/**
* Get the underlying WebContentsView
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ export class BrowserViewMainService extends Disposable implements IBrowserViewMa
return this._getBrowserView(id).focus();
}

async copy(id: string): Promise<void> {
return this._getBrowserView(id).copy();
}

async paste(id: string): Promise<void> {
return this._getBrowserView(id).paste();
}

async cut(id: string): Promise<void> {
return this._getBrowserView(id).cut();
}

async clearGlobalStorage(): Promise<void> {
const { session, resolvedScope } = this.getSession(BrowserViewStorageScope.Global);
if (resolvedScope !== BrowserViewStorageScope.Global) {
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/contrib/browserView/common/browserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export interface IBrowserViewModel extends IDisposable {
captureScreenshot(options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;
dispatchKeyEvent(keyEvent: IBrowserViewKeyDownEvent): Promise<void>;
focus(): Promise<void>;
copy(): Promise<void>;
paste(): Promise<void>;
cut(): Promise<void>;
}

export class BrowserViewModel extends Disposable implements IBrowserViewModel {
Expand Down Expand Up @@ -294,6 +297,18 @@ export class BrowserViewModel extends Disposable implements IBrowserViewModel {
return this.browserViewService.focus(this.id);
}

async copy(): Promise<void> {
return this.browserViewService.copy(this.id);
}

async paste(): Promise<void> {
return this.browserViewService.paste(this.id);
}

async cut(): Promise<void> {
return this.browserViewService.cut(this.id);
}

/**
* Log navigation telemetry event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ export class BrowserEditor extends EditorPane {
return this._model?.toggleDevTools();
}

async copy(): Promise<void> {
return this._model?.copy();
}

async paste(): Promise<void> {
return this._model?.paste();
}

async cut(): Promise<void> {
return this._model?.cut();
}

/**
* Update navigation state and context keys
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,23 @@ 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) {
f(activeEditor);
return true;
}

return false;
});
}

redirectCommandToBrowser(UndoCommand);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot let's do the same for undo, redo, and select all here. And remove the unused redirectCommandToBrowser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8aa0bb4. Added undo, redo, and selectAll methods across the browser view stack and removed the unused redirectCommandToBrowser function. All commands now use overrideCommandForBrowser consistently with the webview pattern.

redirectCommandToBrowser(RedoCommand);
redirectCommandToBrowser(SelectAllCommand);
redirectCommandToBrowser(CopyAction);
redirectCommandToBrowser(PasteAction);
redirectCommandToBrowser(CutAction);
overrideCommandForBrowser(CopyAction, browserEditor => void browserEditor.copy());
overrideCommandForBrowser(PasteAction, browserEditor => void browserEditor.paste());
overrideCommandForBrowser(CutAction, browserEditor => void browserEditor.cut());