Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f1aec14
Read clipboard HTML into a paste tree
sanjaydotpro Nov 16, 2026
0216d16
Add paste fixture corpus and capture tooling
sanjaydotpro Nov 16, 2026
ec46a35
Write pastes as markdown, or in the plain note format
sanjaydotpro Nov 16, 2026
42c2dfb
Fit a paste to the line it lands on
sanjaydotpro Nov 16, 2026
a743793
Keep a pasted picture's place while it downloads
sanjaydotpro Nov 16, 2026
26a7504
Paste rich content into notes as one edit
sanjaydotpro Nov 16, 2026
b63a343
Read every clipboard representation in one call on macOS
sanjaydotpro Nov 16, 2026
ab56c9f
Read every clipboard representation in one call on Windows
sanjaydotpro Nov 16, 2026
cc76e0d
Test reading a clipboard snapshot from the channel
sanjaydotpro Nov 16, 2026
b2be735
Read every clipboard representation in one call on iOS
sanjaydotpro Nov 16, 2026
2ee0d25
Read the primary clip in one call on Android
sanjaydotpro Nov 16, 2026
a5e27a4
Read VS Code's data from Chromium's custom data on macOS
sanjaydotpro Nov 16, 2026
c2835d5
Read every macOS paste fixture through the native clipboard
sanjaydotpro Nov 16, 2026
db0d10d
Add macOS clipboard snapshots for the paste fixtures
sanjaydotpro Nov 16, 2026
91d0bb1
Let paste fixtures carry their macOS snapshot
sanjaydotpro Nov 16, 2026
ded1d21
Read RTFD pictures that a Cocoa app's own HTML shows
sanjaydotpro Nov 16, 2026
61a3246
Add the Apple Notes fixture's macOS clipboard snapshot
sanjaydotpro Nov 16, 2026
7d2593c
Read ballot-box paragraphs as to-dos
sanjaydotpro Nov 16, 2026
fe43473
Check every paste fixture against what it should paste as
sanjaydotpro Nov 16, 2026
b8e4805
Give back every picture one edit dropped
sanjaydotpro Nov 16, 2026
983d6bd
Keep the lines around a pasted markdown picture tidy
sanjaydotpro Nov 16, 2026
f8ffbc4
Test the paste reader, writers, TeX and picture downloads
sanjaydotpro Nov 16, 2026
8e0cd6e
Write stacked conditions under a sum as a substack
sanjaydotpro Nov 16, 2026
815a3b6
Read pastes over 16 KB off the UI isolate
sanjaydotpro Nov 16, 2026
de3e5e9
Test rich and web-picture pastes through the editor
sanjaydotpro Nov 16, 2026
323a31b
Pin down that a pasted picture's address never syncs
sanjaydotpro Nov 16, 2026
b6d6279
Offer the link of a pasted picture that would not load
sanjaydotpro Nov 16, 2026
6c9e0a7
Write KaTeX's non-breaking spaces in text as spaces
sanjaydotpro Nov 16, 2026
0783491
Read picture sizes given in rem, em and pt
sanjaydotpro Nov 16, 2026
af9f700
Leave avatars out of a paste
sanjaydotpro Nov 16, 2026
354f4ea
Read - and -- under words as typing, and escapes as plain characters
sanjaydotpro Nov 16, 2026
5eb2786
Type markdown shortcuts the way Notion does
sanjaydotpro Nov 16, 2026
920eeca
Write paste blocks out as HTML for documents and mail
sanjaydotpro Nov 16, 2026
28e3fd6
Render and convert a note's text the way its editor reads it
sanjaydotpro Nov 16, 2026
a59fd3f
Carry a whole selection in Kapy Notes' own clipboard type
sanjaydotpro Nov 16, 2026
6c3cecc
Copy, cut and paste every selection through the rich clipboard
sanjaydotpro Nov 16, 2026
6b1f582
Let go of the clipboard before converting a pasted bitmap
sanjaydotpro Nov 16, 2026
8441aa4
Re-render the shortcuts golden for Paste as plain text
sanjaydotpro Nov 17, 2026
538ea1d
Paste and copy as before in a note without markdown
sanjaydotpro Nov 17, 2026
a0df289
Keep pasted lists tight unless the source kept them apart
sanjaydotpro Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import android.content.Context
import android.net.Uri
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.ByteArrayOutputStream
import java.io.File
import kotlin.text.Charsets.UTF_8

