From 252b12be13d2e92a93835b2e9c99ff43fedc18cd Mon Sep 17 00:00:00 2001 From: Vjekoslav Ratkajec Date: Fri, 5 Feb 2016 09:06:21 +0100 Subject: [PATCH] Add readRtf feature with appropriate spec test. Docs updated as well. --- atom/common/api/atom_api_clipboard.cc | 8 ++++++++ docs/api/clipboard.md | 10 +++++++++- spec/api-clipboard-spec.js | 12 +++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/atom/common/api/atom_api_clipboard.cc b/atom/common/api/atom_api_clipboard.cc index 5060db17e9aa..5186e22c8d9e 100644 --- a/atom/common/api/atom_api_clipboard.cc +++ b/atom/common/api/atom_api_clipboard.cc @@ -93,6 +93,13 @@ void WriteText(const base::string16& text, mate::Arguments* args) { writer.WriteText(text); } +base::string16 ReadRtf(mate::Arguments* args) { + std::string data; + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + clipboard->ReadRTF(GetClipboardType(args), &data); + return base::UTF8ToUTF16(data); +} + void WriteRtf(const std::string& text, mate::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardType(args)); writer.WriteRTF(text); @@ -139,6 +146,7 @@ void Initialize(v8::Local exports, v8::Local unused, dict.SetMethod("write", &Write); dict.SetMethod("readText", &ReadText); dict.SetMethod("writeText", &WriteText); + dict.SetMethod("readRtf", &ReadRtf); dict.SetMethod("writeRtf", &WriteRtf); dict.SetMethod("readHtml", &ReadHtml); dict.SetMethod("writeHtml", &WriteHtml); diff --git a/docs/api/clipboard.md b/docs/api/clipboard.md index a655977a0e69..dcb9fa398a90 100644 --- a/docs/api/clipboard.md +++ b/docs/api/clipboard.md @@ -61,9 +61,17 @@ Returns the content in the clipboard as a [NativeImage](native-image.md). Writes `image` to the clipboard. -### `clipboard.writeRtf(text)` +### `clipboard.readRtf([type])` + +* `type` String (optional) + +Returns the content in the clipboard as RTF. + + +### `clipboard.writeRtf(text[, type])` * `text` String +* `type` String (optional) Writes the `text` into the clipboard in RTF. diff --git a/spec/api-clipboard-spec.js b/spec/api-clipboard-spec.js index 6154181f0926..fe94e330d414 100644 --- a/spec/api-clipboard-spec.js +++ b/spec/api-clipboard-spec.js @@ -35,20 +35,30 @@ describe('clipboard module', function() { return assert.equal(clipboard.readHtml(), markup); }); }); + describe('clipboard.readRtf', function() { + return it('returns rtf text correctly', function() { + var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}"; + clipboard.writeRtf(rtf); + return assert.equal(clipboard.readRtf(), rtf); + }); + }); return describe('clipboard.write()', function() { return it('returns data correctly', function() { - var i, markup, p, text; + var i, markup, p, text, rtf; text = 'test'; + rtf = '{\\rtf1\\utf8 text}'; p = path.join(fixtures, 'assets', 'logo.png'); i = nativeImage.createFromPath(p); markup = process.platform === 'darwin' ? 'Hi' : process.platform === 'linux' ? 'Hi' : 'Hi'; clipboard.write({ text: "test", html: 'Hi', + rtf: '{\\rtf1\\utf8 text}', image: p }); assert.equal(clipboard.readText(), text); assert.equal(clipboard.readHtml(), markup); + assert.equal(clipboard.readRtf(), rtf); return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL()); }); });