ElyMark: R4.10 round 3 fixes; R4.10 marked [~]
The copy guard also compares the clipboard's HTML, which gpui omits, so a later rich copy with the same plain text is not overwritten. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2c374b23ed
commit
65514599fe
6 files changed
+49
-4
No files matched your search
@@ -204,6 +204,32 @@ fn a_later_editor_copy_outlives_a_pending_conversion(cx: &mut TestAppContext) {
|
||||
assert_eq!(clipboard(cx).as_deref(), Some("alpha"));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_later_rich_copy_with_the_same_text_outlives_a_pending_conversion(cx: &mut TestAppContext) {
|
||||
use ely_platform::clipboard::{self, Clip};
|
||||
if std::env::var_os("ELY_CLIPBOARD_TEST").is_none() {
|
||||
eprintln!("SKIP: set ELY_CLIPBOARD_TEST=1; this replaces the clipboard");
|
||||
return;
|
||||
}
|
||||
let rich = |html: &str| Clip::Html {
|
||||
html: html.into(),
|
||||
text: "x".into(),
|
||||
};
|
||||
let (_desk, cx, _files) = opened("alpha *it*\n", cx);
|
||||
clipboard::write(&rich("<b>x</b>")).expect("writes");
|
||||
cx.write_to_clipboard(gpui::ClipboardItem::new_string("x".into()));
|
||||
cx.update(|window, cx| window.dispatch_action(Box::new(crate::export::CopyHtml), cx));
|
||||
clipboard::write(&rich("<i>x</i>")).expect("writes");
|
||||
cx.run_until_parked();
|
||||
let html = clipboard::html().expect("reads");
|
||||
assert_eq!(
|
||||
clipboard(cx).as_deref(),
|
||||
Some("x"),
|
||||
"the conversion is dropped"
|
||||
);
|
||||
assert!(html.is_some_and(|html| html.contains("<i>x</i>")));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_shut_menu_stays_shut_when_its_tab_returns(cx: &mut TestAppContext) {
|
||||
let (desk, cx, files) = opened("alpha\n", cx);
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Desk {
|
||||
let Some((markdown, beside)) = self.copied_text(cx) else {
|
||||
return;
|
||||
};
|
||||
let before = cx.read_from_clipboard();
|
||||
let before = witness(cx);
|
||||
self.copying = Some(cx.spawn(async move |desk, cx| {
|
||||
let converted = cx
|
||||
.background_executor()
|
||||
@@ -73,7 +73,7 @@ impl Desk {
|
||||
let landed = desk.update(cx, |desk, cx| {
|
||||
desk.copying = None;
|
||||
// A later copy, here or elsewhere, wins.
|
||||
if cx.read_from_clipboard() != before {
|
||||
if witness(cx) != before {
|
||||
return log::info!("mark: the clipboard changed first; a copy is dropped");
|
||||
}
|
||||
desk.copied(converted, cx);
|
||||
@@ -108,6 +108,15 @@ impl Desk {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the clipboard holds, its HTML included.
|
||||
fn witness(cx: &mut Context<Desk>) -> (Option<ClipboardItem>, Result<Option<String>, String>) {
|
||||
let html = clipboard::html().map_err(|error| {
|
||||
log::warn!("mark: the clipboard's HTML did not read: {error:#}");
|
||||
format!("{error:#}")
|
||||
});
|
||||
(cx.read_from_clipboard(), html)
|
||||
}
|
||||
|
||||
/// The copy as `kind`, converted off the window thread.
|
||||
fn convert(kind: As, markdown: String, beside: Option<PathBuf>) -> std::io::Result<Copied> {
|
||||
let beside = beside.as_deref();
|
||||
|
||||
Reference in new issue
Block a user