/** Publishes one selection as text, HTML, and a native image at the same time. */
object RichClipboard {
private const val channelName = "kapynotes/rich_clipboard"
private const val MAX_IMAGE_BYTES = 25L * 1024 * 1024

fun register(engine: FlutterEngine, context: Context) {
val appContext = context.applicationContext
Expand All @@ -29,6 +31,14 @@ object RichClipboard {
}
}

"read" -> {
try {
result.success(read(appContext))
} catch (error: Exception) {
result.error("clipboard_read", error.message, null)
}
}

"readHtml" -> {
try {
result.success(readHtml(appContext))
Expand Down Expand Up @@ -103,6 +113,59 @@ object RichClipboard {
}
}

/**
* Everything the primary clip offers a paste, in the shape
* `ClipboardSnapshot.fromChannel` reads: the first item's HTML and text,
* and its content URI's bytes when that URI is a picture.
*/
private fun read(context: Context): Map<String, Any> {
val manager = context.getSystemService(ClipboardManager::class.java)
val clip = manager.primaryClip ?: return emptyMap()
val description = clip.description
val snapshot = mutableMapOf<String, Any>(
"types" to List(description.mimeTypeCount) { description.getMimeType(it) },
)
if (clip.itemCount == 0) return snapshot
val item = clip.getItemAt(0)
val uri = item.uri
val image = uri
?.let { runCatching { context.contentResolver.getType(it) }.getOrNull() }
?.takeIf { it.startsWith("image/") }
val html = item.htmlText
?: uri?.let { ClipboardImageProvider.htmlFileFor(context, it) }
?.takeIf(File::isFile)
?.readText(UTF_8)
html?.let { snapshot["html"] = it }
val text = if (image == null) item.coerceToText(context) else item.text
text?.toString()?.takeIf { it.isNotEmpty() }?.let { snapshot["text"] = it }
if (uri != null && image != null) {
readCapped(context, uri)?.let {
snapshot["image"] = it
snapshot["imageMime"] = image
}
}
return snapshot
}

/** The bytes behind [uri], or null when it can't be read or is too large to paste. */
private fun readCapped(context: Context, uri: Uri): ByteArray? = try {
context.contentResolver.openInputStream(uri)?.use { input ->
val output = ByteArrayOutputStream()
val buffer = ByteArray(64 * 1024)
var total = 0L
while (true) {
val read = input.read(buffer)
if (read < 0) break
total += read
if (total > MAX_IMAGE_BYTES) return@use null
output.write(buffer, 0, read)
}
output.toByteArray().takeIf { it.isNotEmpty() }
}
} catch (error: Exception) {
null
}

private fun readHtml(context: Context): String? {
val manager = context.getSystemService(ClipboardManager::class.java)
val clip = manager.primaryClip ?: return null
Expand Down
4 changes: 4 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
A1B2C0D000000000000000D4 /* QuickActionsWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C0D000000000000000D3 /* QuickActionsWidget.swift */; };
A1B2C0D000000000000000A5 /* WriteNoteWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A1B2C0D000000000000000A1 /* WriteNoteWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
C1A0B0F20000000000000002 /* RichClipboardTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A0B0F20000000000000001 /* RichClipboardTests.swift */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; };
Expand Down Expand Up @@ -75,6 +76,7 @@
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
C1A0B0F20000000000000001 /* RichClipboardTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RichClipboardTests.swift; sourceTree = "<group>"; };
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -127,6 +129,7 @@
isa = PBXGroup;
children = (
331C807B294A618700263BE5 /* RunnerTests.swift */,
C1A0B0F20000000000000001 /* RichClipboardTests.swift */,
);
path = RunnerTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -392,6 +395,7 @@
buildActionMask = 2147483647;
files = (
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */,
C1A0B0F20000000000000002 /* RichClipboardTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading
Loading