Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 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,42 @@ export interface IBrowserViewService {
*/
focus(id: string): Promise<void>;

/**
* Undo the last editing action
* @param id The browser view identifier
*/
undo(id: string): Promise<void>;

/**
* Redo the last undone action
* @param id The browser view identifier
*/
redo(id: string): Promise<void>;

/**
* Select all content
* @param id The browser view identifier
*/
selectAll(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
42 changes: 42 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,48 @@ export class BrowserView extends Disposable {
this._view.webContents.focus();
}

/**
* Undo the last editing action
*/
async undo(): Promise<void> {
this._view.webContents.undo();
}

/**
* Redo the last undone action
*/
async redo(): Promise<void> {
this._view.webContents.redo();
}

/**
* Select all content
*/
async selectAll(): Promise<void> {
this._view.webContents.selectAll();
}

/**
* 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,30 @@ export class BrowserViewMainService extends Disposable implements IBrowserViewMa
return this._getBrowserView(id).focus();
}

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

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

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

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
30 changes: 30 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,12 @@ export interface IBrowserViewModel extends IDisposable {
captureScreenshot(options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;
dispatchKeyEvent(keyEvent: IBrowserViewKeyDownEvent): Promise<void>;
focus(): Promise<void>;
undo(): Promise<void>;
redo(): Promise<void>;
selectAll(): Promise<void>;
copy(): Promise<void>;
paste(): Promise<void>;
cut(): Promise<void>;
}

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

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

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

async selectAll(): Promise<void> {
return this.browserViewService.selectAll(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,30 @@ export class BrowserEditor extends EditorPane {
return this._model?.toggleDevTools();
}

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

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

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

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 @@ -124,24 +124,23 @@ Registry.as<IConfigurationRegistry>(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());