Clipboard

Reads and writes clipboard payloads for paste and copy operations.

Access:

app.getService('clipboard')

App code:

const clipboard = app.getService('clipboard');

Plugin:

const clipboard = this.app.getService('clipboard');

getContent#

Determines whether to read text/plain or text/html from the clipboard and returns the content, HTML-escaping plain text via encoder.

Parameters:

  • clipboard (object) — clipboard data object

Returns: string

clipboard.getContent(event.clipboardData);

setContent#

Writes text/html (with rx-editor meta marker and SVG whitespace cleanup) and text/plain (derived from HTML or explicit text) to the clipboard on a copy/cut event.

Parameters:

  • event (Event) — native DOM event
  • html (string) — HTML string
  • text (string) — text

Returns: void

clipboard.setContent(event, html, plainText);

isPlainText#

Returns true when the clipboard has text/plain but no non-empty text/html payload.

Parameters:

  • clipboard (object) — clipboard data object

Returns: boolean

clipboard.isPlainText(event.clipboardData);

isPlainHtml#

Returns true when text/plain contains HTML-like angle-bracket markup.

Parameters:

  • clipboard (object) — clipboard data object

Returns: boolean

clipboard.isPlainHtml(event.clipboardData);

createPasteClipboard#

Creates a mutable clipboard view for paste handling. getData reads from the native clipboard unless setData overrode that MIME type. Used by clipboard:before:paste so plugins can rewrite paste data even though native paste DataTransfer is read-only.

Parameters:

  • source (object) — native clipboard data object (event.clipboardData)

Returns: object with getData, setData, files, items, types

const pasteClipboard = clipboard.createPasteClipboard(event.clipboardData);
pasteClipboard.setData('text/plain', 'rewritten');

determineContentType#

Returns 'text/plain' when isPlainText is true, otherwise 'text/html'.

Parameters:

  • clipboard (object) — clipboard data object

Returns: 'text/plain'|'text/html'

clipboard.determineContentType(event.clipboardData);