Search documentation of mob

# Mob.Clipboard (mob v0.6.18)

Copy Markdown View Source

System clipboard access. No permission required.

## Write

    def handle_event("copy", _params, socket) do
      Mob.Clipboard.put(socket, socket.assigns.text)
      {:noreply, socket}
    end

## Read

    def handle_event("paste", _params, socket) do
      case Mob.Clipboard.get(socket) do
        {:clipboard, :ok, text} -> {:noreply, Mob.Socket.assign(socket, :field, text)}
        {:clipboard, :empty}    -> {:noreply, socket}
      end
    end

`get/1` dispatches to the main thread synchronously (same model as `safe_area/0`) — fast enough to call from any callback.

## Summary

### Functions

get(socket)

Read the current clipboard text synchronously.

put(socket, text)

Write `text` to the system clipboard. Fire-and-forget; returns the socket.

## Functions

# get(socket)

    @spec get(Mob.Socket.t()) :: {:clipboard, :ok, binary()} | {:clipboard, :empty}

Read the current clipboard text synchronously.

Returns `{:clipboard, :ok, text}` or `{:clipboard, :empty}`.

# put(socket, text)

    @spec put(Mob.Socket.t(), binary()) :: Mob.Socket.t()

Write `text` to the system clipboard. Fire-and-forget; returns the socket.