Merge fix/647

This commit is contained in:
bflatastic committed 2026-10-17 15:11:24 +07:00
commit 58923a22e8
2 files changed
+25

No files matched your search

+23
View File
@@ -62,3 +62,26 @@ fn html_that_only_mentions_the_marker_pastes_its_text() {
assert_eq!(pasted_text(&app), text);
assert!(app.ui.last_error.is_none(), "{:?}", app.ui.last_error);
}
/// A clipboard whose contents the test replaces between pastes.
struct SharedClip(std::rc::Rc<std::cell::RefCell<Clip>>);
impl Services for SharedClip {
fn clipboard_get_html(&mut self) -> Option<String> {
Some(self.0.borrow().html.clone())
}
fn clipboard_get_text(&mut self) -> Option<String> {
self.0.borrow().text.clone()
}
}
#[test]
fn text_copied_after_a_design_paste_pastes_as_text() {
let clip = std::rc::Rc::new(std::cell::RefCell::new(Clip { html: copied_html(), text: None }));
let mut app = FigApp::new(Session::new(), Box::new(SharedClip(clip.clone())));
crate::menus::paste(&mut app, None);
assert_eq!(selected_names(&app), ["Copied layer"]);
*clip.borrow_mut() = Clip { html: String::new(), text: Some("Fresh text".into()) };
crate::menus::paste(&mut app, None);
assert_eq!(pasted_text(&app), "Fresh text");
}
+2
View File
@@ -38,6 +38,8 @@ pub fn paste(app: &mut FigApp, event_text: Option<&str>) {
// Only HTML that holds readable design data takes this path; other HTML pastes as before.
if let Some(html) = app.services.clipboard_get_html().filter(|h| figcraft_engine::cmd::edit::design_clipboard_buffer(h).is_some()) {
if let Some(r) = app.run("edit.pasteDesignLayers", json!({"html": html})) {
// The pasted layers are now our copy: text another app puts on the clipboard later is newer.
app.ui.last_copy = Some(app.services.clipboard_get_text().unwrap_or_default());
let left_out = r["warnings"].as_array().map_or(0, Vec::len);
if left_out > 0 {
app.toast(trn("Pasted design layers; {n} kinds of content were left out", left_out, &[]));