1package soy.iko.opencode.ui.components
3import android.content.ClipData
4import android.content.ClipboardManager
5import android.content.Context
6import android.widget.Toast
7import androidx.compose.foundation.ExperimentalFoundationApi
8import androidx.compose.foundation.combinedClickable
9import androidx.compose.material3.MaterialTheme
10import androidx.compose.runtime.Composable
11import androidx.compose.ui.Modifier
12import androidx.compose.ui.platform.LocalContext
13import androidx.compose.ui.text.TextStyle
14import com.mikepenz.markdown.m3.Markdown
17 * Renders markdown using [multiplatform-markdown-renderer](https://github.com/mikepenz/multiplatform-markdown-renderer)
18 * (commonmark-java under the hood). Keeps a local API so callers don't import the library directly.
19 * Long-press copies the raw markdown to the system clipboard.
21@OptIn(ExperimentalFoundationApi::class)
25 modifier: Modifier = Modifier,
26 style: TextStyle = MaterialTheme.typography.bodyLarge,
28 val context = LocalContext.current
31 modifier = modifier.combinedClickable(
33 onLongClick = { copyToClipboard(context, markdown) },
38/** Copy [text] to the system clipboard and show a confirmation toast. */
39internal fun copyToClipboard(context: Context, label: String, text: String = label) {
40 val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
41 clipboard.setPrimaryClip(ClipData.newPlainText(label.take(40), text))
42 Toast.makeText(context, "Copied", Toast.LENGTH_SHORT).show()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list