diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index dd2799a30e9..6ccd223f3d6 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -412,6 +412,46 @@ bool WebContents::IsDevToolsOpened() { return storage_->IsDevToolsViewShowing(); } +void WebContents::Undo() { + web_contents()->Undo(); +} + +void WebContents::Redo() { + web_contents()->Redo(); +} + +void WebContents::Cut() { + web_contents()->Cut(); +} + +void WebContents::Copy() { + web_contents()->Copy(); +} + +void WebContents::Paste() { + web_contents()->Paste(); +} + +void WebContents::Delete() { + web_contents()->Delete(); +} + +void WebContents::SelectAll() { + web_contents()->SelectAll(); +} + +void WebContents::Unselect() { + web_contents()->Unselect(); +} + +void WebContents::Replace(const base::string16& word) { + web_contents()->Replace(word); +} + +void WebContents::ReplaceMisspelling(const base::string16& word) { + web_contents()->ReplaceMisspelling(word); +} + bool WebContents::SendIPCMessage(const base::string16& channel, const base::ListValue& args) { return Send(new AtomViewMsg_Message(routing_id(), channel, args)); @@ -482,13 +522,23 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("setUserAgent", &WebContents::SetUserAgent) .SetMethod("insertCSS", &WebContents::InsertCSS) .SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript) + .SetMethod("openDevTools", &WebContents::OpenDevTools) + .SetMethod("closeDevTools", &WebContents::CloseDevTools) + .SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened) + .SetMethod("undo", &WebContents::Undo) + .SetMethod("redo", &WebContents::Redo) + .SetMethod("cut", &WebContents::Cut) + .SetMethod("copy", &WebContents::Copy) + .SetMethod("paste", &WebContents::Paste) + .SetMethod("delete", &WebContents::Delete) + .SetMethod("selectAll", &WebContents::SelectAll) + .SetMethod("unselect", &WebContents::Unselect) + .SetMethod("replace", &WebContents::Replace) + .SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling) .SetMethod("_send", &WebContents::SendIPCMessage) .SetMethod("setAutoSize", &WebContents::SetAutoSize) .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency) .SetMethod("isGuest", &WebContents::is_guest) - .SetMethod("openDevTools", &WebContents::OpenDevTools) - .SetMethod("closeDevTools", &WebContents::CloseDevTools) - .SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened) .Build()); return mate::ObjectTemplateBuilder( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 34def1758fc..dc556b2796d 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -67,6 +67,20 @@ class WebContents : public mate::EventEmitter, void OpenDevTools(); void CloseDevTools(); bool IsDevToolsOpened(); + + // Editing commands. + void Undo(); + void Redo(); + void Cut(); + void Copy(); + void Paste(); + void Delete(); + void SelectAll(); + void Unselect(); + void Replace(const base::string16& word); + void ReplaceMisspelling(const base::string16& word); + + // Sending messages to browser. bool SendIPCMessage(const base::string16& channel, const base::ListValue& args); diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 0229b83fd40..727a462d1ac 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -254,6 +254,16 @@ registerWebViewElement = -> "openDevTools" "closeDevTools" "isDevToolsOpened" + "undo" + "redo" + "cut" + "copy" + "paste" + "delete" + "selectAll" + "unselect" + "replace" + "replaceMisspelling" "send" "getId" ] diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 3a838a6cfeb..3525631b1d9 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -743,7 +743,51 @@ Injects CSS into this page. * `code` String -Evaluate `code` in page. +Evaluates `code` in page. + +### WebContents.undo() + +Executes editing command `undo` in page. + +### WebContents.redo() + +Executes editing command `redo` in page. + +### WebContents.cut() + +Executes editing command `cut` in page. + +### WebContents.copy() + +Executes editing command `copy` in page. + +### WebContents.paste() + +Executes editing command `paste` in page. + +### WebContents.delete() + +Executes editing command `delete` in page. + +### WebContents.selectAll() + +Executes editing command `selectAll` in page. + +### WebContents.unselect() + +Executes editing command `unselect` in page. + +### WebContents.replace(text) + +* `text` String + +Executes editing command `replace` in page. + +### WebContents.replaceMisspelling(text) + +* `text` String + +Executes editing command `replaceMisspelling` in page. ### WebContents.send(channel[, args...]) diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 459e734ca59..40ccf1f174a 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -219,6 +219,50 @@ Closes the devtools window of guest page. Returns whether guest page has a devtools window attached. +### ``.undo() + +Executes editing command `undo` in page. + +### ``.redo() + +Executes editing command `redo` in page. + +### ``.cut() + +Executes editing command `cut` in page. + +### ``.copy() + +Executes editing command `copy` in page. + +### ``.paste() + +Executes editing command `paste` in page. + +### ``.delete() + +Executes editing command `delete` in page. + +### ``.selectAll() + +Executes editing command `selectAll` in page. + +### ``.unselect() + +Executes editing command `unselect` in page. + +### ``.replace(text) + +* `text` String + +Executes editing command `replace` in page. + +### ``.replaceMisspelling(text) + +* `text` String + +Executes editing command `replaceMisspelling` in page. + ### ``.send(channel[, args...]) * `channel` String