From 3859c084d0513dabba5b63a7fdf58be76a029711 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 22:33:27 -0800 Subject: [PATCH 1/2] Clipboard: Paste keeps a Copy or Cut whose system clipboard write failed When another app held the system clipboard open or refused the write, Cut removed the art and kept it in the internal clipboard, but every Paste command then read the older contents that the other app had left on the system clipboard, and pasted those contents instead of the cut art. A failed Copy had the same fault. A failed write is now recorded whether or not the copied formats have text. Until another app copies something, every Paste command takes the internal clipboard, and a paste into type or a text field takes the copy's text, or nothing when the formats have no text. On macOS the clipboard service now reports the pasteboard's change count, so a later copy is noticed whatever the clipboard holds. Linux and the BSDs have no change count: there a later copy is noticed only when it changes the clipboard's text, so a failed write is kept only while the clipboard held text at the failure. The new tests run a failed Copy or Cut through the six Paste commands and a paste into type, with the clipboard locked or the write refused, with and without a change count, with On Copy: Include SVG Code off so that the formats have no text, and over a picture another app copied. --- apps/vectorcraft/src/clipboard.rs | 13 ++++ crates/ui-egui/src/sysclip.rs | 79 ++++++++++++++++------- crates/ui-egui/src/tests/clipboard.rs | 48 ++++++++++++++ crates/ui-egui/src/tests/sysclip.rs | 93 +++++++++++++++++++++++++++ docs/control-protocol.md | 4 +- docs/mcp.md | 7 +- 6 files changed, 218 insertions(+), 26 deletions(-) diff --git a/apps/vectorcraft/src/clipboard.rs b/apps/vectorcraft/src/clipboard.rs index 3568b4683e..a6b60a818c 100644 --- a/apps/vectorcraft/src/clipboard.rs +++ b/apps/vectorcraft/src/clipboard.rs @@ -1513,6 +1513,13 @@ mod portable { } } + /// On macOS the pasteboard's change count ([`super::mac::change_count`]); the other + /// platforms this module serves have none. + #[cfg(target_os = "macos")] + fn change_count(&mut self) -> Option { + super::mac::change_count() + } + fn read(&mut self, mimes: &[&'static str]) -> Option { self.read_now_or_later(mimes)?.flavour() } @@ -3227,6 +3234,12 @@ mod mac { }) } + /// The pasteboard's change count, which goes up each time the pasteboard's ownership changes, + /// as when an app clears it to copy something. + pub fn change_count() -> Option { + autoreleasepool(|_| u64::try_from(NSPasteboard::generalPasteboard().changeCount()).ok()) + } + /// The pasteboard's data for `mime`, the first of its types held ([`pasteboard_types`]) that is /// not empty and at most [`MAX_BYTES`]: its length is checked before it is copied, and a larger /// type is skipped and the next tried. diff --git a/crates/ui-egui/src/sysclip.rs b/crates/ui-egui/src/sysclip.rs index eb5a258e12..6b8a019223 100644 --- a/crates/ui-egui/src/sysclip.rs +++ b/crates/ui-egui/src/sysclip.rs @@ -101,8 +101,8 @@ pub(crate) struct Publishing { /// The latest one's formats wait to be written. pending: bool, /// The latest one's formats could not be written: what the system clipboard held when the - /// write failed, and the text of those formats. - unwritten: Option<(Held, String)>, + /// write failed, and the text of those formats, if they have text. + unwritten: Option<(Held, Option)>, /// The status bar's message when the latest one ran, with [`crate::state::UiState::status_sets`] /// then. Its formats' notes replace the message only while the status bar still shows it and /// nothing has set the status since. @@ -136,6 +136,12 @@ impl Publishing { fn shows_status(&self, ui: &crate::state::UiState) -> bool { ui.status == self.status.0 && ui.status_sets == self.status.1 } + + /// Is the latest Copy or Cut one whose formats could not be written to `cb`, with nothing + /// copied since ([`VectorcraftApp::holds_unwritten_copy`])? + fn holds_unwritten(&self, cb: &mut (dyn SystemClipboard + 'static)) -> bool { + self.unwritten.as_ref().is_some_and(|(held, _)| Held::now(cb) == *held) + } } /// The status bar's line after a Copy (or with `cut`, a Cut) whose formats have `n` notes, the @@ -199,15 +205,34 @@ impl VectorcraftApp { || self.services.system_clipboard.as_mut().is_none_or(|cb| cb.holds_ours()) } + /// Is the latest Copy or Cut one whose formats could not be written to the system clipboard, + /// with nothing copied since? Paste then takes the internal clipboard, and a paste into type or + /// a text field takes that copy's text (nothing when its formats have no text), until another + /// app copies something. Where the platform + /// has no change count (Linux and the BSDs), a copy is noticed only when it changes the + /// clipboard's text, so the copy is kept only when the clipboard held text when the write + /// failed. When it held only a picture, or nothing that could be read, Paste takes what the + /// clipboard holds. + fn holds_unwritten_copy(&mut self) -> bool { + let Some(cb) = self.services.system_clipboard.as_deref_mut() else { return false }; + self.clipboard_publishing.holds_unwritten(cb) + } + /// The text of the latest Copy or Cut whose formats could not be written to the system - /// clipboard, while nothing has been copied since that Copy or Cut. A paste into type or a text - /// field takes this text until another app copies something. Where the platform has no change - /// count, a copy is noticed only when it changes the clipboard's text, so the copy is kept only - /// when the clipboard held text when the write failed. + /// clipboard, while nothing has been copied since that Copy or Cut + /// ([`Self::holds_unwritten_copy`]). pub(crate) fn unwritten_clipboard_text(&mut self) -> Option { - let cb = self.services.system_clipboard.as_deref_mut()?; - let (held, text) = self.clipboard_publishing.unwritten.as_ref()?; - (Held::now(cb) == *held).then(|| text.clone()) + self.clipboard_publishing.unwritten.as_ref()?.1.as_ref()?; + self.unwritten_copy().flatten() + } + + /// While [`Self::holds_unwritten_copy`]: the text of that copy's formats, `None` inside when + /// they have no text. + fn unwritten_copy(&mut self) -> Option> { + if !self.holds_unwritten_copy() { + return None; + } + self.clipboard_publishing.unwritten.as_ref().map(|(_, text)| text.clone()) } /// After Copy or Cut: offer the copied objects to other apps. With the system clipboard @@ -273,8 +298,8 @@ impl VectorcraftApp { let current = before.as_ref() == Some(&before_write); if let Err(e) = cb.write(&f) { // Another app may hold the clipboard open. It keeps what it held (or what the - // failed write left), and a paste into text takes this copy's text until - // something else is copied. + // failed write left). Until something else is copied, Paste takes this copy, + // and a paste into text takes its text. let held = Held::now(cb.as_mut()); let text = f.iter().find(|t| t.mime == TEXT).map(|t| String::from_utf8_lossy(&t.data).into_owned()); // A change during the write is the failed write emptying the clipboard and @@ -289,7 +314,7 @@ impl VectorcraftApp { // Without a change count, a clipboard with no text can't show a later copy of // a picture, or tell an empty clipboard from one that couldn't be read. let trackable = held != Held::Text(None); - app.clipboard_publishing.unwritten = text.filter(|_| current && left_by_write && trackable).map(|text| (held, text)); + app.clipboard_publishing.unwritten = (current && left_by_write && trackable).then_some((held, text)); return Err(e); } Ok(warnings) @@ -377,17 +402,20 @@ impl VectorcraftApp { let waited = ctx.data(|d| d.get_temp::(egui::Id::unique("clipboard.pending-at-tick"))).unwrap_or(false); ctx.data_mut(|d| d.remove::(egui::Id::unique("clipboard.pending-at-tick"))); if !(self.clipboard_publishing.pending || waited) { - // A copy whose formats could not be written: a paste takes its text, not the text the - // clipboard kept ([`Self::unwritten_clipboard_text`]). + // A copy whose formats could not be written: a paste takes its text, or nothing when + // they have none, not the text the clipboard kept ([`Self::unwritten_copy`]). let pasting = textless || ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Paste(_)))); - if pasting && let Some(text) = self.unwritten_clipboard_text() { + if pasting && let Some(text) = self.unwritten_copy() { ctx.input_mut(|i| { - for e in &mut i.events { - if let egui::Event::Paste(t) = e { - t.clone_from(&text); + i.events.retain_mut(|e| match (e, &text) { + (egui::Event::Paste(t), Some(text)) => { + t.clone_from(text); + true } - } - if textless { + (egui::Event::Paste(_), None) => false, + _ => true, + }); + if textless && let Some(text) = text { i.events.insert(0, egui::Event::Paste(text)); } }); @@ -452,7 +480,10 @@ impl VectorcraftApp { // A picture or file the host read from the paste. (Some(f), _) if f.mime != TEXT => import_command(&f, center), (_, Some(cb)) => { - if self.clipboard_publishing.pending || cb.holds_ours() { + // After a Copy or Cut whose formats could not be written, with nothing copied + // since, what the clipboard still holds is older than the internal clipboard. + let publishing = &self.clipboard_publishing; + if publishing.pending || publishing.holds_unwritten(cb.as_mut()) || cb.holds_ours() { return Ok(None); } let mut read = |mimes: &[&'static str]| if defer { cb.read_deferred(mimes) } else { cb.read(mimes).map(ClipboardRead::Now) }; @@ -520,12 +551,12 @@ impl VectorcraftApp { } /// The text on the system clipboard once the formats a Copy or Cut is making are written, for a - /// paste into a text field or type. When they could not be written, their text - /// ([`Self::unwritten_clipboard_text`]). + /// paste into a text field or type. When they could not be written, their text, or `None` when + /// they have none ([`Self::unwritten_copy`]). pub(crate) fn written_clipboard_text(&mut self) -> Option { // Only other copies' formats are ahead of them on the worker ([`Self::publish_clipboard`]). background::wait_until(self, |app| !app.clipboard_publishing.pending); - self.unwritten_clipboard_text().or_else(|| self.system_clipboard_text()) + self.unwritten_copy().unwrap_or_else(|| self.system_clipboard_text()) } /// The text on the system clipboard, if any. diff --git a/crates/ui-egui/src/tests/clipboard.rs b/crates/ui-egui/src/tests/clipboard.rs index 1892df67be..1c037b0f41 100644 --- a/crates/ui-egui/src/tests/clipboard.rs +++ b/crates/ui-egui/src/tests/clipboard.rs @@ -396,6 +396,54 @@ fn type_paste_without_a_change_count_drops_a_refused_copy_it_cannot_track() { assert_eq!(paste_at(&mut app, 5), "Own: "); } +/// After a Copy whose formats have no text (On Copy: Include SVG Code off) and could not be +/// written, a paste into type takes nothing, from the menu or a paste event, not the text another +/// app left on the clipboard. A later copy in another app still pastes. +#[test] +fn a_paste_into_type_after_a_refused_textless_copy_takes_nothing() { + use vectorcraft_engine::cmd::clipboard::TEXT; + let _guard = TEST_CLIP_LOCK.lock().unwrap(); + for uncounted in [false, true] { + let (mut app, board) = super::sysclip::app(); + if uncounted { + super::sysclip::without_change_count(&board); + } + run(&mut app, "prefs.set", json!({"key": "copyAsSvg", "value": false})); + let rect = run(&mut app, "shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 20}))["id"].clone(); + run(&mut app, "select.set", json!({"ids": [rect]})); + super::sysclip::copy_elsewhere(&board, vec![(TEXT, b"Old".to_vec())]); + super::sysclip::refuse_writes(&board, true); + run(&mut app, "edit.copy", json!({})); + crate::background::wait_all(&mut app); + super::sysclip::refuse_writes(&board, false); + + let destination = + run(&mut app, "text.create", json!({"x": 20, "y": 60, "text": "Own: ", "size": 12, "color": "#000000"}))["id"].as_u64().unwrap(); + let v = app.view_info(); + let text = |app: &VectorcraftApp| { + let node = app.session.doc().unwrap().doc.node(NodeId(destination)).unwrap(); + let vectorcraft_doc::NodeKind::Text(t) = &node.kind else { panic!() }; + t.plain_text() + }; + let place = |app: &mut VectorcraftApp| { + app.session.select_tool("selection", v).unwrap(); + app.session.select_tool("type", v).unwrap(); + app.session.set_tool_option("textSelection", &json!({"id": destination, "start": 5, "end": 5})); + }; + place(&mut app); + crate::panels::character::intercept_text_command(&mut app, "edit.paste"); + assert_eq!(text(&app), "Own: ", "uncounted {uncounted}: the menu's Paste"); + place(&mut app); + super::sysclip::frame(&mut app, vec![egui::Event::Paste("Old".into())]); + assert_eq!(text(&app), "Own: ", "uncounted {uncounted}: a paste event"); + + super::sysclip::copy_elsewhere(&board, vec![(TEXT, b"New".to_vec())]); + place(&mut app); + crate::panels::character::intercept_text_command(&mut app, "edit.paste"); + assert_eq!(text(&app), "Own: New", "uncounted {uncounted}: the later copy"); + } +} + #[test] fn a_paste_event_waiting_on_a_refused_copy_pastes_that_copy() { let _guard = TEST_CLIP_LOCK.lock().unwrap(); diff --git a/crates/ui-egui/src/tests/sysclip.rs b/crates/ui-egui/src/tests/sysclip.rs index 6ae55087b8..d857f5be93 100644 --- a/crates/ui-egui/src/tests/sysclip.rs +++ b/crates/ui-egui/src/tests/sysclip.rs @@ -359,6 +359,99 @@ fn our_own_copy_pastes_the_lossless_internal_clipboard() { assert!(matches!(pasted(&app)[0].kind, NodeKind::Path { .. })); } +/// SVG markup of three closed paths, a group of two more and a compound path with a hole: five +/// objects. +fn closed_paths_svg() -> String { + let mut svg = String::from(r#""#); + for x in [10, 20, 30] { + svg.push_str(&format!(r##""##)); + } + svg.push_str(r#""#); + svg.push_str(r#""#); + svg +} + +/// Paste the objects of [`closed_paths_svg`] from another app and select them all → their count. +fn paste_closed_paths(app: &mut VectorcraftApp, board: &Rc>) -> usize { + copy_elsewhere(board, vec![(SVG, closed_paths_svg().into_bytes())]); + run(app, "edit.paste", json!({})); + run(app, "select.all", json!({})); + let objects = count(app); + assert_eq!(app.session.active().unwrap().selection.objects.len(), objects); + objects +} + +/// A Copy or Cut whose formats can't be written to the system clipboard (another app holds it +/// open, or refuses the write) stays what every Paste command takes while nothing else is copied, +/// with and without a change count, and when its formats have no text; the clipboard's older +/// contents do not replace it, and a paste into text takes the copy's text, or nothing. A later +/// copy in another app still wins. Without a change count, a clipboard that held only a picture +/// can't show a later copy, so there Paste takes the picture. +#[test] +fn a_copy_the_system_clipboard_refused_still_pastes_the_copied_art() { + type Fail = fn(&Rc>, bool); + // Case, Copy or Cut, how the write fails, no change count, On Copy: Include SVG Code, the + // other app's copy before it is a picture, Paste takes the copied art. + let cases: [(&str, &str, Fail, bool, bool, bool, bool); 8] = [ + ("locked", "edit.cut", lock, false, true, false, true), + ("refused", "edit.cut", refuse_writes, false, true, false, true), + ("refused, uncounted", "edit.cut", refuse_writes, true, true, false, true), + ("refused, no text", "edit.cut", refuse_writes, false, false, false, true), + ("refused, uncounted, no text", "edit.cut", refuse_writes, true, false, false, true), + ("refused copy", "edit.copy", refuse_writes, false, true, false, true), + ("refused, over a picture", "edit.cut", refuse_writes, false, true, true, true), + ("refused, uncounted, over a picture", "edit.cut", refuse_writes, true, true, true, false), + ]; + let pastes = + ["edit.paste", "edit.pasteInFront", "edit.pasteInBack", "edit.pasteInPlace", "edit.pasteOnAllArtboards", "edit.pasteWithoutFormatting"]; + for (case, op, fail, uncounted, svg_text, over_picture, kept) in cases { + let (mut app, board) = app(); + if uncounted { + without_change_count(&board); + } + run(&mut app, "prefs.set", json!({"key": "copyAsSvg", "value": svg_text})); + let objects = paste_closed_paths(&mut app, &board); + if over_picture { + copy_elsewhere(&board, vec![(PNG, blue_png())]); + } else { + copy_elsewhere(&board, vec![(TEXT, b"Words another app copied".to_vec())]); + } + fail(&board, true); + run(&mut app, op, json!({})); + background::wait_all(&mut app); + fail(&board, false); + assert!(app.ui.status.starts_with("Couldn't copy to the system clipboard"), "{case}: {}", app.ui.status); + let left = if op == "edit.cut" { 0 } else { objects }; + assert_eq!(count(&app), left, "{case}"); + if !kept { + run(&mut app, "edit.paste", json!({})); + assert!(matches!(pasted(&app)[0].kind, NodeKind::Image { .. }), "{case}: the picture"); + continue; + } + let text = app.written_clipboard_text(); + assert_eq!(text.is_some(), svg_text, "{case}: a paste into text takes the copy's text, or nothing: {text:?}"); + assert!(text.is_none_or(|t| t.contains(" Date: Sun, 22 Nov 2026 12:54:43 -0800 Subject: [PATCH 2/2] Clipboard: a failed copy stays replaced, and the menu's Paste into a field takes nothing Without a change count, a Copy or Cut whose formats could not be written was kept for as long as the clipboard held the same text as at the failure. When another app copied other text and later put the older text back, Paste took the copied art again. The record of the failed write is now dropped once a different change count, or different readable text, is seen on the clipboard. The Edit menu's Paste into a focused text field, after a failed Copy whose formats have no text, found no text and fell through to the canvas Paste, which pasted the copied art. The field now gets an empty paste and takes nothing. --- crates/ui-egui/src/menus/invoke.rs | 2 +- crates/ui-egui/src/sysclip.rs | 31 +++++++++++++-- crates/ui-egui/src/tests/sysclip.rs | 58 +++++++++++++++++++++++++++++ docs/mcp.md | 4 +- 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 7186f0707d..8bb9fcbe4e 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -112,7 +112,7 @@ pub(super) fn field_event(app: &mut VectorcraftApp, id: &str) -> Option egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND }, "edit.copy" => egui::Event::Copy, "edit.cut" => egui::Event::Cut, - "edit.paste" | "edit.pasteWithoutFormatting" => egui::Event::Paste(app.written_clipboard_text()?), + "edit.paste" | "edit.pasteWithoutFormatting" => egui::Event::Paste(app.field_paste_text()?), _ => return None, }) } diff --git a/crates/ui-egui/src/sysclip.rs b/crates/ui-egui/src/sysclip.rs index 6b8a019223..f841721c99 100644 --- a/crates/ui-egui/src/sysclip.rs +++ b/crates/ui-egui/src/sysclip.rs @@ -138,9 +138,20 @@ impl Publishing { } /// Is the latest Copy or Cut one whose formats could not be written to `cb`, with nothing - /// copied since ([`VectorcraftApp::holds_unwritten_copy`])? - fn holds_unwritten(&self, cb: &mut (dyn SystemClipboard + 'static)) -> bool { - self.unwritten.as_ref().is_some_and(|(held, _)| Held::now(cb) == *held) + /// copied since ([`VectorcraftApp::holds_unwritten_copy`])? A different change count, or + /// different text read from `cb`, shows a later copy: the record of the failed write is then + /// dropped, so the clipboard holding the older text again later does not bring it back. Text + /// that could not be read keeps the record. + fn holds_unwritten(&mut self, cb: &mut (dyn SystemClipboard + 'static)) -> bool { + let Some((held, _)) = &self.unwritten else { return false }; + let now = Held::now(cb); + if now == *held { + return true; + } + if now != Held::Text(None) { + self.unwritten = None; + } + false } } @@ -482,7 +493,7 @@ impl VectorcraftApp { (_, Some(cb)) => { // After a Copy or Cut whose formats could not be written, with nothing copied // since, what the clipboard still holds is older than the internal clipboard. - let publishing = &self.clipboard_publishing; + let publishing = &mut self.clipboard_publishing; if publishing.pending || publishing.holds_unwritten(cb.as_mut()) || cb.holds_ours() { return Ok(None); } @@ -559,6 +570,18 @@ impl VectorcraftApp { self.unwritten_copy().unwrap_or_else(|| self.system_clipboard_text()) } + /// The text a paste from the Edit menu gives a focused text field ([`Self::written_clipboard_text`]): + /// empty when the formats of a Copy or Cut could not be written and have no text, so the field + /// takes nothing and the art is not pasted onto the canvas. `None` when the system clipboard + /// holds no text. + pub(crate) fn field_paste_text(&mut self) -> Option { + background::wait_until(self, |app| !app.clipboard_publishing.pending); + match self.unwritten_copy() { + Some(text) => Some(text.unwrap_or_default()), + None => self.system_clipboard_text(), + } + } + /// The text on the system clipboard, if any. pub(crate) fn system_clipboard_text(&mut self) -> Option { match self.services.system_clipboard.as_mut() { diff --git a/crates/ui-egui/src/tests/sysclip.rs b/crates/ui-egui/src/tests/sysclip.rs index d857f5be93..412f8264ac 100644 --- a/crates/ui-egui/src/tests/sysclip.rs +++ b/crates/ui-egui/src/tests/sysclip.rs @@ -720,6 +720,64 @@ fn the_menus_paste_into_a_field_waits_for_the_formats() { background::wait_all(&mut app); } +/// The Edit menu's Paste into a text field after a Copy whose formats have no text (On Copy: +/// Include SVG Code off) and could not be written: the field takes nothing, not the text another +/// app left on the clipboard, and the copied art is not pasted onto the canvas. +#[test] +fn the_menus_paste_into_a_field_after_a_refused_textless_copy_takes_nothing() { + for uncounted in [false, true] { + let (mut app, board) = app(); + if uncounted { + without_change_count(&board); + } + run(&mut app, "prefs.set", json!({"key": "copyAsSvg", "value": false})); + let rect = run(&mut app, "shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 20}))["id"].clone(); + run(&mut app, "select.set", json!({"ids": [rect]})); + copy_elsewhere(&board, vec![(TEXT, b"Old".to_vec())]); + refuse_writes(&board, true); + run(&mut app, "edit.copy", json!({})); + background::wait_all(&mut app); + refuse_writes(&board, false); + let objects = count(&app); + let (ctx, id, mut field) = (egui::Context::default(), egui::Id::unique("field"), String::new()); + for paste in [false, true] { + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + if paste { + menus::invoke_from_system_menu(&mut app, ui.ctx(), "edit.paste", json!({})); + } + ui.add(egui::TextEdit::singleline(&mut field).id(id)).request_focus(); + }); + out.textures_delta.clear(); + } + assert_eq!(field, "", "uncounted {uncounted}: the field takes nothing"); + assert_eq!(count(&app), objects, "uncounted {uncounted}: nothing is pasted onto the canvas"); + } +} + +/// Without a change count, a Copy whose formats could not be written stops being what Paste takes +/// once different text is seen on the clipboard: when another app later puts the older text back, +/// Paste takes that text, not the copied art. +#[test] +fn a_refused_copy_stays_replaced_when_the_older_text_comes_back() { + let (mut app, board) = app(); + without_change_count(&board); + let rect = run(&mut app, "shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 20}))["id"].clone(); + run(&mut app, "select.set", json!({"ids": [rect]})); + copy_elsewhere(&board, vec![(TEXT, b"Old".to_vec())]); + refuse_writes(&board, true); + run(&mut app, "edit.copy", json!({})); + background::wait_all(&mut app); + refuse_writes(&board, false); + + copy_elsewhere(&board, vec![(TEXT, b"New".to_vec())]); + assert_eq!(app.written_clipboard_text().as_deref(), Some("New")); + copy_elsewhere(&board, vec![(TEXT, b"Old".to_vec())]); + assert_eq!(app.written_clipboard_text().as_deref(), Some("Old"), "a paste into text"); + run(&mut app, "edit.paste", json!({})); + let NodeKind::Text(t) = &pasted(&app)[0].kind else { panic!("the copied art, not the clipboard's text") }; + assert_eq!(t.plain_text(), "Old"); +} + /// A paste chord into type being edited, before the formats are written: the formats are written /// first, and the paste pastes their text whether the host read another app's text for it or found /// no text, also when the chord's key comes up a frame after they were written; with no text in diff --git a/docs/mcp.md b/docs/mcp.md index 0825fc6fd2..763241086f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9863,8 +9863,8 @@ or refused the write), every Paste takes the internal clipboard until another ap into a text field or type takes the copy's text, or nothing when the formats have no text. Windows and macOS notice that copy by the clipboard's change count. Linux and the BSDs notice it only when it changes the clipboard's text, so there Paste reads the system clipboard when it held only a picture, or nothing that could be read, at the failed -write. While a text field or the Type tool has the keyboard, the app waits for -them. Windows carries every format both ways and pastes a bitmap from PNG, else +write. Once a paste there has read the changed text, the older text coming back does not restore the copy. While a +text field or the Type tool has the keyboard, the app waits for them. Windows carries every format both ways and pastes a bitmap from PNG, else from the device-independent bitmap screenshots copy (`CF_DIBV5`, then `CF_DIB`; alpha kept, opaque when it is zero throughout, at most 32768 px a side); macOS and Linux carry one format (the text, else the PNG) and paste text and bitmaps (macOS the pasteboard's PNG, else TIFF, as screenshots copy them). A Paste from the menus or the keys decodes