diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 07c8955f48..bb33fd9665 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -60,6 +60,7 @@ pub fn set_rich(text: &str, html: &str, rtf: &str, mathml: &str) -> bool { set } +/// Write HTML and plain text to the system clipboard via the cached writer slot, recording ownership. fn set_html_text(html: &str, text: &str) -> bool { WRITER.with(|w| { let Ok(mut slot) = w.try_borrow_mut() else { return false }; @@ -68,7 +69,10 @@ fn set_html_text(html: &str, text: &str) -> bool { } let set = slot.as_mut().map(|c| if html.is_empty() { c.set_text(text) } else { c.set().html(html, Some(text)) }); match set { - Some(Ok(())) => true, + Some(Ok(())) => { + platform::record_own(); + true + } Some(Err(e)) => { log::warn!("clipboard: {e}"); *slot = None; @@ -79,6 +83,74 @@ fn set_html_text(html: &str, text: &str) -> bool { }) } +/// Put a copied picture on the clipboard: its pixels, with HTML and text beside it where the +/// platform takes them. `false` when it couldn't be set. +pub fn set_image(image: &wordcraft_ui_egui::system_clipboard::CopyImage, html: &str, text: &str) -> bool { + if platform::set_image(image, html, text) { + return true; + } + if !platform::can_set() { + return false; + } + let set = set_image_arboard(image); + if set { + platform::after_set_image(image, html, text); + } + set +} + +/// Write image pixels to the clipboard through arboard. +fn set_image_arboard(image: &wordcraft_ui_egui::system_clipboard::CopyImage) -> bool { + WRITER.with(|w| { + let Ok(mut slot) = w.try_borrow_mut() else { return false }; + if slot.is_none() { + *slot = open(); + } + let img = arboard::ImageData { width: image.width, height: image.height, bytes: std::borrow::Cow::Borrowed(&image.rgba) }; + let set = slot.as_mut().map(|c| c.set().image(img)); + match set { + Some(Ok(())) => { + platform::record_own(); + true + } + Some(Err(e)) => { + log::warn!("clipboard image: {e}"); + *slot = None; + false + } + None => false, + } + }) +} + +/// Whether the system clipboard still holds WordCraft's last copy. +pub fn is_own() -> bool { + platform::is_own() +} + +/// Wrap HTML in the Windows CF_HTML header format required by clipboard readers. +/// +/// Offsets are byte offsets from the start of the payload; `EndHTML` excludes the trailing NUL. +#[cfg(any(target_os = "windows", test))] +fn wrap_cf_html(ctn: &str) -> Vec { + let h_version = "Version:0.9"; + let h_start_html = "\r\nStartHTML:"; + let h_end_html = "\r\nEndHTML:"; + let h_start_frag = "\r\nStartFragment:"; + let h_end_frag = "\r\nEndFragment:"; + let c_start_frag = "\r\n\r\n\r\n\r\n"; + let c_end_frag = "\r\n\r\n\r\n\0"; + let h_len = h_version.len() + h_start_html.len() + 10 + h_end_html.len() + 10 + h_start_frag.len() + 10 + h_end_frag.len() + 10; + let n_start_html = h_len + 2; + let n_start_frag = h_len + c_start_frag.len(); + let n_end_frag = n_start_frag + ctn.len(); + let n_end_html = n_end_frag + c_end_frag.len() - 1; + let header = format!( + "{h_version}{h_start_html}{n_start_html:010}{h_end_html}{n_end_html:010}{h_start_frag}{n_start_frag:010}{h_end_frag}{n_end_frag:010}{c_start_frag}{ctn}{c_end_frag}" + ); + header.into_bytes() +} + /// The clipboard's text. pub fn text() -> Option { open()?.get_text().ok() @@ -185,6 +257,39 @@ mod platform { get_mime_types_ordered(ClipboardType::Regular, Seat::Unspecified).unwrap_or_default() } + const OWNER_MIME: &str = "application/x-wordcraft-owner"; + + /// Process-unique ownership token placed into Wayland clipboard offers. + fn owner_token() -> [u8; 16] { + static TOKEN: std::sync::OnceLock<[u8; 16]> = std::sync::OnceLock::new(); + *TOKEN.get_or_init(|| { + let mut b = [0u8; 16]; + let _ = getrandom::fill(&mut b); + b + }) + } + + static X11_OWNER: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); + + /// Record clipboard ownership for X11 selection tracking. + pub fn record_own() { + if !wayland() { + let win = x11::owner_window().unwrap_or(0); + X11_OWNER.store(win, std::sync::atomic::Ordering::Relaxed); + } + } + + /// Whether WordCraft still owns the Wayland offer or X11 selection. + pub fn is_own() -> bool { + if wayland() { + if formats().iter().any(|m| m == OWNER_MIME) { read(OWNER_MIME, 16).is_some_and(|b| b == owner_token()) } else { false } + } else { + let current = x11::owner_window().unwrap_or(0); + let recorded = X11_OWNER.load(std::sync::atomic::Ordering::Relaxed); + recorded != 0 && current == recorded + } + } + /// Whether arboard sets the clipboard natively: X11, or Wayland with data-control. pub fn can_set() -> bool { !wayland() @@ -211,6 +316,7 @@ mod platform { sources.push(offer(mime, data)); } } + sources.push(MimeSource { source: Source::Bytes(owner_token().to_vec().into()), mime_type: MimeType::Specific(OWNER_MIME.into()) }); match Options::new().copy_multi(sources) { Ok(()) => true, Err(e) => { @@ -220,6 +326,37 @@ mod platform { } } + /// Put a copied picture on the Wayland clipboard alongside HTML, text, and ownership token. + pub fn set_image(image: &wordcraft_ui_egui::system_clipboard::CopyImage, html: &str, text: &str) -> bool { + use wl_clipboard_rs::copy::{MimeSource, MimeType, Options, Source}; + + if !wayland() { + return false; + } + let Ok(png) = wordcraft_ui_egui::paste_picture::png_from_rgba(image.width, image.height, image.rgba.clone()) else { + return false; + }; + let offer = |mime: &str, data: &str| MimeSource { source: Source::Bytes(data.as_bytes().into()), mime_type: MimeType::Specific(mime.into()) }; + let mut sources = vec![MimeSource { source: Source::Bytes(png.into()), mime_type: MimeType::Specific("image/png".into()) }]; + if !text.is_empty() { + sources.push(offer("text/plain;charset=utf-8", text)); + } + if !html.is_empty() { + sources.push(offer("text/html", html)); + } + sources.push(MimeSource { source: Source::Bytes(owner_token().to_vec().into()), mime_type: MimeType::Specific(OWNER_MIME.into()) }); + match Options::new().copy_multi(sources) { + Ok(()) => true, + Err(e) => { + log::warn!("clipboard image: {e}"); + false + } + } + } + + /// Additional formats to register after setting image via arboard on Unix. + pub fn after_set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) {} + /// Wayland copies carry their RTF already; X11 ones can't (see the module docs). pub fn add_rtf(_rtf: &str) {} @@ -346,6 +483,14 @@ mod platform { let reply = r.convert(target, cap, true)?; (reply.type_ != incr).then_some(reply.value) } + + /// Query X11 for the current window id owning the CLIPBOARD selection. + pub fn owner_window() -> Option { + let (conn, _) = x11rb::connect(None).ok()?; + let clipboard = atom(&conn, "CLIPBOARD")?; + let reply = conn.get_selection_owner(clipboard).ok()?.reply().ok()?; + (reply.owner != x11rb::NONE).then_some(reply.owner) + } } /// The Wayland clipboard's picture, read encoded under the paste's byte cap and refused from @@ -436,6 +581,40 @@ mod platform { Ok(out) } + const OWNER_FORMAT: &str = "WordCraft Copy Owner"; + + /// Process-unique ownership token placed into Windows clipboard marker. + fn owner_token() -> [u8; 16] { + static TOKEN: std::sync::OnceLock<[u8; 16]> = std::sync::OnceLock::new(); + *TOKEN.get_or_init(|| { + let mut b = [0u8; 16]; + let _ = getrandom::fill(&mut b); + b + }) + } + + /// Record clipboard ownership for Windows clipboard. + pub fn record_own() { + let Some(format) = raw::register_format(OWNER_FORMAT) else { return }; + let Ok(_open) = Clipboard::new_attempts(10) else { return }; + let _ = raw::set_without_clear(format.get(), &owner_token()); + } + + /// Whether WordCraft still owns the Windows clipboard contents. + pub fn is_own() -> bool { + let Some(format) = raw::register_format(OWNER_FORMAT) else { return false }; + let Ok(_open) = Clipboard::new_attempts(10) else { return false }; + if !raw::is_format_avail(format.get()) { + return false; + } + let mut out = Vec::new(); + if raw::get_vec(format.get(), &mut out).is_err() { + return false; + } + out == owner_token() + } + + /// Windows supports clipboard setting via arboard and clipboard_win. pub fn can_set() -> bool { true } @@ -445,6 +624,29 @@ mod platform { false } + /// Windows sets the primary image through arboard and supplements via [`after_set_image`]. + pub fn set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) -> bool { + false + } + + /// Add PNG and CF_HTML formats alongside arboard's image, then mark ownership. + pub fn after_set_image(image: &wordcraft_ui_egui::system_clipboard::CopyImage, html: &str, _text: &str) { + if let Ok(png) = wordcraft_ui_egui::paste_picture::png_from_rgba(image.width, image.height, image.rgba.clone()) + && let Some(format) = raw::register_format("PNG") + && let Ok(_open) = Clipboard::new_attempts(10) + { + let _ = raw::set_without_clear(format.get(), &png); + } + if !html.is_empty() + && let Some(format) = raw::register_format("HTML Format") + && let Ok(_open) = Clipboard::new_attempts(10) + { + let cf = super::wrap_cf_html(html); + let _ = raw::set_without_clear(format.get(), &cf); + } + record_own(); + } + /// Add "Rich Text Format" to what arboard just set, NUL-terminated as is usual. pub fn add_rtf(rtf: &str) { let Some(format) = raw::register_format("Rich Text Format") else { return }; @@ -487,19 +689,38 @@ mod platform { /// RTF's pasteboard type (`NSPasteboardTypeRTF`, whose extern static needs unsafe to read). const RTF: &str = "public.rtf"; + /// Formats offered on macOS pasteboard. pub fn formats() -> Vec { Vec::new() } + /// Read RTF data from macOS pasteboard. pub fn rtf() -> Option> { let data = NSPasteboard::generalPasteboard().dataForType(&NSString::from_str(RTF))?; (data.len() <= super::MAX_PASTE_BYTES).then(|| data.to_vec()) } + /// Read encoded picture data from macOS pasteboard. pub fn encoded_picture() -> Option> { None } + static LAST_CHANGE_COUNT: std::sync::atomic::AtomicIsize = std::sync::atomic::AtomicIsize::new(-1); + + /// Record pasteboard changeCount on macOS to verify ownership. + pub fn record_own() { + let count = NSPasteboard::generalPasteboard().changeCount(); + LAST_CHANGE_COUNT.store(count, std::sync::atomic::Ordering::Relaxed); + } + + /// Whether WordCraft still owns the macOS pasteboard. + pub fn is_own() -> bool { + let count = NSPasteboard::generalPasteboard().changeCount(); + let recorded = LAST_CHANGE_COUNT.load(std::sync::atomic::Ordering::Relaxed); + recorded >= 0 && count == recorded + } + + /// Whether macOS supports setting the pasteboard. pub fn can_set() -> bool { true } @@ -509,6 +730,23 @@ mod platform { false } + /// macOS sets the primary image through arboard and supplements via [`after_set_image`]. + pub fn set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) -> bool { + false + } + + /// Set supplemental PNG and HTML representations on macOS pasteboard. + pub fn after_set_image(image: &wordcraft_ui_egui::system_clipboard::CopyImage, html: &str, _text: &str) { + let board = NSPasteboard::generalPasteboard(); + if let Ok(png) = wordcraft_ui_egui::paste_picture::png_from_rgba(image.width, image.height, image.rgba.clone()) { + let _ = board.setData_forType(Some(&NSData::with_bytes(&png)), &NSString::from_str("public.png")); + } + if !html.is_empty() { + let _ = board.setString_forType(&NSString::from_str(html), &NSString::from_str("public.html")); + } + record_own(); + } + /// Add RTF to the pasteboard item arboard just wrote (it cleared the pasteboard first). pub fn add_rtf(rtf: &str) { if !NSPasteboard::generalPasteboard().setData_forType(Some(&NSData::with_bytes(rtf.as_bytes())), &NSString::from_str(RTF)) { @@ -535,27 +773,80 @@ mod platform { all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))) )))] mod platform { + /// Formats on the clipboard. pub fn formats() -> Vec { Vec::new() } + /// The RTF bytes on the clipboard. pub fn rtf() -> Option> { None } + /// Encoded picture bytes on the clipboard. pub fn encoded_picture() -> Option> { None } + /// Whether the fallback platform can set the clipboard. pub fn can_set() -> bool { true } + /// Record clipboard ownership on the fallback platform. + pub fn record_own() {} + + /// Whether WordCraft owns the clipboard on the fallback platform. + pub fn is_own() -> bool { + false + } + + /// Set rich text on the fallback platform. pub fn set_rich(_text: &str, _html: &str, _rtf: &str) -> bool { false } + /// Set image on the fallback platform. + pub fn set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) -> bool { + false + } + + /// Post-image set hook on the fallback platform. + pub fn after_set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) {} + + /// Add RTF to the clipboard on the fallback platform. pub fn add_rtf(_rtf: &str) {} + /// Add MathML to the clipboard on the fallback platform. pub fn add_mathml(_mathml: &str) {} } + +#[cfg(test)] +mod cf_html_tests { + use super::wrap_cf_html; + + fn field(data: &[u8], name: &str) -> usize { + let at = data.windows(name.len()).position(|w| w == name.as_bytes()).expect("field") + name.len(); + std::str::from_utf8(&data[at..at + 10]).expect("offset digits").parse().expect("offset") + } + + #[test] + fn cf_html_offsets_delimit_the_fragment_bytes() { + let fragment = "

