mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-21 19:04:56 +01:00
fix: make editor context-menu paste match keyboard paste on Linux
On Linux, the context-menu Paste used its own navigator.clipboard.readText() flow. On WebKitGTK it lost text copied from other applications. When a web image copy also carried text, it pasted the URL instead of the bitmap. It also skipped ProseMirror's paste handling, so things like callout paste and the pasted-HTML style cleanup never ran. The context menu now reads the clipboard with navigator.clipboard.read(), classifies each format, and replays the result as a paste event on the editor DOM. That runs the same path as Ctrl/Cmd+V: ProseMirror's paste handler, every handlePaste prop (file, callout, link), transformPastedHTML, the clipboard parsers and TipTap's paste rules. Only real attachments (image/*, application/pdf) become files. Other text formats such as text/uri-list stay text, and browser/OS metadata formats are ignored, so a copied link no longer becomes a pasted-0.uri-list attachment. A link offered only as a URI list pastes as its first URI. When the web clipboard is unavailable (WebKitGTK bug #218519), Paste falls back to native arboard reads: the image first, then text through the new read_clipboard_text command. The text is replayed through the same paste path. Every await re-checks the editor origin, as upstream's paste code does. The classification lives in src/lib/utils/clipboard-paste.ts and has regression tests. Closes #259
This commit is contained in:
1 parent
add45ad9dd
commit
ec479ced8e
6 files changed
+257
-16
No files matched your search
@@ -2029,6 +2029,30 @@ pub fn copy_text_to_clipboard(_text: String) -> Result<(), String> {
|
||||
Err("Text clipboard copy is only supported on desktop".to_string())
|
||||
}
|
||||
|
||||
/// Read text from the system clipboard through the native backend.
|
||||
/// Works around the WebKitGTK clipboard bug where the async `navigator.clipboard`
|
||||
/// API returns empty for text copied from external applications.
|
||||
#[cfg(desktop)]
|
||||
#[tauri::command]
|
||||
pub async fn read_clipboard_text() -> Result<String, String> {
|
||||
// Reading the clipboard can block while the owning application answers, like the image read below.
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
let mut clipboard =
|
||||
arboard::Clipboard::new().map_err(|e| format!("Clipboard init failed: {}", e))?;
|
||||
clipboard
|
||||
.get_text()
|
||||
.map_err(|e| format!("Failed to read text from clipboard: {}", e))
|
||||
})
|
||||
.await
|
||||
.map_err(|error| error.to_string())?
|
||||
}
|
||||
|
||||
#[cfg(mobile)]
|
||||
#[tauri::command]
|
||||
pub async fn read_clipboard_text() -> Result<String, String> {
|
||||
Err("Text clipboard read is only supported on desktop".to_string())
|
||||
}
|
||||
|
||||
/// Read image from system clipboard (bypasses WebKitGTK clipboard bug).
|
||||
/// Returns PNG bytes as Vec<u8>, or error if no image on clipboard.
|
||||
#[cfg(desktop)]
|
||||
|
||||
@@ -212,6 +212,7 @@ pub fn run() {
|
||||
commands::load_vault_state,
|
||||
commands::save_vault_state,
|
||||
commands::copy_text_to_clipboard,
|
||||
commands::read_clipboard_text,
|
||||
commands::read_clipboard_image,
|
||||
commands::copy_image_to_clipboard,
|
||||
commands::save_image,
|
||||
|
||||
Reference in new issue
Block a user