Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide API to access selection clipboard, fixes #377.
- Loading branch information
Showing
3 changed files
with
73 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
module.exports = | ||
if process.platform is 'linux' and process.type is 'renderer' | ||
# On Linux we could not access clipboard in renderer process. | ||
require('remote').process.atomBinding 'clipboard' | ||
else | ||
process.atomBinding 'clipboard' | ||
if process.platform is 'linux' and process.type is 'renderer' | ||
# On Linux we could not access clipboard in renderer process. | ||
module.exports = require('remote').process.atomBinding 'clipboard' | ||
else | ||
binding = process.atomBinding 'clipboard' | ||
|
||
module.exports = | ||
has: (format, type='standard') -> binding._has format, type | ||
read: (format, type='standard') -> binding._read format, type | ||
readText: (type='standard') -> binding._readText type | ||
writeText: (text, type='standard') -> binding._writeText text, type | ||
clear: (type='standard') -> binding._clear type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,55 @@ | ||
# clipboard | ||
|
||
An example of writing a string to clipboard: | ||
The `clipboard` provides methods to do copy/paste operations. An example of | ||
writing a string to clipboard: | ||
|
||
```javascript | ||
var clipboard = require('clipboard'); | ||
clipboard.writeText('Example String'); | ||
``` | ||
|
||
## clipboard.readText() | ||
On X Window systems, there is also a selection clipboard, to manipulate in it | ||
you need to pass `selection` to each method: | ||
|
||
```javascript | ||
var clipboard = require('clipboard'); | ||
clipboard.writeText('Example String', 'selection'); | ||
console.log(clipboard.readText('selection')); | ||
``` | ||
|
||
## clipboard.readText([type]) | ||
|
||
* `type` String | ||
|
||
Returns the content in clipboard as plain text. | ||
|
||
## clipboard.writeText(text) | ||
## clipboard.writeText(text[, type]) | ||
|
||
* `text` String | ||
* `type` String | ||
|
||
Writes the `text` into clipboard as plain text. | ||
|
||
## clipboard.clear() | ||
## clipboard.clear([type]) | ||
|
||
* `type` String | ||
|
||
Clears everything in clipboard. | ||
|
||
## clipboard.has(type) | ||
## clipboard.has(format[, type]) | ||
|
||
* `format` String | ||
* `type` String | ||
|
||
Returns whether clipboard has data in specified `type`. | ||
Returns whether clipboard has data in specified `format`. | ||
|
||
**Note:** This API is experimental and could be removed in future. | ||
|
||
## clipboard.read(type) | ||
## clipboard.read(format[, type]) | ||
|
||
* `format` String | ||
* `type` String | ||
|
||
Reads the data in clipboard of the `type`. | ||
Reads the data in clipboard of the `format`. | ||
|
||
**Note:** This API is experimental and could be removed in future. |