From 49e777cce500c7464a8ebf0b68674f492319fb3e Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Tue, 10 Nov 2026 20:59:58 -0300 Subject: [PATCH 01/13] Clipboard: transfer copied images to system clipboard and preserve media across internal paste (#6205) --- apps/wordcraft/src/clipboard.rs | 192 ++++++++++++++++++++++++- apps/wordcraft/src/main.rs | 2 + crates/doc/src/edit.rs | 50 ++++++- crates/doc/src/edit/tests.rs | 2 +- crates/engine/src/cmd/column.rs | 3 +- crates/engine/src/cmd/edit.rs | 5 +- crates/engine/src/cmd/tools/actions.rs | 4 +- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/keys/canvas.rs | 8 +- crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/services.rs | 6 +- crates/ui-egui/src/system_clipboard.rs | 160 +++++++++++++++++++-- crates/ui-egui/src/window_ui.rs | 1 + 13 files changed, 415 insertions(+), 21 deletions(-) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 95ec1a35c0..daf6d2b49d 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -68,7 +68,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 +82,50 @@ 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 +} + +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() +} + /// The clipboard's text. pub fn text() -> Option { open()?.get_text().ok() @@ -180,6 +227,36 @@ mod platform { get_mime_types_ordered(ClipboardType::Regular, Seat::Unspecified).unwrap_or_default() } + const OWNER_MIME: &str = "application/x-wordcraft-owner"; + + 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); + + pub fn record_own() { + if !wayland() { + let win = x11::owner_window().unwrap_or(0); + X11_OWNER.store(win, std::sync::atomic::Ordering::Relaxed); + } + } + + 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() @@ -206,6 +283,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) => { @@ -215,6 +293,35 @@ mod platform { } } + 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 + } + } + } + + 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) {} @@ -341,6 +448,13 @@ mod platform { let reply = r.convert(target, cap, true)?; (reply.type_ != incr).then_some(reply.value) } + + 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) + } } #[cfg(test)] @@ -415,6 +529,20 @@ mod platform { Ok(out) } + const OWNER_FORMAT: &str = "WordCraft Copy Owner"; + + 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(), &[1u8]); + } + + 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 }; + raw::is_format_avail(format.get()) + } + pub fn can_set() -> bool { true } @@ -424,6 +552,28 @@ mod platform { false } + pub fn set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) -> bool { + false + } + + 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()) { + if let Some(format) = raw::register_format("PNG") { + if let Ok(_open) = Clipboard::new_attempts(10) { + let _ = raw::set_without_clear(format.get(), &png); + } + } + } + if !html.is_empty() { + if let Some(format) = raw::register_format("HTML Format") { + if let Ok(_open) = Clipboard::new_attempts(10) { + let _ = raw::set_without_clear(format.get(), html.as_bytes()); + } + } + } + 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 }; @@ -479,6 +629,19 @@ mod platform { None } + static LAST_CHANGE_COUNT: std::sync::atomic::AtomicIsize = std::sync::atomic::AtomicIsize::new(-1); + + pub fn record_own() { + let count = NSPasteboard::generalPasteboard().changeCount(); + LAST_CHANGE_COUNT.store(count, std::sync::atomic::Ordering::Relaxed); + } + + 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 + } + pub fn can_set() -> bool { true } @@ -488,6 +651,21 @@ mod platform { false } + pub fn set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) -> bool { + false + } + + 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)) { @@ -530,10 +708,22 @@ mod platform { true } + pub fn record_own() {} + + pub fn is_own() -> bool { + false + } + pub fn set_rich(_text: &str, _html: &str, _rtf: &str) -> bool { false } + pub fn set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) -> bool { + false + } + + pub fn after_set_image(_image: &wordcraft_ui_egui::system_clipboard::CopyImage, _html: &str, _text: &str) {} + pub fn add_rtf(_rtf: &str) {} pub fn add_mathml(_mathml: &str) {} diff --git a/apps/wordcraft/src/main.rs b/apps/wordcraft/src/main.rs index 2360a2e510..347f76089a 100644 --- a/apps/wordcraft/src/main.rs +++ b/apps/wordcraft/src/main.rs @@ -352,6 +352,8 @@ fn services(file_dialog: file_dialogs::Hook, ctx: &egui::Context) -> Services { 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..ce3fbd2b8b 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 @@ -974,7 +979,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 +1002,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 +1045,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 +1215,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 +1223,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 +1249,33 @@ 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(); + let mut collect_para = |p: &Paragraph| { + for o in &p.objects { + if let InlineObject::Image { media, .. } = o { + keys.insert(media.clone()); + } + } + }; + 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 +1424,11 @@ 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 { + for (k, v) in &frag.media { + if !self.media.contains_key(k) { + 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()); diff --git a/crates/doc/src/edit/tests.rs b/crates/doc/src/edit/tests.rs index ae7f7d64af..fd8946bf7c 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] 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..35c64fbbbc 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -204,7 +204,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()), 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/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index b2533e5f1f..b3926c3716 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -100,6 +100,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/keys/canvas.rs b/crates/ui-egui/src/keys/canvas.rs index f5890f382c..775aaebc44 100644 --- a/crates/ui-egui/src/keys/canvas.rs +++ b/crates/ui-egui/src/keys/canvas.rs @@ -269,12 +269,16 @@ fn paste_release(app: &mut WordApp, e: &egui::Event) -> bool { let modifiers = &paste_release_modifiers(*modifiers, press_seen, app.canvas.paste_mods.take()); let paste_keys = is_paste_release(*key, *modifiers); let pasted = std::mem::take(&mut app.canvas.pasted); - if !pasted && paste_keys && app.session.math.is_none() && app.services.clipboard_picture.is_some() { + if !pasted && paste_keys && app.session.math.is_none() && (app.services.clipboard_picture.is_some() || app.session.clipboard.is_some()) { let _ = app.run("edit.paste", json!({})); } // Mod+Alt+V with no text on the clipboard: Paste Special still opens, listing what // is there (a picture) or saying what it holds (#687, #833). - if !pasted && is_paste_special_release(*key, *modifiers) && app.session.math.is_none() && app.services.clipboard_picture.is_some() { + if !pasted + && is_paste_special_release(*key, *modifiers) + && app.session.math.is_none() + && (app.services.clipboard_picture.is_some() || app.session.clipboard.is_some()) + { let _ = app.run("edit.pasteSpecial", json!({})); } return true; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 516852fd6c..1d2e37b7c8 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -614,6 +614,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 d9359b973b..5228e0783b 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)] @@ -73,6 +73,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..87c815a2ff 100644 --- a/crates/ui-egui/src/system_clipboard.rs +++ b/crates/ui-egui/src/system_clipboard.rs @@ -11,6 +11,14 @@ 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 { + pub width: usize, + pub height: usize, + 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 +38,10 @@ 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 } /// Put what Copy or Cut returned on the system clipboard (see [`put`]). -pub(crate) fn put_result(app: &WordApp, ctx: &egui::Context, r: &Value) { +pub(crate) fn put_result(app: &mut WordApp, ctx: &egui::Context, r: &Value) { 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")); +} + +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 image = wordcraft_render::render_items(&app.session.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), + }) +} + +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 +356,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(" Date: Tue, 10 Nov 2026 21:12:03 -0300 Subject: [PATCH 02/13] Clipboard: collapse nested checks in Windows clipboard host (#6205) --- apps/wordcraft/src/clipboard.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index daf6d2b49d..4039746a08 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -557,19 +557,17 @@ mod platform { } 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()) { - if let Some(format) = raw::register_format("PNG") { - if let Ok(_open) = Clipboard::new_attempts(10) { - let _ = raw::set_without_clear(format.get(), &png); - } - } + 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() { - if let Some(format) = raw::register_format("HTML Format") { - if let Ok(_open) = Clipboard::new_attempts(10) { - let _ = raw::set_without_clear(format.get(), html.as_bytes()); - } - } + if !html.is_empty() + && let Some(format) = raw::register_format("HTML Format") + && let Ok(_open) = Clipboard::new_attempts(10) + { + let _ = raw::set_without_clear(format.get(), html.as_bytes()); } record_own(); } From 860426adda6e2a276b29f7f90f1b19aa9dd1984e Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Tue, 10 Nov 2026 21:33:22 -0300 Subject: [PATCH 03/13] Clipboard: remap conflicting media keys, format Windows CF_HTML, and complete docstrings (#6205) --- apps/wordcraft/src/clipboard.rs | 54 +++++++++++++++- crates/doc/src/edit.rs | 85 ++++++++++++++++++++++++-- crates/doc/src/edit/tests.rs | 77 +++++++++++++++++++++++ crates/ui-egui/src/keys/canvas.rs | 8 +-- crates/ui-egui/src/system_clipboard.rs | 8 ++- 5 files changed, 219 insertions(+), 13 deletions(-) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 4039746a08..3721325814 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -98,6 +98,7 @@ pub fn set_image(image: &wordcraft_ui_egui::system_clipboard::CopyImage, html: & 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 }; @@ -229,6 +230,7 @@ mod platform { 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(|| { @@ -240,6 +242,7 @@ mod platform { 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); @@ -247,6 +250,7 @@ mod platform { } } + /// 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 } @@ -293,6 +297,7 @@ 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}; @@ -320,6 +325,7 @@ mod platform { } } + /// 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). @@ -449,6 +455,7 @@ mod platform { (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")?; @@ -531,18 +538,21 @@ mod platform { const OWNER_FORMAT: &str = "WordCraft Copy Owner"; + /// 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(), &[1u8]); } + /// 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 }; raw::is_format_avail(format.get()) } + /// Windows supports clipboard setting via arboard and clipboard_win. pub fn can_set() -> bool { true } @@ -552,10 +562,32 @@ 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 } + /// Wrap HTML in the Windows CF_HTML header format required by clipboard readers. + 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() + } + + /// 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") @@ -567,7 +599,8 @@ mod platform { && let Some(format) = raw::register_format("HTML Format") && let Ok(_open) = Clipboard::new_attempts(10) { - let _ = raw::set_without_clear(format.get(), html.as_bytes()); + let cf = wrap_cf_html(html); + let _ = raw::set_without_clear(format.get(), &cf); } record_own(); } @@ -614,32 +647,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 } @@ -649,10 +688,12 @@ 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()) { @@ -690,39 +731,50 @@ 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) {} } diff --git a/crates/doc/src/edit.rs b/crates/doc/src/edit.rs index ce3fbd2b8b..175210e031 100644 --- a/crates/doc/src/edit.rs +++ b/crates/doc/src/edit.rs @@ -565,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 @@ -1252,11 +1290,30 @@ impl Document { /// 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(); - let mut collect_para = |p: &Paragraph| { - for o in &p.objects { - if let InlineObject::Image { media, .. } = o { + /// 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 { @@ -1424,8 +1481,15 @@ 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 !self.media.contains_key(k) { + 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()); } } @@ -1441,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 fd8946bf7c..0278396824 100644 --- a/crates/doc/src/edit/tests.rs +++ b/crates/doc/src/edit/tests.rs @@ -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/ui-egui/src/keys/canvas.rs b/crates/ui-egui/src/keys/canvas.rs index 775aaebc44..f5890f382c 100644 --- a/crates/ui-egui/src/keys/canvas.rs +++ b/crates/ui-egui/src/keys/canvas.rs @@ -269,16 +269,12 @@ fn paste_release(app: &mut WordApp, e: &egui::Event) -> bool { let modifiers = &paste_release_modifiers(*modifiers, press_seen, app.canvas.paste_mods.take()); let paste_keys = is_paste_release(*key, *modifiers); let pasted = std::mem::take(&mut app.canvas.pasted); - if !pasted && paste_keys && app.session.math.is_none() && (app.services.clipboard_picture.is_some() || app.session.clipboard.is_some()) { + if !pasted && paste_keys && app.session.math.is_none() && app.services.clipboard_picture.is_some() { let _ = app.run("edit.paste", json!({})); } // Mod+Alt+V with no text on the clipboard: Paste Special still opens, listing what // is there (a picture) or saying what it holds (#687, #833). - if !pasted - && is_paste_special_release(*key, *modifiers) - && app.session.math.is_none() - && (app.services.clipboard_picture.is_some() || app.session.clipboard.is_some()) - { + if !pasted && is_paste_special_release(*key, *modifiers) && app.session.math.is_none() && app.services.clipboard_picture.is_some() { let _ = app.run("edit.pasteSpecial", json!({})); } return true; diff --git a/crates/ui-egui/src/system_clipboard.rs b/crates/ui-egui/src/system_clipboard.rs index 87c815a2ff..67adc30b4d 100644 --- a/crates/ui-egui/src/system_clipboard.rs +++ b/crates/ui-egui/src/system_clipboard.rs @@ -14,8 +14,11 @@ 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, } @@ -130,6 +133,7 @@ pub(crate) fn put_result(app: &mut WordApp, ctx: &egui::Context, r: &Value) { 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()?; @@ -151,13 +155,15 @@ fn copied_image(app: &WordApp) -> Option> { fx: Default::default(), decorative: false, }]; - let image = wordcraft_render::render_items(&app.session.doc, &items, rect, 96.0 / 72.0, &Default::default()); + 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()); From 22f01131d8cb4e0c9786eb481525f5a8cfee5b19 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Tue, 10 Nov 2026 21:47:52 -0300 Subject: [PATCH 04/13] Clipboard: use process-unique token for Windows clipboard ownership (#6205) --- apps/wordcraft/src/clipboard.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 3721325814..901e6c9812 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -538,18 +538,35 @@ mod platform { 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(), &[1u8]); + 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 }; - raw::is_format_avail(format.get()) + 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. From 28af39b610bc68fbab5a122047b6a688104a6258 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Wed, 11 Nov 2026 09:34:43 -0300 Subject: [PATCH 05/13] Clipboard: preserve system clipboard and ownership when copy has no selection (#6205) --- apps/wordcraft/src/clipboard.rs | 1 + crates/ui-egui/src/system_clipboard.rs | 51 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 901e6c9812..7d1722e1c7 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 }; diff --git a/crates/ui-egui/src/system_clipboard.rs b/crates/ui-egui/src/system_clipboard.rs index 67adc30b4d..b683af85ce 100644 --- a/crates/ui-egui/src/system_clipboard.rs +++ b/crates/ui-egui/src/system_clipboard.rs @@ -110,8 +110,21 @@ pub(crate) fn put(app: &WordApp, ctx: &egui::Context, text: &str, html: &str, rt 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`]). +/// +/// 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(""); app.clipboard_published = false; if app.services.set_clipboard_image.is_some() @@ -439,4 +452,42 @@ mod tests { assert!(!a.session.doc.media.is_empty()); } + + #[test] + fn empty_copy_does_not_publish_or_overwrite_clipboard_state() { + 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); + 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"); + } } From a1d4495cfb60ebecaf660046c2fb2c2820f95ce9 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Thu, 12 Nov 2026 09:53:17 -0300 Subject: [PATCH 06/13] Clipboard: account for fragment media and test CF_HTML offsets (#6205) --- apps/wordcraft/src/clipboard.rs | 73 ++++++++++++++++++++++++--------- crates/engine/src/cmd/edit.rs | 5 ++- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 7d1722e1c7..9946bfe601 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -128,6 +128,29 @@ 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() @@ -585,26 +608,6 @@ mod platform { false } - /// Wrap HTML in the Windows CF_HTML header format required by clipboard readers. - 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() - } - /// 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()) @@ -796,3 +799,33 @@ mod platform { /// 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/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 35c64fbbbc..f878cc9691 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -365,9 +365,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; } From cd4e63849e1962d8f8fcf18083634fc15b22b4a9 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Thu, 12 Nov 2026 10:06:07 -0300 Subject: [PATCH 07/13] Clipboard: qualify the CF_HTML helper in the Windows host (#6205) --- apps/wordcraft/src/clipboard.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wordcraft/src/clipboard.rs b/apps/wordcraft/src/clipboard.rs index 9946bfe601..92a4a4d254 100644 --- a/apps/wordcraft/src/clipboard.rs +++ b/apps/wordcraft/src/clipboard.rs @@ -620,7 +620,7 @@ mod platform { && let Some(format) = raw::register_format("HTML Format") && let Ok(_open) = Clipboard::new_attempts(10) { - let cf = wrap_cf_html(html); + let cf = super::wrap_cf_html(html); let _ = raw::set_without_clear(format.get(), &cf); } record_own(); From afcb2ce46e322f961c12e25e0cd8fc5fb30fff0e Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Thu, 12 Nov 2026 10:37:38 -0300 Subject: [PATCH 08/13] Docs: record clipboard picture copying in gaps and UI parity (#6205) --- docs/gaps.md | 8 +++++--- docs/ui-parity.md | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/gaps.md b/docs/gaps.md index 80d2e148a8..bf52f8ad24 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-08 · **Change:** 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 (#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-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) | | 2026-11-07 | trivial | Page Setup also bounds the unfocused margin display after a long numeric paste; the accepted value is retained (#5650). | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 440f3c09fe..e03511b72a 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-06 · **Change:** 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 (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. @@ -127,6 +127,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 | Page Setup also bounds the unfocused margin display after a long numeric paste; the accepted value is retained (#5650). | | 2026-11-06 | trivial | The document's scroll bars are always drawn, in the room beside the page left for them, with a grey thumb that stands out from its track in both themes; they were invisible until the pointer reached the window's right edge, so without a mouse wheel nothing showed how to reach page 2 (#5746) | | 2026-11-05 | trivial | Page Setup's margin, paper-size and document-grid number boxes scroll long text inside the field instead of enlarging the dialog (#5650). Readiness estimates unchanged. | @@ -140,7 +141,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) | From ab90b7142e3068b8afaea51ec237baa1f7f1f968 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Thu, 12 Nov 2026 12:22:28 -0300 Subject: [PATCH 09/13] Clipboard: honor another program's clipboard ownership on paste (#6225) Paste selected WordCraft's own fragment whenever the system clipboard text matched, even when the host reported that another program owned the clipboard, so a plain-text copy made elsewhere could paste the earlier bold fragment back. Read privateClipboard in paste_content and in the Formatted Text source, using the session fragment only when ownership is true or the caller omits the flag (agents and the CLI keep working). Carry the flag through the Paste Special request and dialog so its format list matches. --- crates/engine/src/cmd/edit.rs | 6 ++-- crates/engine/src/cmd/paste.rs | 23 ++++++++++++--- crates/engine/src/tests.rs | 46 +++++++++++++++++++++++++++++ crates/ui-egui/src/dialogs.rs | 3 ++ crates/ui-egui/src/dialogs/tests.rs | 13 ++++++++ 5 files changed, 85 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index f878cc9691..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; 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/tests.rs b/crates/engine/src/tests.rs index 6439b3de9e..5fe96f0729 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/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. From 1a8fd899d30bdd067724f6a61e64f1cbe1bd2142 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Thu, 12 Nov 2026 12:38:27 -0300 Subject: [PATCH 10/13] Clipboard: keep the ownership flag Paste Special captured (#6225) system_clipboard::fill recomputed privateClipboard whenever the host could report ownership, overwriting the value the Paste Special dialog captured when it opened. Only compute it when the caller supplied none, so the dialog's format list and the paste agree while ribbon and agent calls keep reading ownership from the clipboard. --- crates/ui-egui/src/system_clipboard.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/system_clipboard.rs b/crates/ui-egui/src/system_clipboard.rs index b683af85ce..6af6fa66d8 100644 --- a/crates/ui-egui/src/system_clipboard.rs +++ b/crates/ui-egui/src/system_clipboard.rs @@ -41,7 +41,8 @@ pub(crate) fn fill(app: &mut WordApp, id: &str, params: &mut Value) -> Option::new())); From 869350d4c78efad043385d1e9d94ce63a0e9695f Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 12 Nov 2026 19:31:52 +0100 Subject: [PATCH 11/13] Clean combined UI parity history after main merge (#6225) --- docs/ui-parity.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/ui-parity.md b/docs/ui-parity.md index b5332c3b1c..ed89ed7f0a 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,10 +1,6 @@ # UI parity with Microsoft Word - fix/6205-image-copy-paste -> **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 (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-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 - main +> **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. From aa6deaee03e7724e4e61b2e800080c02e014fb81 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 12 Nov 2026 19:39:50 +0100 Subject: [PATCH 12/13] test: use mutable cells in LaTeX table setup (#6225) --- crates/formats/src/latex/tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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))]; From d54fb7854414274f48347429874dcefe3f68ff4d Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 12 Nov 2026 19:43:54 +0100 Subject: [PATCH 13/13] test: avoid range indexing in layout and eraser fixtures (#6225) --- crates/engine/src/cmd/table_draw.rs | 6 +++--- crates/layout/src/tests.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) 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/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) {