Olá, 世界 — café

"; + let data = wrap_cf_html(fragment); + + let start_html = field(&data, "StartHTML:"); + let end_html = field(&data, "EndHTML:"); + let start_fragment = field(&data, "StartFragment:"); + let end_fragment = field(&data, "EndFragment:"); + + assert!(start_html < start_fragment, "HTML starts before its fragment"); + assert!(start_fragment < end_fragment, "fragment has a positive length"); + assert!(end_fragment < end_html, "fragment ends inside the document"); + assert_eq!(&data[start_html..start_html + "".len()], b""); + assert_eq!(&data[start_fragment..end_fragment], fragment.as_bytes()); + assert_eq!(end_fragment - start_fragment, fragment.len(), "offsets count UTF-8 bytes"); + assert_eq!(&data[end_html..], b"\0", "EndHTML excludes the trailing NUL"); + assert_eq!(end_html, data.len() - 1); + } +} diff --git a/apps/wordcraft/src/main.rs b/apps/wordcraft/src/main.rs index e40803998f..18b7b7935f 100644 --- a/apps/wordcraft/src/main.rs +++ b/apps/wordcraft/src/main.rs @@ -384,6 +384,8 @@ fn services(file_dialog: file_dialogs::Hook, cancel_file_dialog: file_dialogs::C clipboard_text: Some(Box::new(clipboard::text)), clipboard_html: Some(Box::new(clipboard::html)), set_clipboard_rich: Some(Box::new(clipboard::set_rich)), + set_clipboard_image: Some(Box::new(clipboard::set_image)), + clipboard_is_own: Some(Box::new(clipboard::is_own)), clipboard_rtf: Some(Box::new(clipboard::rtf)), clipboard_formats: Some(Box::new(clipboard::formats)), save_prefs: Some(Box::new(try_save_prefs)), diff --git a/crates/doc/src/edit.rs b/crates/doc/src/edit.rs index fc8fa2bb26..175210e031 100644 --- a/crates/doc/src/edit.rs +++ b/crates/doc/src/edit.rs @@ -20,6 +20,9 @@ pub struct Fragment { /// gives each box a new story made from these. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub parts: BTreeMap, + /// Media items referenced by objects in this fragment. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty", with = "crate::byte_store")] + pub media: BTreeMap>>, } impl Fragment { @@ -30,6 +33,8 @@ impl Fragment { pub fn to_document(&self) -> Document { let mut d = Document::new(); d.body = self.blocks.iter().cloned().map(Arc::new).collect(); + d.parts = self.parts.clone(); + d.media = self.media.clone(); d } /// Whether the fragment holds an equation (in tables too), which a copy also puts on the @@ -560,6 +565,44 @@ fn box_ids(p: &Paragraph) -> impl Iterator + '_ { p.objects.iter().flat_map(InlineObject::text_boxes) } +/// Remap media references in an inline object. +fn remap_media_object(o: &mut InlineObject, map: &BTreeMap, depth: usize) { + match o { + InlineObject::Image { media, .. } => { + if let Some(k) = map.get(media.as_str()) { + *media = k.clone(); + } + } + InlineObject::Graphic { graphic, .. } => { + let mapped = |m: &str| map.get(m).filter(|k| k.as_str() != m); + if graphic.items.iter().any(|i| matches!(i, crate::graphic::GraphicItem::Image { media, .. } if mapped(media).is_some())) { + for i in &mut Arc::make_mut(graphic).items { + if let crate::graphic::GraphicItem::Image { media, .. } = i + && let Some(k) = map.get(media.as_str()) + { + *media = k.clone(); + } + } + } + } + InlineObject::Group { children, .. } if depth < MAX_BOX_DEPTH => { + for child in children { + remap_media_object(&mut child.obj, map, depth + 1); + } + } + _ => {} + } +} + +/// Remap media references in a block. +fn remap_media_block(b: &mut Block, map: &BTreeMap) { + each_para_mut(b, 0, &mut |p| { + for o in &mut p.objects { + remap_media_object(o, map, 0); + } + }); +} + impl Document { /// Convert notes between footnotes and endnotes: footnotes (`foot`) become endnotes and /// endnotes (`end`) footnotes, both at once to swap them. Each note's kind changes, as do its @@ -974,7 +1017,8 @@ impl Document { // Half a content control (one marker without the other) isn't copied. crate::control::balance_blocks(&mut blocks); let parts = self.text_box_parts(&blocks); - Fragment { blocks, parts } + let media = self.media_of_blocks(&blocks); + Fragment { blocks, parts, media } } /// A copy of the block at `path` (a whole table, say) as a fragment, with its text boxes. @@ -996,7 +1040,8 @@ impl Document { fn fragment_of(&self, mut blocks: Vec) -> Fragment { crate::control::balance_blocks(&mut blocks); let parts = self.text_box_parts(&blocks); - Fragment { blocks, parts } + let media = self.media_of_blocks(&blocks); + Fragment { blocks, parts, media } } /// The table whose whole text `a..b` covers when the range runs across its cells: from the @@ -1038,7 +1083,8 @@ impl Document { pub fn body_fragment(&self) -> Fragment { let blocks: Vec = self.body.iter().map(|b| (**b).clone()).collect(); let parts = self.text_box_parts(&blocks); - Fragment { blocks, parts } + let media = self.media_of_blocks(&blocks); + Fragment { blocks, parts, media } } /// Another document's body as a fragment of this one, to insert: the media, lists, styles, @@ -1207,7 +1253,7 @@ impl Document { } let mut blocks: Vec = src.body.iter().map(|b| (**b).clone()).collect(); blocks.iter_mut().for_each(|b| link.block(b)); - Fragment { blocks, parts } + Fragment { blocks, parts, media: self.media.clone() } } /// [`Self::adopt_with`] as blocks to place in a story directly (a reader building one): its @@ -1215,7 +1261,7 @@ impl Document { /// id the reader hasn't given out (ranges it holds aren't in this document yet); it moves past /// the adopted ones. pub fn adopt_blocks(&mut self, src: Document, keep_styles: bool, perms: &mut u32) -> Vec { - let Fragment { mut blocks, parts } = self.adopt_in(src, keep_styles, perms); + let Fragment { mut blocks, parts, .. } = self.adopt_in(src, keep_styles, perms); let mut budget = BoxBudget::new(); self.adopt_text_boxes(&mut blocks, &parts, 0, &mut budget); blocks @@ -1241,6 +1287,52 @@ impl Document { out } + /// Media items referenced by objects in `blocks`, nested text box stories included. + pub fn media_of_blocks(&self, blocks: &[Block]) -> BTreeMap>> { + let mut keys = std::collections::BTreeSet::new(); + /// Collect media keys from an inline object recursively. + fn collect_object(o: &InlineObject, keys: &mut std::collections::BTreeSet, depth: usize) { + match o { + InlineObject::Image { media, .. } => { + keys.insert(media.clone()); + } + InlineObject::Graphic { graphic, .. } => { + for item in &graphic.items { + if let crate::graphic::GraphicItem::Image { media, .. } = item { + keys.insert(media.clone()); + } + } + } + InlineObject::Group { children, .. } if depth < MAX_BOX_DEPTH => { + for child in children { + collect_object(&child.obj, keys, depth + 1); + } + } + _ => {} + } + } + let mut collect_para = |p: &Paragraph| { + for o in &p.objects { + collect_object(o, &mut keys, 0); + } + }; + for b in blocks { + each_para(b, 0, &mut collect_para); + } + for part in self.text_box_parts(blocks).values() { + for b in &part.blocks { + each_para(b, 0, &mut collect_para); + } + } + let mut out = BTreeMap::new(); + for k in keys { + if let Some(data) = self.media.get(&k) { + out.insert(k, data.clone()); + } + } + out + } + fn copy_blocks(&self, a: &Pos, b: &Pos) -> Vec { let (a, b) = order(a, b); let mut out = Vec::new(); @@ -1389,6 +1481,18 @@ impl Document { /// Insert a fragment at `pos`; returns the position after the pasted content. pub fn insert_fragment(&mut self, pos: &Pos, frag: &Fragment) -> Result { + let mut media_remap = BTreeMap::new(); + for (k, v) in &frag.media { + if let Some(existing) = self.media.get(k) { + if existing.as_slice() != v.as_slice() { + let ext = k.rsplit_once('.').map_or("png", |(_, ext)| ext); + let new_key = self.add_media((**v).clone(), ext); + media_remap.insert(k.clone(), new_key); + } + } else { + self.media.insert(k.clone(), v.clone()); + } + } // Tables that would nest deeper than the limit here become their paragraphs (#1596). let room = MAX_TABLE_DEPTH.saturating_sub(pos.path.depth()); let mut blocks = Vec::with_capacity(frag.blocks.len()); @@ -1401,9 +1505,20 @@ impl Document { if self.para_at(pos).is_none() { return Err(DocError::BadPath(pos.path.to_string())); } + let mut parts = frag.parts.clone(); + if !media_remap.is_empty() { + for b in &mut blocks { + remap_media_block(b, &media_remap); + } + for part in parts.values_mut() { + for b in &mut part.blocks { + remap_media_block(Arc::make_mut(b), &media_remap); + } + } + } // Pasted text boxes get stories of their own (never shared with the copy's source). let mut budget = BoxBudget::new(); - self.adopt_text_boxes(&mut blocks, &frag.parts, 0, &mut budget); + self.adopt_text_boxes(&mut blocks, &parts, 0, &mut budget); if budget.skipped > 0 { // Once per paste, not once per box (review of #3874). log::warn!( diff --git a/crates/doc/src/edit/tests.rs b/crates/doc/src/edit/tests.rs index ae7f7d64af..0278396824 100644 --- a/crates/doc/src/edit/tests.rs +++ b/crates/doc/src/edit/tests.rs @@ -326,7 +326,7 @@ fn fan_out(story: Vec>, refs: usize) -> Fragment { } let mut parts = BTreeMap::new(); parts.insert(1, crate::Part { kind: PartKind::TextBox, blocks: story, body: Default::default() }); - Fragment { blocks: vec![Block::Para(p)], parts } + Fragment { blocks: vec![Block::Para(p)], parts, ..Default::default() } } #[test] @@ -911,3 +911,80 @@ fn an_adopted_notes_text_box_gets_a_story_of_its_own() { assert_eq!(part.kind, PartKind::TextBox); assert!(matches!(part.blocks.first().map(|b| &**b), Some(Block::Para(p)) if p.text == "their box")); } + +#[test] +fn media_of_blocks_collects_graphic_and_group_images() { + let mut d = doc(&["test"]); + d.media.insert("graphic_img.png".into(), Arc::new(vec![1, 2, 3])); + d.media.insert("group_img.png".into(), Arc::new(vec![4, 5, 6])); + + let graphic = crate::graphic::Graphic { + kind: crate::graphic::GraphicKind::Diagram, + items: vec![crate::graphic::GraphicItem::Image { rect: [0.0, 0.0, 10.0, 10.0], media: "graphic_img.png".into() }], + ..Default::default() + }; + let group = InlineObject::Group { + w: 50.0, + h: 50.0, + float: Default::default(), + ch_w: 50.0, + ch_h: 50.0, + canvas: None, + children: vec![crate::para::GroupChild { + x: 0.0, + y: 0.0, + obj: InlineObject::Image { + media: "group_img.png".into(), + w: 10.0, + h: 10.0, + alt: String::new(), + float: Default::default(), + crop: [0.0; 4], + fx: Default::default(), + ole: None, + }, + }], + }; + let mut p = Paragraph::with_text(&crate::para::OBJ.to_string(), CharProps::default()); + p.objects.push(InlineObject::Graphic { w: 100.0, h: 100.0, float: Default::default(), alt: String::new(), graphic: Arc::new(graphic) }); + p.objects.push(group); + let blocks = vec![Block::Para(p)]; + let collected = d.media_of_blocks(&blocks); + assert!(collected.contains_key("graphic_img.png")); + assert!(collected.contains_key("group_img.png")); +} + +#[test] +fn insert_fragment_remaps_conflicting_media_keys() { + let mut d = doc(&["destination"]); + d.media.insert("image1.png".into(), Arc::new(vec![1, 1, 1])); + + let mut frag_media = std::collections::BTreeMap::new(); + frag_media.insert("image1.png".into(), Arc::new(vec![2, 2, 2])); + + let mut p = Paragraph::with_text(&crate::para::OBJ.to_string(), CharProps::default()); + p.objects.push(InlineObject::Image { + media: "image1.png".into(), + w: 10.0, + h: 10.0, + alt: String::new(), + float: Default::default(), + crop: [0.0; 4], + fx: Default::default(), + ole: None, + }); + let frag = Fragment { blocks: vec![Block::Para(p)], parts: Default::default(), media: frag_media }; + + let pos = Pos::body(0, 0); + d.insert_fragment(&pos, &frag).unwrap(); + // The original destination media is preserved. + assert_eq!(d.media["image1.png"].as_slice(), &[1, 1, 1]); + // A second media key was created for the conflicting fragment media. + assert_eq!(d.media.len(), 2); + let other_key = d.media.keys().find(|k| k.as_str() != "image1.png").unwrap(); + assert_eq!(d.media[other_key].as_slice(), &[2, 2, 2]); + // The inserted paragraph references the remapped key. + let para = d.para(StoryRef::Body, &Path::top(0)).unwrap(); + let remapped = para.objects.iter().find_map(|o| if let InlineObject::Image { media, .. } = o { Some(media.as_str()) } else { None }).unwrap(); + assert_eq!(remapped, other_key); +} diff --git a/crates/engine/src/cmd/column.rs b/crates/engine/src/cmd/column.rs index 6d6c83b805..8801d2d9e7 100644 --- a/crates/engine/src/cmd/column.rs +++ b/crates/engine/src/cmd/column.rs @@ -232,7 +232,8 @@ fn copy(s: &mut Session, segs: &[(Pos, Pos)]) -> CmdResult { blocks.push(Block::Para(para)); } s.clipboard_text = rows.join("\n"); - s.clipboard = Some(Fragment { blocks, parts }); + let media = s.doc.media_of_blocks(&blocks); + s.clipboard = Some(Fragment { blocks, parts, media }); Ok(super::edit::copy_result(s)) } diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index a55ce7571e..bcc9cff404 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -79,12 +79,14 @@ pub fn specs() -> Vec { Some("the Spike is empty") } }), - CommandSpec::new("edit.paste", "Paste", "Home › Clipboard", paste).key("Mod+V / Shift+Insert").params(r#"{"text"?: string, "html"?: string, "rtf"?: string}"#), + CommandSpec::new("edit.paste", "Paste", "Home › Clipboard", paste) + .key("Mod+V / Shift+Insert") + .params(r#"{"text"?: string, "html"?: string, "rtf"?: string, "privateClipboard"?: bool}"#), CommandSpec::new("edit.pasteText", "Paste: Keep Text Only", "Home › Clipboard › Paste", paste_text) .params(r#"{"text"?: string}"#) .key("Mod+Shift+Alt+V"), CommandSpec::new("edit.pasteMerge", "Paste: Merge Formatting", "Home › Clipboard › Paste", paste_merge) - .params(r#"{"text"?: string, "html"?: string, "rtf"?: string}"#), + .params(r#"{"text"?: string, "html"?: string, "rtf"?: string, "privateClipboard"?: bool}"#), CommandSpec::new("edit.clipboardPane", "Clipboard Pane", "Home › Clipboard", |s, v| { let on = p::bool(v, "value").unwrap_or(!s.view.clipboard_pane); s.view.clipboard_pane = on; @@ -204,7 +206,10 @@ fn copy_with(s: &mut Session, whole: Option<&Path>) -> CmdResult { pub(crate) fn copy_result(s: &mut Session) -> Value { (s.clipboard_html, s.clipboard_rtf) = match &s.clipboard { Some(f) => { - let d = f.to_document(); + let mut d = f.to_document(); + if d.media.is_empty() { + d.media = s.doc.media.clone(); + } (wordcraft_formats::html::export_fragment(&d), wordcraft_formats::rtf::export(&d)) } None => (String::new(), String::new()), @@ -362,9 +367,10 @@ impl ClipHistory { } pub(crate) fn push(&mut self, f: &Fragment, text: &str) { - // Text plus per-paragraph overhead; pictures are references into the document. + // Text plus per-paragraph overhead, plus the picture bytes the fragment keeps alive. let paras = text.matches('\n').count().saturating_add(f.blocks.len()).saturating_add(f.parts.len()).saturating_add(1); - let bytes = text.len().saturating_mul(2).saturating_add(paras.saturating_mul(256)); + let media = f.media.values().map(|m| m.len()).fold(0, usize::saturating_add); + let bytes = text.len().saturating_mul(2).saturating_add(paras.saturating_mul(256)).saturating_add(media); if bytes > CLIP_ITEM_BYTES || f.blocks.is_empty() { return; } diff --git a/crates/engine/src/cmd/paste.rs b/crates/engine/src/cmd/paste.rs index 4a8aad3b02..e4df30bd95 100644 --- a/crates/engine/src/cmd/paste.rs +++ b/crates/engine/src/cmd/paste.rs @@ -37,7 +37,7 @@ pub fn specs() -> Vec { vec![ CommandSpec::new("edit.pasteSpecial", "Paste Special", "Home › Clipboard › Paste", paste_special) .key("Mod+Alt+V") - .params(r#"{"as"?: "formatted"|"rtf"|"html"|"picture"|"text", "text"?: string, "html"?: string, "rtf"?: string, "picture"?: base64}"#), + .params(r#"{"as"?: "formatted"|"rtf"|"html"|"picture"|"text", "text"?: string, "html"?: string, "rtf"?: string, "picture"?: base64, "privateClipboard"?: bool}"#), ] } @@ -58,11 +58,18 @@ fn looks_like_html(t: &str) -> bool { t.starts_with('<') && (t.contains("")) } +/// Whether the system clipboard still holds this window's copy. A front end that can check says +/// so in `privateClipboard`; callers that cannot (an agent, the CLI) omit it, and the session's +/// copy is used as before. +fn owns_clipboard(v: &Value) -> bool { + p::bool(v, "privateClipboard").unwrap_or(true) +} + /// The source for a format, if the clipboard has it. fn source(s: &Session, v: &Value, fmt: &str) -> Option { let non_empty = |t: String| if t.is_empty() { None } else { Some(t) }; match fmt { - "formatted" => { + "formatted" if owns_clipboard(v) => { let f = s.clipboard.as_ref()?; // System clipboard text that isn't our own copy means someone else copied since. match p::str(v, "text") { @@ -70,6 +77,7 @@ fn source(s: &Session, v: &Value, fmt: &str) -> Option { _ => Some(String::new()), } } + "formatted" => None, "rtf" => p::str(v, "rtf").map(str::to_string).or_else(|| clip_text(s, v).filter(|t| looks_like_rtf(t))).and_then(non_empty), "html" => p::str(v, "html").map(str::to_string).or_else(|| clip_text(s, v).filter(|t| looks_like_html(t))).and_then(non_empty), "picture" => p::str(v, "picture").map(str::to_string).and_then(non_empty), @@ -105,6 +113,10 @@ fn paste_special(s: &mut Session, v: &Value) -> CmdResult { req[k] = json!(t); } } + // Keep the ownership result so the dialog's list is the same as this one. + if let Some(own) = p::bool(v, "privateClipboard") { + req["privateClipboard"] = json!(own); + } // Only the newest dialog request matters; older ones would pin their payloads. s.ui_requests.retain(|r| r["open"] != "pasteSpecial"); s.push_ui_request(req); @@ -265,10 +277,13 @@ pub enum Pasted { } /// What Paste inserts: WordCraft's own copy while the system clipboard still holds it, else -/// another program's formatted copy (HTML, RTF), else the system clipboard's text. +/// another program's formatted copy (HTML, RTF), else the system clipboard's text. A front end +/// that knows another program owns the clipboard passes `privateClipboard: false`, which keeps +/// the fragment out even when the text matches. pub fn paste_content(s: &mut Session, v: &Value) -> Result { let text = p::str(v, "text").map(|t| t.replace("\r\n", "\n")); - if let Some(f) = &s.clipboard + if owns_clipboard(v) + && let Some(f) = &s.clipboard && text.as_ref().is_none_or(|t| f.clipboard_text() == *t) && (text.is_some() || (p::str(v, "html").is_none() && p::str(v, "rtf").is_none())) { diff --git a/crates/engine/src/cmd/table_draw.rs b/crates/engine/src/cmd/table_draw.rs index a5102ea7cf..259af94b78 100644 --- a/crates/engine/src/cmd/table_draw.rs +++ b/crates/engine/src/cmd/table_draw.rs @@ -765,9 +765,9 @@ mod tests { s.run("table.eraser", &json!({"page": 0, "x": a.right() + 0.5, "y": a.y + a.h / 2.0})).unwrap(); let t = first_table(&s); assert_eq!(shape(&t), shape(&start), "no merge"); - for r in 0..2 { - let right = t.rows[r].cells[0].props.borders.and_then(|b| b.right); - let left = t.rows[r].cells[1].props.borders.and_then(|b| b.left); + for (r, row) in t.rows[..2].iter().enumerate() { + let right = row.cells[0].props.borders.and_then(|b| b.right); + let left = row.cells[1].props.borders.and_then(|b| b.left); assert!(right.is_some_and(|b| !b.is_visible()) && left.is_some_and(|b| !b.is_visible()), "row {r}"); } assert!(t.rows[2].cells[0].props.borders.is_none(), "rows outside the edge are untouched"); diff --git a/crates/engine/src/cmd/tools/actions.rs b/crates/engine/src/cmd/tools/actions.rs index 28bc721c13..50c492e921 100644 --- a/crates/engine/src/cmd/tools/actions.rs +++ b/crates/engine/src/cmd/tools/actions.rs @@ -131,7 +131,9 @@ pub(super) fn quick_parts(s: &mut Session, v: &Value, gallery: &str) -> CmdResul None => { let e = document_entry(&s.doc, name, gallery).and_then(|i| s.doc.glossary.get(i)); let e = e.ok_or_else(|| CmdError::Params(format!("no Quick Part `{name}`")))?; - wordcraft_doc::edit::Fragment { blocks: e.blocks.iter().map(|b| (**b).clone()).collect(), parts: Default::default() } + let blocks: Vec<_> = e.blocks.iter().map(|b| (**b).clone()).collect(); + let media = s.doc.media_of_blocks(&blocks); + wordcraft_doc::edit::Fragment { blocks, parts: Default::default(), media } } }; let at = delete_selection(s)?; diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 22ea3b72e7..6d8222f713 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -1193,6 +1193,52 @@ fn clipboard_round_trip() { assert_eq!(text(&s), "plain\ntext"); } +/// Whether any run in the body is bold. +fn any_bold(s: &Session) -> bool { + s.doc.body.iter().filter_map(|b| b.as_para()).flat_map(|p| p.runs.iter()).any(|r| r.props.bold == Some(true)) +} + +#[test] +fn paste_from_another_program_does_not_bring_back_our_fragment() { + // Review on #6225: when another program owns the clipboard, matching text must not make + // Paste put WordCraft's own formatted fragment back. + let mut s = s(); + run(&mut s, "document.setText", json!({"text": "Bold"})); + run(&mut s, "select.all", json!({})); + run(&mut s, "format.bold", json!({})); + run(&mut s, "edit.copy", json!({})); + assert_eq!(s.clipboard_text, "Bold"); + + // The same text, copied by another program: paste it as plain text, not our bold fragment. + run(&mut s, "document.setText", json!({"text": "Plain "})); + run(&mut s, "caret.docEnd", json!({})); + run(&mut s, "edit.paste", json!({"text": "Bold", "privateClipboard": false})); + assert_eq!(text(&s), "Plain Bold"); + assert!(!any_bold(&s), "{:?}", s.doc.body); + + // Callers that omit the flag (an agent, the CLI) still get the session's own copy. + run(&mut s, "caret.docEnd", json!({})); + run(&mut s, "edit.paste", json!({"text": "Bold"})); + assert!(any_bold(&s), "{:?}", s.doc.body); +} + +#[test] +fn paste_special_does_not_offer_our_fragment_for_another_programs_copy() { + let mut s = s(); + run(&mut s, "document.setText", json!({"text": "Bold"})); + run(&mut s, "select.all", json!({})); + run(&mut s, "format.bold", json!({})); + run(&mut s, "edit.copy", json!({})); + + let r = run(&mut s, "edit.pasteSpecial", json!({"text": "Bold", "privateClipboard": false})); + let ids: Vec<&str> = r["formats"].as_array().map(|a| a.iter().filter_map(|f| f["id"].as_str()).collect()).unwrap_or_default(); + assert!(!ids.contains(&"formatted"), "{ids:?}"); + assert_eq!(s.ui_requests.last().and_then(|r| r.get("privateClipboard")), Some(&json!(false)), "{:?}", s.ui_requests); + + let e = s.run("edit.pasteSpecial", &json!({"as": "formatted", "text": "Bold", "privateClipboard": false})); + assert!(e.is_err(), "another program's copy cannot be pasted as our fragment"); +} + /// Equations in the paragraphs of a session's body, as linear text. fn equations(s: &Session) -> Vec { let mut out = Vec::new(); diff --git a/crates/formats/src/latex/tests.rs b/crates/formats/src/latex/tests.rs index 3097eaea1f..2b81895a9c 100644 --- a/crates/formats/src/latex/tests.rs +++ b/crates/formats/src/latex/tests.rs @@ -391,9 +391,9 @@ fn table_borders_and_borderless_round_trip() { let mut doc = Document::new(); let mut t_borderless = Table::new(2, 2, 400.0); t_borderless.props.style = None; - for r in 0..2 { - for c in 0..2 { - t_borderless.rows[r].cells[c].blocks = vec![para_block(Paragraph::with_text("cell", CharProps::default()))]; + for row in &mut t_borderless.rows { + for cell in &mut row.cells { + cell.blocks = vec![para_block(Paragraph::with_text("cell", CharProps::default()))]; } } doc.body = vec![Arc::new(Block::Table(t_borderless))]; @@ -407,9 +407,9 @@ fn table_borders_and_borderless_round_trip() { let mut doc_bordered = Document::new(); let mut t_bordered = Table::new(2, 2, 400.0); t_bordered.props.style = Some("TableGrid".to_string()); - for r in 0..2 { - for c in 0..2 { - t_bordered.rows[r].cells[c].blocks = vec![para_block(Paragraph::with_text("cell", CharProps::default()))]; + for row in &mut t_bordered.rows { + for cell in &mut row.cells { + cell.blocks = vec![para_block(Paragraph::with_text("cell", CharProps::default()))]; } } doc_bordered.body = vec![Arc::new(Block::Table(t_bordered))]; diff --git a/crates/layout/src/tests.rs b/crates/layout/src/tests.rs index b83e5bf3fb..a15f2f672b 100644 --- a/crates/layout/src/tests.rs +++ b/crates/layout/src/tests.rs @@ -8640,8 +8640,8 @@ fn picture_row(room: f32, min: f32, pic_h: f32, lines: usize) -> (DocLayout, Vec t.rows[1].props.height = Some(min); t.rows[1].props.height_rule = HeightRule::AtLeast; } - for c in 1..3 { - t.rows[1].cells[c].blocks = lines_in_cell(lines, "N/A"); + for cell in &mut t.rows[1].cells[1..3] { + cell.blocks = lines_in_cell(lines, "N/A"); } set_at_least_row_spacing(&mut t); let mut p = wordcraft_doc::Paragraph::with_text("", Default::default()); @@ -10327,8 +10327,8 @@ fn a_hidden_cell_mark_takes_no_room() { let mut d = Document::from_text("Above"); let mut t = Table::new(3, 2, 300.0); for (r, text) in [(0, "R1"), (2, "R3")] { - for c in 0..2 { - t.rows[r].cells[c].blocks = vec![wordcraft_doc::para_block(wordcraft_doc::Paragraph::with_text(text, Default::default()))]; + for cell in &mut t.rows[r].cells { + cell.blocks = vec![wordcraft_doc::para_block(wordcraft_doc::Paragraph::with_text(text, Default::default()))]; } } for (cell, hide) in t.rows[1].cells.iter_mut().zip(hide) { diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 77c2b82580..d4d8487e7e 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -101,6 +101,7 @@ impl WordApp { ..UiState::default() }, services, + clipboard_published: false, printing: Default::default(), print_feedback_seen: None, integrated_titlebar: false, diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 8f20dc4ecb..c9872347a9 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -869,6 +869,9 @@ impl Dialog { kept[k] = json!(t); } } + if let Some(own) = payload.get("privateClipboard").and_then(Value::as_bool) { + kept["privateClipboard"] = json!(own); + } let note = if formats.is_empty() { crate::system_clipboard::nothing_to_paste(app) } else { String::new() }; Dialog::PasteSpecial { formats, choice: 0, payload: kept, note } } diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index eb31a99c32..7154033a25 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -3,6 +3,19 @@ use wordcraft_doc::Pos; use wordcraft_doc::props::Align; use wordcraft_engine::Session; +/// Paste Special lists and pastes the same formats the engine chose: the clipboard ownership +/// result must survive into the dialog's payload, or another program's copy could be replaced +/// by WordCraft's own fragment. +#[test] +fn paste_special_dialog_keeps_the_clipboard_ownership_result() { + let a = WordApp::new(Session::new(wordcraft_doc::Document::from_text("")), crate::Services::default()); + let d = Dialog::paste_special(&a, &json!({"text": "Bold", "privateClipboard": false})); + let Dialog::PasteSpecial { formats, payload, .. } = d else { panic!("not Paste Special") }; + assert_eq!(formats, ["text"], "another program's copy isn't our fragment"); + assert_eq!(payload.get("privateClipboard"), Some(&json!(false))); + assert_eq!(payload.get("text").and_then(Value::as_str), Some("Bold")); +} + /// #3931: hovering Insert › Table's grid asks the page for a preview of that table (rows by /// columns) and changes nothing; leaving the grid drops it; a click inserts the table with no /// preview left over for the page to show on top of it. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 659466d177..955a77aac0 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -625,6 +625,8 @@ pub struct WordApp { pub session: Session, pub ui: UiState, pub services: Services, + /// Only a successfully published copy may reuse this window's private fragment. + pub clipboard_published: bool, pub printing: printing::State, print_feedback_seen: Option, pub canvas: canvas::CanvasState, diff --git a/crates/ui-egui/src/services.rs b/crates/ui-egui/src/services.rs index a144ecd197..baaff42c28 100644 --- a/crates/ui-egui/src/services.rs +++ b/crates/ui-egui/src/services.rs @@ -1,5 +1,5 @@ use super::state::DefaultApp; -use super::{FileDialogAnswer, FileDialogRequest, WordApp, async_saves, paste_picture, printing}; +use super::{FileDialogAnswer, FileDialogRequest, WordApp, async_saves, paste_picture, printing, system_clipboard}; /// Platform services injected by the host (file dialogs, file I/O). #[derive(Default)] @@ -77,6 +77,10 @@ pub struct Services { /// pasted equation from (#1297). `true` when the text and HTML are there; otherwise the copy's /// text goes through egui as usual. pub set_clipboard_rich: Option bool>>, + /// Desktop: publish one picture's pixels, HTML and text together without clearing formats. + pub set_clipboard_image: Option bool>>, + /// Whether the clipboard still contains this process's last copy. + pub clipboard_is_own: Option bool>>, /// Desktop: the RTF on the system clipboard, where the platform offers it (#687). pub clipboard_rtf: Option Option>>, /// Desktop: the names of the formats on the system clipboard (MIME types, Windows format diff --git a/crates/ui-egui/src/system_clipboard.rs b/crates/ui-egui/src/system_clipboard.rs index bbb9525f53..6af6fa66d8 100644 --- a/crates/ui-egui/src/system_clipboard.rs +++ b/crates/ui-egui/src/system_clipboard.rs @@ -11,6 +11,17 @@ use wordcraft_engine::cmd::paste::{MAX_PASTE_BYTES, MAX_PICTURE_BYTES}; use crate::{WordApp, paste_picture}; +/// Straight RGBA8 pixels for a native image copy. Decode limits are applied before allocation. +#[derive(Clone, Debug)] +pub struct CopyImage { + /// Width in pixels. + pub width: usize, + /// Height in pixels. + pub height: usize, + /// Raw uncompressed RGBA pixel bytes (4 bytes per pixel). + pub rgba: Vec, +} + /// The commands that paste the clipboard. pub(crate) fn is_paste(id: &str) -> bool { matches!(id, "edit.paste" | "edit.pasteText" | "edit.pasteMerge" | "edit.pasteSpecial") @@ -30,6 +41,11 @@ pub(crate) fn fill(app: &mut WordApp, id: &str, params: &mut Value) -> Option Option Option bool { if text.is_empty() { // A copied picture or shape has no text, only HTML (#2276): empty the clipboard's text, // else Paste would find the text copied before it and paste that instead of our copy. if !html.is_empty() { + if !(html.is_empty() && rtf.is_empty()) && app.services.set_clipboard_rich.as_ref().is_some_and(|f| f(text, html, rtf, mathml)) { + return true; + } ctx.copy_text(String::new()); } - return; + return false; } if !(html.is_empty() && rtf.is_empty()) && app.services.set_clipboard_rich.as_ref().is_some_and(|f| f(text, html, rtf, mathml)) { - return; + return true; } ctx.copy_text(text.to_string()); + false +} + +/// Return whether the command result `r` contains any copied payload (text, HTML, RTF, or MathML). +fn has_copied_content(r: &Value) -> bool { + let s = |k: &str| r.get(k).and_then(Value::as_str).unwrap_or(""); + !s("text").is_empty() || !s("html").is_empty() || !s("rtf").is_empty() || !s("mathml").is_empty() } /// Put what Copy or Cut returned on the system clipboard (see [`put`]). -pub(crate) fn put_result(app: &WordApp, ctx: &egui::Context, r: &Value) { +/// +/// When `r` contains no copied content (e.g. Copy on a collapsed selection), +/// this does nothing: it avoids overwriting external clipboard contents with +/// previously-copied fragments or modifying the published ownership state. +pub(crate) fn put_result(app: &mut WordApp, ctx: &egui::Context, r: &Value) { + if !has_copied_content(r) { + return; + } let s = |k: &str| r.get(k).and_then(Value::as_str).unwrap_or(""); - put(app, ctx, s("text"), s("html"), s("rtf"), s("mathml")); + app.clipboard_published = false; + if app.services.set_clipboard_image.is_some() + && let Some(res) = copied_image(app) + { + match res { + Ok(image) => { + let set = app.services.set_clipboard_image.as_ref().map(|f| f(&image, s("html"), s("text"))).unwrap_or(false); + if set { + app.clipboard_published = true; + return; + } + } + Err(e) => { + app.status(format!("Couldn't copy the picture: {e}")); + } + } + } + app.clipboard_published = put(app, ctx, s("text"), s("html"), s("rtf"), s("mathml")); +} + +/// Extract the single copied image from the clipboard fragment, if that is all that was copied. +fn copied_image(app: &WordApp) -> Option> { + use wordcraft_doc::{Block, para::InlineObject}; + let fragment = app.session.clipboard.as_ref()?; + let [Block::Para(para)] = fragment.blocks.as_slice() else { return None }; + let [InlineObject::Image { media, .. }] = para.objects.as_slice() else { return None }; + if para.text != wordcraft_doc::para::OBJ.to_string() { + return None; + } + let bytes = fragment.media.get(media).or_else(|| app.session.doc.media.get(media))?; + Some(match wordcraft_render::metafile_size(bytes) { + Some((w, h, _)) => { + let rect = wordcraft_geom::Rect::new(0.0, 0.0, w, h); + let items = [wordcraft_layout::display::Draw::Image { + rect, + media: media.clone(), + crop: [0.0; 4], + alpha: 1.0, + alt: String::new(), + fx: Default::default(), + decorative: false, + }]; + let doc = fragment.to_document(); + let image = wordcraft_render::render_items(&doc, &items, rect, 96.0 / 72.0, &Default::default()); + Ok(CopyImage { width: image.width as usize, height: image.height as usize, rgba: image.to_straight() }) + } + None => decode_image(bytes), + }) +} + +/// Decode raster image bytes into unpremultiplied RGBA8 pixels under bounded size limits. +fn decode_image(bytes: &[u8]) -> Result { + if bytes.len() as u64 > paste_picture::MAX_FILE_BYTES { + return Err("the picture file is larger than 200 MB".into()); + } + let reader = || image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format().map_err(|e| e.to_string()); + let (w, h) = reader()?.into_dimensions().map_err(|e| e.to_string())?; + let pixels = (w as usize).checked_mul(h as usize); + if w == 0 + || h == 0 + || w as usize > paste_picture::MAX_SIDE + || h as usize > paste_picture::MAX_SIDE + || pixels.is_none_or(|n| n > paste_picture::MAX_PIXELS) + { + return Err(format!("the picture is too large to copy ({w} × {h} pixels)")); + } + let mut limits = image::Limits::default(); + limits.max_image_width = Some(paste_picture::MAX_SIDE as u32); + limits.max_image_height = Some(paste_picture::MAX_SIDE as u32); + limits.max_alloc = Some((paste_picture::MAX_PIXELS as u64).saturating_mul(4)); + let mut reader = reader()?; + reader.limits(limits); + let rgba = reader.decode().map_err(|e| e.to_string())?.into_rgba8(); + Ok(CopyImage { width: w as usize, height: h as usize, rgba: rgba.into_raw() }) } /// Format names worth showing: not the clipboard protocol's own bookkeeping targets. @@ -265,7 +376,7 @@ mod tests { a.run("select.all", json!({})).unwrap(); let ctx = egui::Context::default(); let r = a.run("edit.copy", json!({})).unwrap(); - put_result(&a, &ctx, &r); + put_result(&mut a, &ctx, &r); let got_now = got.borrow().clone(); assert_eq!(got_now.len(), 1); assert!(got_now[0].0.contains("") && got_now[2].1 == "y=2x_s", "{got_now:?}"); } + + #[test] + fn copying_an_image_publishes_image_and_html_to_system_clipboard() { + let got_image = std::rc::Rc::new(std::cell::RefCell::new(Vec::<(usize, usize, String, String)>::new())); + let sink = got_image.clone(); + let services = Services { + set_clipboard_image: Some(Box::new(move |img, html, text| { + sink.borrow_mut().push((img.width, img.height, html.to_string(), text.to_string())); + true + })), + ..Default::default() + }; + let mut a = app(services); + let png = paste_picture::png_from_rgba(2, 2, vec![255; 16]).unwrap(); + let data = wordcraft_engine::cmd::insert::base64_encode(&png); + a.run("insert.picture", json!({"data": data})).unwrap(); + a.run("select.all", json!({})).unwrap(); + let ctx = egui::Context::default(); + let r = a.run("edit.copy", json!({})).unwrap(); + put_result(&mut a, &ctx, &r); + assert!(a.clipboard_published); + let got = got_image.borrow().clone(); + assert_eq!(got.len(), 1); + assert_eq!(got[0].0, 2); + assert_eq!(got[0].1, 2); + assert!(got[0].2.contains("::new())); + let sink = got_image.clone(); + let services = Services { + set_clipboard_image: Some(Box::new(move |img, html, text| { + sink.borrow_mut().push((img.width, img.height, html.to_string(), text.to_string())); + true + })), + ..Default::default() + }; + let mut a = app(services); + let png = paste_picture::png_from_rgba(2, 2, vec![255; 16]).unwrap(); + let data = wordcraft_engine::cmd::insert::base64_encode(&png); + a.run("insert.picture", json!({"data": data})).unwrap(); + a.run("select.all", json!({})).unwrap(); + let ctx = egui::Context::default(); + let r = a.run("edit.copy", json!({})).unwrap(); + put_result(&mut a, &ctx, &r); + assert!(a.clipboard_published); + assert_eq!(got_image.borrow().len(), 1); + + a.run("caret.docEnd", json!({})).unwrap(); + assert!(a.session.sel.is_collapsed()); + + let empty_r = a.run("edit.copy", json!({})).unwrap(); + put_result(&mut a, &ctx, &empty_r); + + assert_eq!(got_image.borrow().len(), 1, "empty copy must not call set_clipboard_image"); + assert!(a.clipboard_published, "empty copy must not change published-copy state"); + + let mut a2 = app(Services { set_clipboard_image: Some(Box::new(|_, _, _| true)), ..Default::default() }); + assert!(!a2.clipboard_published); + let empty_r2 = a2.run("edit.copy", json!({})).unwrap(); + put_result(&mut a2, &ctx, &empty_r2); + assert!(!a2.clipboard_published, "empty copy must not change published-copy state when false"); + } } diff --git a/crates/ui-egui/src/window_ui.rs b/crates/ui-egui/src/window_ui.rs index 125b2bd100..3d3e3b684f 100644 --- a/crates/ui-egui/src/window_ui.rs +++ b/crates/ui-egui/src/window_ui.rs @@ -253,6 +253,7 @@ impl WordApp { file_browser, info_editing, shown_document, + clipboard_published: _, } = self; let UiState { // App-wide: preferences, recent lists, and the settings the session owns while diff --git a/docs/gaps.md b/docs/gaps.md index 461f184e8f..f67cd79dff 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -2,7 +2,7 @@ > **CLI path update:** 2026-11-04 · Options before a non-Unicode input filename no longer make the CLI reject that filename; text option values still require Unicode; `run --file` and `run --script` retain native paths. No ranked gap or readiness estimate changes. -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-10 · **Change:** trivial (#4501 refactor regressions restored, #4683; no ranked gap changed); previously trivial (#19: ODT default language kept when styles are written from the model); previously trivial (#10 narrowed: a turned inline picture whose file keeps no room for the turn keeps its line to its frame, as in Word); previously trivial (Protected typing boundary lookup counts preceding objects once and indexes editable permission IDs (#3614); caret movement and enforcement policy are unchanged; previously trivial: View windows: several open documents and Switch Windows in the engine; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: text mini toolbar available with the right-click menu, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: tracked table/row/cell/section property changes record in WordCraft, narrowing gap 5; previously trivial: a document with many content controls saves in the time the controls take, #13; previously trivial: Format Page Numbers dialog carries Word's number formats and Continue from previous section / Start at, #1113; previously trivial: centred list labels after leading page breaks, #2964; previously trivial: fixed font inputs in four layout controls; previously trivial: a right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, goes to the next line with its text, #1840; previously trivial: Bullets and Numbering toggle off style-inherited lists at their effective level, including basedOn chains and numbered ListParagraph styles; other paragraphs and list definitions stay unchanged (related to #3459); previously trivial (gap 4: a float anchored right after a page break, before text, is drawn on the new page, #4262); previously trivial (Drawing Canvas members picked and moved on their own, #2637); previously trivial (gap 4: a float anchored on a later page of a long paragraph is drawn there, #4250); previously trivial (#29: typed `\int`, `\sum`… + Space wait for their limits, observed in Word for Windows on #4938, #4917); previously trivial (only the PDF sent to the printer leaves out link annotations; Save these pages as PDF keeps them, #4734; no ranked gap changed); previously trivial (print helpers erase loaded plaintext inputs before driver work, #5710); previously trivial (Windows print submissions use isolated helpers so a cancelled driver cannot block a retry, #5710); previously trivial (print cancellation remains available without a document; sending-boundary limitation clarified, #5710); previously trivial (gap 6: a print job waiting on its driver can be cancelled, #5710; no ranked gap changed); previously trivial (gap 6: the printer list no longer waits on printer drivers, #5710; no ranked gap changed); previously trivial (Page drawing indexes text-box warp lookups per paragraph (#3614)); previously trivial (built-in citation source lookups, #4888; current-main progress records retained); previously trivial (MATH construction reuse, #3630); previously trivial (DOCX `w:adjustRightInd` defaults true and is written in schema order); previously trivial (ink page lookups reuse scanned paragraph prefixes, #3614); previously trivial (#19: ODT settings for what the standard leaves open removed); previously trivial (#19: ODT element audit; files from other applications checked); previously trivial (#11: the dialogs of the mirrored Arabic interface read right to left: label-and-field rows, tables (list columns, the Models table), tile galleries and the Add/Remove arrows follow the reading direction, through one `rtl::Table` helper that draws exactly as before in English; no ranked gap closed, readiness estimates unchanged); previously trivial (#4: fonts that aren't installed are flagged in the font box and status bar); previously trivial (#19: ODT sections inside text boxes kept as read); previously trivial (#19: an ODT saved without edits keeps what WordCraft doesn't model); previously trivial (#19: ODT interpretation profile, WordCraft / LibreOffice / custom); previously trivial (#19: ODT form controls placed and multi-line; custom shapes keep their geometry); previously trivial (#19: ODT in-line frames placed against the text; template instantiation listed as left); previously trivial (#19: ODT charts kept as read; frame outlines; default header height); previously trivial (#19: ODT tables no longer gain repeated header rows); previously trivial (#19: ODT padding without a border, unequal columns, column breaks, picture-only lines); previously trivial (#19: ODT tables' margins and spacing, header spacing, pictures alone in a paragraph); previously trivial (#19: no LibreOffice template changes page count through a save); previously trivial (#19: ODT variables, emphasis marks, page backgrounds, fixed tables, default size); previously trivial (#19: ODT checked against LibreOffice's own templates: placeholders, first-page styles, unsized pages, metafile logos, `.ott`); previously trivial (#19: ODT at ~90%: custom shapes, cell formulas, macros kept, turned text, control sizes and buttons); previously trivial (#19 narrowed: ODT read and written nearly whole; estimate 18–27 h → 10–16 h); previously trivial (#10 narrowed: text in a turned text box is drawn turned with it); previously trivial (gap 19 narrowed: ODT heading numbering read and written); previously trivial (gap 19 narrowed: ODT table borders and padding read and written); previously trivial (gap 19 narrowed: ODT heading style looks read and written); previously trivial (gap 19 narrowed: ODT tab stops read and written); previously trivial (gap 19 narrowed: ODT character formatting read and written); previously trivial (gap 19 narrowed: ODT list formats read and written); previously trivial (gap 19 narrowed: ODT comments read and written); previously trivial (gap 19 narrowed: ODT footnotes and endnotes read and written); previously trivial (gap 19 narrowed: ODT headers and footers written, text fields and paragraph spacing read and written); previously trivial (#8: Options › Language lists Your languages and Add a language… replaces the Language packs table); previously trivial (#8: the missing-pack bar works on a fresh install and counts the caret's language); previously trivial (#8: Language pack languages are in Set Proofing Language, Review › Language and the status bar; built-in proofing is named as such); previously trivial (#20: layout resource caps and linear-time passes (#3867, #3866)); previously trivial (#3 narrowed: a pasted text box story is charged for the formatting it copies); previously trivial (#3 narrowed: a .doc table row keeps one override per cell); previously trivial (#3 narrowed: a .doc file's sections find their paragraphs by index); previously minor (#11: Arabic interface with mirrored shell landed, #1195; hi/id/pt-PT and Hebrew UI remain); previously trivial (#8: language-packs-2 is published and pinned: 75 packs, adding Danish, German (Germany, Austria, Switzerland), Esperanto, Estonian, Persian, Croatian, Hungarian, Norwegian (Bokmål, Nynorsk), Dutch and Swedish (Sweden, Finland); no ranked gap changed); previously trivial (#8: language-packs-1 is published and pinned, 61 packs: Lithuanian, Romanian, Catalan, French, Greek, Slovak, Serbian and Latvian install as Language packs; Dutch, German and the other compounding languages wait on craft-proof; no ranked gap changed); previously minor (#8: Language packs: every other language's spelling and hyphenation installs from File › Options › Language or the missing-pack bar, through the font store; Lithuanian and Romanian are available as a Language pack once language-packs-1 is published; Dutch, Catalan, French, Greek, Slovak, Serbian and Latvian packs wait on craft-proof engine support); previously trivial (gap 8: English spelling reads SCOWL 2026, one dictionary per English, #40, #520, #5205; no ranked gap changed);; previously trivial (DOCX table rows and cells inside selected alternate-content branches survive open and repeated saves (#5219); broader corpus qualification and readiness estimates unchanged); previously trivial (#26 narrowed: MHT opens and `w:altChunk` content is brought in on open; saving MHT remains) previously trivial (gap 8 points at craft-proof in craft-libs, its data in craft-i18n, #5202; no ranked gap changed); previously trivial (arrowheads keep their kind, width and length and are drawn at Word's sizes; no ranked gap changed); previously trivial (.doc default font from the stylesheet's standard font, #5066; no ranked gap changed); previously trivial (a middle or bottom cell of a row split across pages lines up on the first page; no ranked gap changed); previously trivial (tab leader dots spaced and placed as in Word; no ranked gap changed); previously trivial (a list level above counts its first number at the first deeper item; no ranked gap changed); previously trivial (only the PDF sent to the printer leaves out link annotations; Save these pages as PDF keeps them, #4734; no ranked gap changed); previously trivial (documents with links print: the print job leaves out link annotations, #4734; no ranked gap changed; previously trivial: aligned-copy review fixes retain the document axis through scrolling and include secondary selections (#4764)); previously trivial (connector rerouting indexes laid-out object positions once per batch (#3631); previously trivial (custom-property bookmark-link preservation, #4767); previously trivial (Relative font-size commands preserve mixed sizes in the selection (#4903); existing button steps and one-point shortcuts are unchanged; readiness estimates unchanged); previously trivial (Arabic Backspace removes one combining mark and keeps its base letter (#4757); previously trivial (note conversion reference-run membership uses one ordered walk, #4750); previously trivial (DOCX comment-ID save lookups); previously trivial (gap 19: RTF reads and writes WMF and EMF pictures, #4259); previously trivial (#4658 bounds nested Markdown reference-label work); previously trivial (HTML import keeps preformatted lines with CR or CRLF input newlines, #4810); previously trivial (Recipient labels continue across product-sized sheets instead of stopping after the first sheet (#4880)); previously trivial (View windows: several open documents and Switch Windows in the engine; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: text mini toolbar available with the right-click menu, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: tracked table/row/cell/section property changes record in WordCraft, narrowing gap 5; previously trivial: a document with many content controls saves in the time the controls take, #13; previously trivial: Format Page Numbers dialog carries Word's number formats and Continue from previous section / Start at, #1113; previously trivial: centred list labels after leading page breaks, #2964; previously trivial: fixed font inputs in four layout controls; previously trivial: a right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, goes to the next line with its text, #1840; previously trivial: Bullets and Numbering toggle off style-inherited lists at their effective level, including basedOn chains and numbered ListParagraph styles; other paragraphs and list definitions stay unchanged (related to #3459); previously trivial: Russian sorting keeps ё with е and recognises decomposed ё/й; previously trivial: #8: English dialects — en-GB, en-CA, en-AU… flag each other's spellings, #1281; previously trivial: #1: shape gradients and transparency, #1500; previously trivial: text typed into a content control takes the control's formatting; localized placeholder styles recognised; previously trivial: forms protection keeps its content controls: no inserting, Properties or Remove Content Control; previously trivial: clearing a no-match font query keeps the recent heading visible, #2068; previously trivial: line breaking: a slash opening a word travels whole to the next line, #2963; previously trivial: recipient list search and merged-only view, #1576; previously trivial: #2 impact restated: only ink rendering and OLE editing remain; previously trivial: #2 narrowed: native ink nested in groups and drawing canvases kept on save; previously trivial: opening a DOCX no longer copies its pictures; previously trivial: RTF export writes sections (gap 19); previously trivial: ODT export writes sections (gap 19); previously trivial: automatic Asian/Latin and Asian/number spacing laid out, #2358; previously trivial: hint-reliant CJK outlines; previously trivial: numbered headings, #1793; previously trivial: legacy outline, shadow, emboss and imprint text effects drawn, #2534; previously trivial: #8 narrowed: Indonesian proofing from the installed Hunspell dictionary, #498; previously trivial: glossary/building blocks closed; previously trivial: Split Cells and Convert Text to Table follow the Word check, #2592; previously trivial: Language dialog keeps inherited proofing language and no-proof choices (#2717); previously trivial: #29: a copied equation also goes in the MathML clipboard formats, #1297; previously trivial: #24: the Spike, Ctrl+F3 and Ctrl+Shift+F3; previously trivial: VML freeforms read and kept on save; previously trivial: consistent preferred cell widths; previously trivial: multi-paragraph field instructions no longer add blank lines; previously trivial: page-break-only list paragraphs hide their labels; previously trivial: floating-table overlap ignores empty line-break lines; previously trivial: copies keep their formatting on the clipboard as HTML, #1523; previously trivial: sample-text formulas on Enter, #1067; previously trivial: #29: copied equations as MathML, OMML open as #1297, #816; previously trivial: the Font list no longer keeps every previewed font in memory, #848; previously trivial: table column and row markers on the rulers, #700; previously trivial: table borders and the resize handle drag on the page, #217; previously trivial: formatting revisions landed, #41; previously trivial: Draw Table and Eraser landed, #303; previously minor: beta distance restated: ~15 points, ~150–230 h; previously: first version; every known shortfall from the 2026-10-10 re-measure, ranked) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-12 · **Change:** trivial (clipboard: a copied picture now reaches the system clipboard as PNG, with HTML where the host writes it; a copy of only shapes still stays in WordCraft, #6205); previously trivial (#4501 refactor regressions restored, #4683; no ranked gap changed); previously trivial (#19: ODT default language kept when styles are written from the model); previously trivial (#10 narrowed: a turned inline picture whose file keeps no room for the turn keeps its line to its frame, as in Word); previously trivial (Protected typing boundary lookup counts preceding objects once and indexes editable permission IDs (#3614); caret movement and enforcement policy are unchanged; previously trivial: View windows: several open documents and Switch Windows in the engine; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: text mini toolbar available with the right-click menu, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: tracked table/row/cell/section property changes record in WordCraft, narrowing gap 5; previously trivial: a document with many content controls saves in the time the controls take, #13; previously trivial: Format Page Numbers dialog carries Word's number formats and Continue from previous section / Start at, #1113; previously trivial: centred list labels after leading page breaks, #2964; previously trivial: fixed font inputs in four layout controls; previously trivial: a right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, goes to the next line with its text, #1840; previously trivial: Bullets and Numbering toggle off style-inherited lists at their effective level, including basedOn chains and numbered ListParagraph styles; other paragraphs and list definitions stay unchanged (related to #3459); previously trivial (gap 4: a float anchored right after a page break, before text, is drawn on the new page, #4262); previously trivial (Drawing Canvas members picked and moved on their own, #2637); previously trivial (gap 4: a float anchored on a later page of a long paragraph is drawn there, #4250); previously trivial (#29: typed `\int`, `\sum`… + Space wait for their limits, observed in Word for Windows on #4938, #4917); previously trivial (only the PDF sent to the printer leaves out link annotations; Save these pages as PDF keeps them, #4734; no ranked gap changed); previously trivial (print helpers erase loaded plaintext inputs before driver work, #5710); previously trivial (Windows print submissions use isolated helpers so a cancelled driver cannot block a retry, #5710); previously trivial (print cancellation remains available without a document; sending-boundary limitation clarified, #5710); previously trivial (gap 6: a print job waiting on its driver can be cancelled, #5710; no ranked gap changed); previously trivial (gap 6: the printer list no longer waits on printer drivers, #5710; no ranked gap changed); previously trivial (Page drawing indexes text-box warp lookups per paragraph (#3614)); previously trivial (built-in citation source lookups, #4888; current-main progress records retained); previously trivial (MATH construction reuse, #3630); previously trivial (DOCX `w:adjustRightInd` defaults true and is written in schema order); previously trivial (ink page lookups reuse scanned paragraph prefixes, #3614); previously trivial (#19: ODT settings for what the standard leaves open removed); previously trivial (#19: ODT element audit; files from other applications checked); previously trivial (#11: the dialogs of the mirrored Arabic interface read right to left: label-and-field rows, tables (list columns, the Models table), tile galleries and the Add/Remove arrows follow the reading direction, through one `rtl::Table` helper that draws exactly as before in English; no ranked gap closed, readiness estimates unchanged); previously trivial (#4: fonts that aren't installed are flagged in the font box and status bar); previously trivial (#19: ODT sections inside text boxes kept as read); previously trivial (#19: an ODT saved without edits keeps what WordCraft doesn't model); previously trivial (#19: ODT interpretation profile, WordCraft / LibreOffice / custom); previously trivial (#19: ODT form controls placed and multi-line; custom shapes keep their geometry); previously trivial (#19: ODT in-line frames placed against the text; template instantiation listed as left); previously trivial (#19: ODT charts kept as read; frame outlines; default header height); previously trivial (#19: ODT tables no longer gain repeated header rows); previously trivial (#19: ODT padding without a border, unequal columns, column breaks, picture-only lines); previously trivial (#19: ODT tables' margins and spacing, header spacing, pictures alone in a paragraph); previously trivial (#19: no LibreOffice template changes page count through a save); previously trivial (#19: ODT variables, emphasis marks, page backgrounds, fixed tables, default size); previously trivial (#19: ODT checked against LibreOffice's own templates: placeholders, first-page styles, unsized pages, metafile logos, `.ott`); previously trivial (#19: ODT at ~90%: custom shapes, cell formulas, macros kept, turned text, control sizes and buttons); previously trivial (#19 narrowed: ODT read and written nearly whole; estimate 18–27 h → 10–16 h); previously trivial (#10 narrowed: text in a turned text box is drawn turned with it); previously trivial (gap 19 narrowed: ODT heading numbering read and written); previously trivial (gap 19 narrowed: ODT table borders and padding read and written); previously trivial (gap 19 narrowed: ODT heading style looks read and written); previously trivial (gap 19 narrowed: ODT tab stops read and written); previously trivial (gap 19 narrowed: ODT character formatting read and written); previously trivial (gap 19 narrowed: ODT list formats read and written); previously trivial (gap 19 narrowed: ODT comments read and written); previously trivial (gap 19 narrowed: ODT footnotes and endnotes read and written); previously trivial (gap 19 narrowed: ODT headers and footers written, text fields and paragraph spacing read and written); previously trivial (#8: Options › Language lists Your languages and Add a language… replaces the Language packs table); previously trivial (#8: the missing-pack bar works on a fresh install and counts the caret's language); previously trivial (#8: Language pack languages are in Set Proofing Language, Review › Language and the status bar; built-in proofing is named as such); previously trivial (#20: layout resource caps and linear-time passes (#3867, #3866)); previously trivial (#3 narrowed: a pasted text box story is charged for the formatting it copies); previously trivial (#3 narrowed: a .doc table row keeps one override per cell); previously trivial (#3 narrowed: a .doc file's sections find their paragraphs by index); previously minor (#11: Arabic interface with mirrored shell landed, #1195; hi/id/pt-PT and Hebrew UI remain); previously trivial (#8: language-packs-2 is published and pinned: 75 packs, adding Danish, German (Germany, Austria, Switzerland), Esperanto, Estonian, Persian, Croatian, Hungarian, Norwegian (Bokmål, Nynorsk), Dutch and Swedish (Sweden, Finland); no ranked gap changed); previously trivial (#8: language-packs-1 is published and pinned, 61 packs: Lithuanian, Romanian, Catalan, French, Greek, Slovak, Serbian and Latvian install as Language packs; Dutch, German and the other compounding languages wait on craft-proof; no ranked gap changed); previously minor (#8: Language packs: every other language's spelling and hyphenation installs from File › Options › Language or the missing-pack bar, through the font store; Lithuanian and Romanian are available as a Language pack once language-packs-1 is published; Dutch, Catalan, French, Greek, Slovak, Serbian and Latvian packs wait on craft-proof engine support); previously trivial (gap 8: English spelling reads SCOWL 2026, one dictionary per English, #40, #520, #5205; no ranked gap changed);; previously trivial (DOCX table rows and cells inside selected alternate-content branches survive open and repeated saves (#5219); broader corpus qualification and readiness estimates unchanged); previously trivial (#26 narrowed: MHT opens and `w:altChunk` content is brought in on open; saving MHT remains) previously trivial (gap 8 points at craft-proof in craft-libs, its data in craft-i18n, #5202; no ranked gap changed); previously trivial (arrowheads keep their kind, width and length and are drawn at Word's sizes; no ranked gap changed); previously trivial (.doc default font from the stylesheet's standard font, #5066; no ranked gap changed); previously trivial (a middle or bottom cell of a row split across pages lines up on the first page; no ranked gap changed); previously trivial (tab leader dots spaced and placed as in Word; no ranked gap changed); previously trivial (a list level above counts its first number at the first deeper item; no ranked gap changed); previously trivial (only the PDF sent to the printer leaves out link annotations; Save these pages as PDF keeps them, #4734; no ranked gap changed); previously trivial (documents with links print: the print job leaves out link annotations, #4734; no ranked gap changed; previously trivial: aligned-copy review fixes retain the document axis through scrolling and include secondary selections (#4764)); previously trivial (connector rerouting indexes laid-out object positions once per batch (#3631); previously trivial (custom-property bookmark-link preservation, #4767); previously trivial (Relative font-size commands preserve mixed sizes in the selection (#4903); existing button steps and one-point shortcuts are unchanged; readiness estimates unchanged); previously trivial (Arabic Backspace removes one combining mark and keeps its base letter (#4757); previously trivial (note conversion reference-run membership uses one ordered walk, #4750); previously trivial (DOCX comment-ID save lookups); previously trivial (gap 19: RTF reads and writes WMF and EMF pictures, #4259); previously trivial (#4658 bounds nested Markdown reference-label work); previously trivial (HTML import keeps preformatted lines with CR or CRLF input newlines, #4810); previously trivial (Recipient labels continue across product-sized sheets instead of stopping after the first sheet (#4880)); previously trivial (View windows: several open documents and Switch Windows in the engine; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: text mini toolbar available with the right-click menu, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: tracked table/row/cell/section property changes record in WordCraft, narrowing gap 5; previously trivial: a document with many content controls saves in the time the controls take, #13; previously trivial: Format Page Numbers dialog carries Word's number formats and Continue from previous section / Start at, #1113; previously trivial: centred list labels after leading page breaks, #2964; previously trivial: fixed font inputs in four layout controls; previously trivial: a right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, goes to the next line with its text, #1840; previously trivial: Bullets and Numbering toggle off style-inherited lists at their effective level, including basedOn chains and numbered ListParagraph styles; other paragraphs and list definitions stay unchanged (related to #3459); previously trivial: Russian sorting keeps ё with е and recognises decomposed ё/й; previously trivial: #8: English dialects — en-GB, en-CA, en-AU… flag each other's spellings, #1281; previously trivial: #1: shape gradients and transparency, #1500; previously trivial: text typed into a content control takes the control's formatting; localized placeholder styles recognised; previously trivial: forms protection keeps its content controls: no inserting, Properties or Remove Content Control; previously trivial: clearing a no-match font query keeps the recent heading visible, #2068; previously trivial: line breaking: a slash opening a word travels whole to the next line, #2963; previously trivial: recipient list search and merged-only view, #1576; previously trivial: #2 impact restated: only ink rendering and OLE editing remain; previously trivial: #2 narrowed: native ink nested in groups and drawing canvases kept on save; previously trivial: opening a DOCX no longer copies its pictures; previously trivial: RTF export writes sections (gap 19); previously trivial: ODT export writes sections (gap 19); previously trivial: automatic Asian/Latin and Asian/number spacing laid out, #2358; previously trivial: hint-reliant CJK outlines; previously trivial: numbered headings, #1793; previously trivial: legacy outline, shadow, emboss and imprint text effects drawn, #2534; previously trivial: #8 narrowed: Indonesian proofing from the installed Hunspell dictionary, #498; previously trivial: glossary/building blocks closed; previously trivial: Split Cells and Convert Text to Table follow the Word check, #2592; previously trivial: Language dialog keeps inherited proofing language and no-proof choices (#2717); previously trivial: #29: a copied equation also goes in the MathML clipboard formats, #1297; previously trivial: #24: the Spike, Ctrl+F3 and Ctrl+Shift+F3; previously trivial: VML freeforms read and kept on save; previously trivial: consistent preferred cell widths; previously trivial: multi-paragraph field instructions no longer add blank lines; previously trivial: page-break-only list paragraphs hide their labels; previously trivial: floating-table overlap ignores empty line-break lines; previously trivial: copies keep their formatting on the clipboard as HTML, #1523; previously trivial: sample-text formulas on Enter, #1067; previously trivial: #29: copied equations as MathML, OMML open as #1297, #816; previously trivial: the Font list no longer keeps every previewed font in memory, #848; previously trivial: table column and row markers on the rulers, #700; previously trivial: table borders and the resize handle drag on the page, #217; previously trivial: formatting revisions landed, #41; previously trivial: Draw Table and Eraser landed, #303; previously minor: beta distance restated: ~15 points, ~150–230 h; previously: first version; every known shortfall from the 2026-10-10 re-measure, ranked) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4 > **Page Setup update:** 2026-11-07 · Page Setup number boxes keep long input inside the field, including accepted margin values after focus leaves (#5650); accepted ranges and readiness estimates are unchanged. > **Floating anchor row segments:** 2026-11-07 · A floating anchor after a manual page/column break counts visible content on the far side of the same wrapped row. Marker-only cover anchors retain their previous-page rule. Synthetic picture spacing, placement and history controls; no new native Word measurement. Readiness estimates unchanged. @@ -147,8 +147,9 @@ The same gaps grouped the way the parity documents are, for agents working in on (#816), and a lone equation also in the MathML clipboard formats on Windows and macOS (#1297; pasting into Word/LibreOffice not yet verified); RTF is written on Windows, macOS and Wayland, while an X11 copy still carries text and HTML only (arboard owns the selection there); a - copy of only pictures or shapes carries neither, so WordCraft pastes its own copy. Paste - reads RTF on all four. + copy of only pictures puts its PNG (and HTML where the host writes it) on the clipboard, while + a copy of only shapes carries neither, so WordCraft pastes its own copy. Paste reads RTF on + all four. Options › Animation effects › Use system setting reads macOS (Reduce motion) and the Linux/BSD desktops (`apps/wordcraft/src/animations.rs`) but hasn't been tried on a Mac or in a real GNOME or KDE session yet. @@ -197,6 +198,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text | Date | Change | Summary | |---|---|---| +| 2026-11-12 | trivial | Clipboard: a copied picture is published to the system clipboard as PNG, with HTML where the host writes it, and WordCraft's own paste keeps the original fragment; a copy of only shapes stays in WordCraft (#6205). Native external-app paste remains untested. | | 2026-11-04 | trivial | #4501 refactor regressions restored: per-section header/footer grid, ODT default font, link tooltip (#4683); no ranked gap changed; readiness estimates unchanged | | 2026-11-08 | trivial | #10 narrowed: a turned inline picture with no recorded effect extent keeps its line to its frame (exchanged near a quarter turn in Word 2013+ layout), cut at the line; gap stays open | | 2026-11-08 | trivial | #4 narrowed: a cell's last Normal paragraph drops its contextual space after, the end-of-cell mark counting as a Normal paragraph (#5450) | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index d2bb4da117..ed89ed7f0a 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity with Microsoft Word -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-10 · **Change:** trivial (Save As on Linux: the desktop portal's Save dialog reports the file type picked, updating the extension so saving as PDF writes a .pdf, #6180); previously trivial (Vertical scrollbar track: clicking above the elevator moves one screen up and clicking below it moves one screen down, as in Word (#5853)); previously trivial (a press the canvas handles, such as Ctrl+click on a link, no longer also shows the link tooltip that frame, #4683); previously trivial (the window moves by its title bar behind a modal dialog, as in Word for Mac, #5124); previously trivial (pointer zoom stretches page rasters until it stops); previously trivial (dark-theme interface text on Linux and the BSDs no longer looks semi-bold); previously trivial (the document's scroll bars show wherever the pointer is, not only at the window's edge, #5746); previously trivial (Protected typing boundary lookup counts preceding objects once and indexes editable permission IDs (#3614); caret movement and enforcement policy are unchanged; previously trivial: Custom Document Properties dialog from File › Info › Properties › Advanced Properties…, #2982; previously trivial: View › Window › New Window opens another window on the document, each with its own caret and view; previously trivial: mail merge: First Record, Last Record and a record number box in Preview Results; Finish & Merge asks which records to merge or print, #3028; previously trivial: selection bar for right-to-left paragraphs and table rows; previously trivial: read only and comments-only protection grey out edits; previously trivial: the Font dialog previews "NaN" or "inf" in the Size box at 12 pt, #3663; previously trivial: File › Options disables the User name field while Restrict Editing is active; previously trivial: while editing a header or footer, a click in the other one edits it there without scrolling; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: Insert Table of Figures dialog: any caption label, #3013; previously trivial: Home › Underline drop-down shows its lines, #2738; previously trivial: the text context menu includes the formatting mini toolbar, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: the scrollbar page tip stays on one line as the page number grows, #3341; previously trivial: File › Home and New: templates and recent documents are buttons named for screen readers, #3176; previously trivial: forms protection greys out the Developer tab's control buttons and Properties; previously trivial: AltGr doesn't open KeyTips, #2388; previously trivial: closing the header or footer puts the caret back where it was in the body, #3331; previously trivial: Format Page Numbers dialog: number format and Continue from previous section / Start at, #1113; previously trivial: inline pictures drag to a dashed insertion cursor and stay inline, #2233, #2234; previously trivial: Save Changes prompt: a text file saved over itself closes, #2376; previously trivial: the equation being edited is framed as in Word: an outline as tall as its line, a grip, an options strip that opens its menu, and its current argument shaded; previously trivial: the table handles show while the caret is in the table, #2428; previously trivial: legacy menu keys, #1697; previously trivial: Shape Fill › Gradient and the Format Shape pane, #1500; previously trivial: Focus fills the screen, and Full Screen View shows the pages alone, #1678; previously trivial: the text pointer over the page is drawn black or white on Windows, #1746; previously trivial: a click in the header/footer band from the body no longer scrolls to the body text, #2103; previously trivial: File › Recover follows the app theme, #3243; previously trivial: long navigation headings wrap onto further lines within the pane, #3015; previously trivial: clearing a no-match font query keeps the recent heading visible, #2068; previously trivial: dragging the vertical scrollbar names the page at the top of the window, #2551; previously trivial: Add Font imports every selected font file, #1789); previously trivial (dragging an In Line with Text object shows a bold insertion cursor, as in Word, instead of a faint dashed one, #4195); previously trivial (the shapes, pictures and text boxes inside a Drawing Canvas are picked, moved and resized on their own, #2637); previously trivial (Shape Format › Size shows the interface unit and takes any typed unit, #4196); previously trivial (over a turned picture, shape or text box the resize arrows turn with it, #3932); previously trivial (the status bar's count is words by default and can be characters with or without spaces, chosen from its right-click menu or File › Options › Display and kept between runs, #2797); previously trivial (Linux display server setting in File › Options › Advanced, #2184); previously trivial (dialogs are modal except Find and Replace, Symbol, Mark Index Entry, Cross-reference and Insert Merge Field, and a press beside one shakes it, #3859); previously trivial (showing the Format Shape pane leaves a gradient angle above 359.9° as it is, #3955); previously trivial (Return on File › Print prints, as Word's default Print button does); previously trivial (N-up and booklet printing, #641; readiness unchanged); previously trivial (missing fonts flagged in the font box and status bar, read from what layout drew; metric-compatible substitutes and symbol fonts not flagged); previously minor (Options › Language redesign: Your languages, Add a language…, Set as default; the Dictionaries folder moved from Proofing); previously trivial (a long comment's card and balloon stop at ten lines, #3382); previously minor (Arabic mirrored interface: ribbon, panes, File page, dialogs, menus; document canvas independent, #1195); previously trivial (Alt, F badges the Backstage pages; Alt, F, P and V open Print, #4960); previously trivial (View › Macros opens a Macros dialog with Run, Delete and Record, #4327); previously trivial (aligned-copy review fixes retain the document axis through scrolling and include secondary selections (#4764)); previously trivial (Table Properties: row, column and cell settings apply to the selected rows, columns and cells; mixed row check boxes, #4857); previously trivial (Insert › Shapes shows the basic shapes as a grid of drawn icon tiles, #4349); previously trivial (File › Options › Proofing › AutoCorrect Options opens with no document open, #4585); previously trivial (the Shading buttons show the last picked colour, #4412); previously trivial (a blank User Name in File › Options stays blank after a restart, #4368); previously trivial (window size falls back to the screen rectangle when the reported inner size is invalid; equation symbol tooltips no longer repeat a missing glyph's name); previously trivial (window titles and suggested file names omit NUL characters, #3634); previously trivial (Recipient labels continue across product-sized sheets instead of stopping after the first sheet (#4880)); previously trivial (Custom Document Properties dialog from File › Info › Properties › Advanced Properties…, #2982; previously trivial: View › Window › New Window opens another window on the document, each with its own caret and view; previously trivial: mail merge: First Record, Last Record and a record number box in Preview Results; Finish & Merge asks which records to merge or print, #3028; previously trivial: selection bar for right-to-left paragraphs and table rows; previously trivial: read only and comments-only protection grey out edits; previously trivial: the Font dialog previews "NaN" or "inf" in the Size box at 12 pt, #3663; previously trivial: File › Options disables the User name field while Restrict Editing is active; previously trivial: while editing a header or footer, a click in the other one edits it there without scrolling; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: Insert Table of Figures dialog: any caption label, #3013; previously trivial: Home › Underline drop-down shows its lines, #2738; previously trivial: the text context menu includes the formatting mini toolbar, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: the scrollbar page tip stays on one line as the page number grows, #3341; previously trivial: File › Home and New: templates and recent documents are buttons named for screen readers, #3176; previously trivial: forms protection greys out the Developer tab's control buttons and Properties; previously trivial: AltGr doesn't open KeyTips, #2388; previously trivial: closing the header or footer puts the caret back where it was in the body, #3331; previously trivial: Format Page Numbers dialog: number format and Continue from previous section / Start at, #1113; previously trivial: inline pictures drag to a dashed insertion cursor and stay inline, #2233, #2234; previously trivial: Save Changes prompt: a text file saved over itself closes, #2376; previously trivial: the equation being edited is framed as in Word: an outline as tall as its line, a grip, an options strip that opens its menu, and its current argument shaded; previously trivial: the table handles show while the caret is in the table, #2428; previously trivial: legacy menu keys, #1697; previously trivial: Shape Fill › Gradient and the Format Shape pane, #1500; previously trivial: Focus fills the screen, and Full Screen View shows the pages alone, #1678; previously trivial: the text pointer over the page is drawn black or white on Windows, #1746; previously trivial: a click in the header/footer band from the body no longer scrolls to the body text, #2103; previously trivial: File › Recover follows the app theme, #3243; previously trivial: long navigation headings wrap onto further lines within the pane, #3015; previously trivial: clearing a no-match font query keeps the recent heading visible, #2068; previously trivial: dragging the vertical scrollbar names the page at the top of the window, #2551; previously trivial: Add Font imports every selected font file, #1789); previously trivial (File › Close keeps the window, #1712; previously trivial: the Spike: Ctrl+F3 and Ctrl+Shift+F3; previously trivial: Ctrl+wheel zoom no longer scrolls the document, #1743; previously trivial: a mouse drag on a table leaves the view where it is, #1738; previously trivial: numbered headings, #1793; previously trivial: Navigation Find exposes Results, #2096; previously trivial: the tab strip never draws tabs over Comments / Editing / Share, #2026; previously trivial: Columns on selected text, #2024; previously trivial: Different First Page headers reachable from page 1, #2826; previously trivial: a copied equation also goes in the clipboard's MathML formats, #1297; previously trivial: Read Mode keeps the keyboard, shows whole columns and keeps text clear of the page-turn bar, #1772); previously trivial: font list entries of tall-ascent fonts sit in their row, not cut off, #2570); previously trivial: Split Cells and Convert Text to Table dialogs follow Word's merged-cell limits and Initial column width, #2592; previously trivial: a new source's Tag is made like Word's, three letters of the author and two digits of the year with a number added when taken, and an edit keeps the Tag, #2094; previously trivial: Web Layout text fills the window width, #1876; previously trivial: Language dialog keeps inherited proofing language and no-proof choices (#2717)); previously trivial: comment balloons readable in the dark theme, #2045; previously trivial: Recently Used Fonts section at the top of the font list, #2068; previously trivial: web preferences kept between visits, #2132; previously trivial: dialog close control: a Windows-style box at the title bar's right end, the whole box clickable, red on hover, #1885); previously trivial (Modify Table Style formats every table style part, #714); previously trivial: a click on the ribbon chrome hands the keyboard to the page in the same frame, #1093 follow-up; previously trivial: Page Setup vertical alignment, #1320; previously trivial: the app opens on the Home tab every launch, as in Word; previously trivial: no document behind the Start screen, #1129; previously trivial: equation pictures share a few textures, #1002; previously trivial: selection bar in the left margin, #856; previously trivial: table column and row markers on the rulers, #700; previously trivial: table borders and the resize handle drag on the page, #217; previously major: first version; ribbon, dialogs, shortcuts and on-canvas interaction measured from `crates/ui-egui` and the command registry) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-12 · **Change:** trivial (clipboard: a copied picture reaches the system clipboard as PNG, with HTML where the host writes it, while a copy of only shapes stays in WordCraft, #6205); previously trivial (Save As on Linux: the desktop portal's Save dialog reports the file type picked, updating the extension so saving as PDF writes a .pdf, #6180); previously trivial (Vertical scrollbar track: clicking above the elevator moves one screen up and clicking below it moves one screen down, as in Word (#5853)); previously trivial (a press the canvas handles, such as Ctrl+click on a link, no longer also shows the link tooltip that frame, #4683); previously trivial (the window moves by its title bar behind a modal dialog, as in Word for Mac, #5124); previously trivial (pointer zoom stretches page rasters until it stops); previously trivial (dark-theme interface text on Linux and the BSDs no longer looks semi-bold); previously trivial (the document's scroll bars show wherever the pointer is, not only at the window's edge, #5746); previously trivial (Protected typing boundary lookup counts preceding objects once and indexes editable permission IDs (#3614); caret movement and enforcement policy are unchanged; previously trivial: Custom Document Properties dialog from File › Info › Properties › Advanced Properties…, #2982; previously trivial: View › Window › New Window opens another window on the document, each with its own caret and view; previously trivial: mail merge: First Record, Last Record and a record number box in Preview Results; Finish & Merge asks which records to merge or print, #3028; previously trivial: selection bar for right-to-left paragraphs and table rows; previously trivial: read only and comments-only protection grey out edits; previously trivial: the Font dialog previews "NaN" or "inf" in the Size box at 12 pt, #3663; previously trivial: File › Options disables the User name field while Restrict Editing is active; previously trivial: while editing a header or footer, a click in the other one edits it there without scrolling; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: Insert Table of Figures dialog: any caption label, #3013; previously trivial: Home › Underline drop-down shows its lines, #2738; previously trivial: the text context menu includes the formatting mini toolbar, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: the scrollbar page tip stays on one line as the page number grows, #3341; previously trivial: File › Home and New: templates and recent documents are buttons named for screen readers, #3176; previously trivial: forms protection greys out the Developer tab's control buttons and Properties; previously trivial: AltGr doesn't open KeyTips, #2388; previously trivial: closing the header or footer puts the caret back where it was in the body, #3331; previously trivial: Format Page Numbers dialog: number format and Continue from previous section / Start at, #1113; previously trivial: inline pictures drag to a dashed insertion cursor and stay inline, #2233, #2234; previously trivial: Save Changes prompt: a text file saved over itself closes, #2376; previously trivial: the equation being edited is framed as in Word: an outline as tall as its line, a grip, an options strip that opens its menu, and its current argument shaded; previously trivial: the table handles show while the caret is in the table, #2428; previously trivial: legacy menu keys, #1697; previously trivial: Shape Fill › Gradient and the Format Shape pane, #1500; previously trivial: Focus fills the screen, and Full Screen View shows the pages alone, #1678; previously trivial: the text pointer over the page is drawn black or white on Windows, #1746; previously trivial: a click in the header/footer band from the body no longer scrolls to the body text, #2103; previously trivial: File › Recover follows the app theme, #3243; previously trivial: long navigation headings wrap onto further lines within the pane, #3015; previously trivial: clearing a no-match font query keeps the recent heading visible, #2068; previously trivial: dragging the vertical scrollbar names the page at the top of the window, #2551; previously trivial: Add Font imports every selected font file, #1789); previously trivial (dragging an In Line with Text object shows a bold insertion cursor, as in Word, instead of a faint dashed one, #4195); previously trivial (the shapes, pictures and text boxes inside a Drawing Canvas are picked, moved and resized on their own, #2637); previously trivial (Shape Format › Size shows the interface unit and takes any typed unit, #4196); previously trivial (over a turned picture, shape or text box the resize arrows turn with it, #3932); previously trivial (the status bar's count is words by default and can be characters with or without spaces, chosen from its right-click menu or File › Options › Display and kept between runs, #2797); previously trivial (Linux display server setting in File › Options › Advanced, #2184); previously trivial (dialogs are modal except Find and Replace, Symbol, Mark Index Entry, Cross-reference and Insert Merge Field, and a press beside one shakes it, #3859); previously trivial (showing the Format Shape pane leaves a gradient angle above 359.9° as it is, #3955); previously trivial (Return on File › Print prints, as Word's default Print button does); previously trivial (N-up and booklet printing, #641; readiness unchanged); previously trivial (missing fonts flagged in the font box and status bar, read from what layout drew; metric-compatible substitutes and symbol fonts not flagged); previously minor (Options › Language redesign: Your languages, Add a language…, Set as default; the Dictionaries folder moved from Proofing); previously trivial (a long comment's card and balloon stop at ten lines, #3382); previously minor (Arabic mirrored interface: ribbon, panes, File page, dialogs, menus; document canvas independent, #1195); previously trivial (Alt, F badges the Backstage pages; Alt, F, P and V open Print, #4960); previously trivial (View › Macros opens a Macros dialog with Run, Delete and Record, #4327); previously trivial (aligned-copy review fixes retain the document axis through scrolling and include secondary selections (#4764)); previously trivial (Table Properties: row, column and cell settings apply to the selected rows, columns and cells; mixed row check boxes, #4857); previously trivial (Insert › Shapes shows the basic shapes as a grid of drawn icon tiles, #4349); previously trivial (File › Options › Proofing › AutoCorrect Options opens with no document open, #4585); previously trivial (the Shading buttons show the last picked colour, #4412); previously trivial (a blank User Name in File › Options stays blank after a restart, #4368); previously trivial (window size falls back to the screen rectangle when the reported inner size is invalid; equation symbol tooltips no longer repeat a missing glyph's name); previously trivial (window titles and suggested file names omit NUL characters, #3634); previously trivial (Recipient labels continue across product-sized sheets instead of stopping after the first sheet (#4880)); previously trivial (Custom Document Properties dialog from File › Info › Properties › Advanced Properties…, #2982; previously trivial: View › Window › New Window opens another window on the document, each with its own caret and view; previously trivial: mail merge: First Record, Last Record and a record number box in Preview Results; Finish & Merge asks which records to merge or print, #3028; previously trivial: selection bar for right-to-left paragraphs and table rows; previously trivial: read only and comments-only protection grey out edits; previously trivial: the Font dialog previews "NaN" or "inf" in the Size box at 12 pt, #3663; previously trivial: File › Options disables the User name field while Restrict Editing is active; previously trivial: while editing a header or footer, a click in the other one edits it there without scrolling; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: Insert Table of Figures dialog: any caption label, #3013; previously trivial: Home › Underline drop-down shows its lines, #2738; previously trivial: the text context menu includes the formatting mini toolbar, #2959; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: the scrollbar page tip stays on one line as the page number grows, #3341; previously trivial: File › Home and New: templates and recent documents are buttons named for screen readers, #3176; previously trivial: forms protection greys out the Developer tab's control buttons and Properties; previously trivial: AltGr doesn't open KeyTips, #2388; previously trivial: closing the header or footer puts the caret back where it was in the body, #3331; previously trivial: Format Page Numbers dialog: number format and Continue from previous section / Start at, #1113; previously trivial: inline pictures drag to a dashed insertion cursor and stay inline, #2233, #2234; previously trivial: Save Changes prompt: a text file saved over itself closes, #2376; previously trivial: the equation being edited is framed as in Word: an outline as tall as its line, a grip, an options strip that opens its menu, and its current argument shaded; previously trivial: the table handles show while the caret is in the table, #2428; previously trivial: legacy menu keys, #1697; previously trivial: Shape Fill › Gradient and the Format Shape pane, #1500; previously trivial: Focus fills the screen, and Full Screen View shows the pages alone, #1678; previously trivial: the text pointer over the page is drawn black or white on Windows, #1746; previously trivial: a click in the header/footer band from the body no longer scrolls to the body text, #2103; previously trivial: File › Recover follows the app theme, #3243; previously trivial: long navigation headings wrap onto further lines within the pane, #3015; previously trivial: clearing a no-match font query keeps the recent heading visible, #2068; previously trivial: dragging the vertical scrollbar names the page at the top of the window, #2551; previously trivial: Add Font imports every selected font file, #1789); previously trivial (File › Close keeps the window, #1712; previously trivial: the Spike: Ctrl+F3 and Ctrl+Shift+F3; previously trivial: Ctrl+wheel zoom no longer scrolls the document, #1743; previously trivial: a mouse drag on a table leaves the view where it is, #1738; previously trivial: numbered headings, #1793; previously trivial: Navigation Find exposes Results, #2096; previously trivial: the tab strip never draws tabs over Comments / Editing / Share, #2026; previously trivial: Columns on selected text, #2024; previously trivial: Different First Page headers reachable from page 1, #2826; previously trivial: a copied equation also goes in the clipboard's MathML formats, #1297; previously trivial: Read Mode keeps the keyboard, shows whole columns and keeps text clear of the page-turn bar, #1772); previously trivial: font list entries of tall-ascent fonts sit in their row, not cut off, #2570); previously trivial: Split Cells and Convert Text to Table dialogs follow Word's merged-cell limits and Initial column width, #2592; previously trivial: a new source's Tag is made like Word's, three letters of the author and two digits of the year with a number added when taken, and an edit keeps the Tag, #2094; previously trivial: Web Layout text fills the window width, #1876; previously trivial: Language dialog keeps inherited proofing language and no-proof choices (#2717)); previously trivial: comment balloons readable in the dark theme, #2045; previously trivial: Recently Used Fonts section at the top of the font list, #2068; previously trivial: web preferences kept between visits, #2132; previously trivial: dialog close control: a Windows-style box at the title bar's right end, the whole box clickable, red on hover, #1885); previously trivial (Modify Table Style formats every table style part, #714); previously trivial: a click on the ribbon chrome hands the keyboard to the page in the same frame, #1093 follow-up; previously trivial: Page Setup vertical alignment, #1320; previously trivial: the app opens on the Home tab every launch, as in Word; previously trivial: no document behind the Start screen, #1129; previously trivial: equation pictures share a few textures, #1002; previously trivial: selection bar in the left margin, #856; previously trivial: table column and row markers on the rulers, #700; previously trivial: table borders and the resize handle drag on the page, #217; previously major: first version; ribbon, dialogs, shortcuts and on-canvas interaction measured from `crates/ui-egui` and the command registry) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4 > **Page Setup update:** 2026-11-07 · Page Setup number boxes keep long input inside the field, including accepted margin values after focus leaves (#5650); accepted ranges and readiness estimates are unchanged. @@ -128,6 +128,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text | Date | Change | Summary | |---|---|---| +| 2026-11-12 | trivial | Clipboard: a copied picture is published as PNG (and HTML where the host writes it); WordCraft's own paste still keeps the original fragment, and a copy of only shapes carries no HTML or RTF (#6205). Native external-app paste remains untested. | | 2026-11-07 | trivial | Vertical scrollbar track: clicking above the elevator moves one screen up and clicking below it moves one screen down, as in Word, instead of jumping to that position in the document (#5853) | | 2026-11-04 | trivial | Canvas: a press the canvas handles itself (Ctrl+click on a link, switching into a header or footer, equation entry) skips the link tooltip that frame; hovering shows it again; a regression from the #4501 refactor (#4683) | | 2026-11-07 | trivial | Page Setup also bounds the unfocused margin display after a long numeric paste; the accepted value is retained (#5650). | @@ -143,7 +144,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text | 2026-11-01 | trivial | Rulers: the spaces between text columns are shaded on the horizontal ruler (Print Layout, in the main text outside tables, with the selection in one section); dragging an edge changes the spacing; equal columns stay equal, as in Word for Mac (#5197) | | 2026-10-31 | trivial | Behind a modal dialog the window still moves by its title bar, as in Word for Mac, where WordCraft draws the title bar itself; a drag on the dialog where it reaches over the title bar moves only the dialog (#5124) | | 2026-10-31 | trivial | Dialogs are modal (#3859): while one is open, clicks on the ribbon, File or the page, typing and shortcuts do nothing, as in Word. Find and Replace, Symbol, Mark Index Entry, Cross-reference and Insert Merge Field stay modeless, as in Word for Mac. A press beside a modal dialog shakes it a little, or flashes its border with animation effects off, so it is clear why nothing behind it reacts | -| 2026-10-17 | trivial | Copy and Cut put RTF beside the text and HTML on the system clipboard, for programs that read RTF rather than HTML (Windows "Rich Text Format", macOS `public.rtf`, Wayland `text/rtf`; an X11 copy stays text and HTML, since arboard owns the selection there; a copy of only pictures or shapes carries no HTML or RTF, so pasting it back keeps every detail); Paste reads another program's RTF on macOS and X11 too, as on Windows and Wayland | +| 2026-10-17 | trivial | Copy and Cut put RTF beside the text and HTML on the system clipboard, for programs that read RTF rather than HTML (Windows "Rich Text Format", macOS `public.rtf`, Wayland `text/rtf`; an X11 copy stays text and HTML, since arboard owns the selection there; a copy of only pictures puts its PNG (and HTML where the host writes it) on the clipboard, while a copy of only shapes carries no HTML or RTF, so pasting it back keeps every detail); Paste reads another program's RTF on macOS and X11 too, as on Windows and Wayland | | 2026-11-04 | trivial | Table Sort rejects malformed or nonexistent explicit columns before mutation; valid columns, the omitted-column default and history are retained (#5531). Readiness estimates unchanged. | | 2026-11-03 | trivial | Comments: a long comment's card, balloon and fields stop at ten lines; the fields scroll, and a balloon that isn't selected shows the first ten lines of the comment and of each reply (#3382) | | 2026-11-03 | trivial | Over a turned picture, shape or text box, the pointer on a resize handle shows the arrow along which that handle resizes: turned 90°, the handle now at the top shows an up-down arrow (it showed left-right), turned 45° the middle handles show diagonal ones; also while the handle is dragged (#3932) |