Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] 753c3977a9 Merge main (8d75a12b) into the pull request
I resolved the conflicts in crates/engine/src/cmd/edit.rs, crates/engine

I resolved the conflicts in crates/engine/src/cmd/edit.rs, crates/engine/src/cmd/paste.rs and docs/typing-parity.md, and no conflict markers remain. I didn't build or run tests: earlier merges couldn't build offline because cargo couldn't fetch the winit git dependency, and I didn't try again. `cargo fmt --check` is clean. In edit.rs, `copy_with` computes the labelled text, calls main's `copy_result(s, &f, &text)` and pushes it to the clip history. Replace's `^c` keeps the label-free clip text in main's `expand(..., quotes)` call. In paste.rs I took main's `matches_session_clipboard` and changed its text check to compare against `s.clipboard_text`, the text Copy put on the clipboard with its list labels. The docs keep main's header with the #2015 entry added, and the pull request's change-log row sits after main's 2026-12-03, 2026-11-27 and 2026-11-17 rows.
2026-12-03 20:10:35 +00:00
Diego Guerini 956a45baf7 Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-11-17 18:54:45 +01:00
Diego Guerini f124aef0d3 #2015 review: a tracked cut of list items stays a move, and Replace's ^c leaves out the list labels 2026-11-17 09:08:13 +01:00
Diego Guerini 59eaad690f Merge upstream/main into copy-list-labels 2026-11-16 17:21:56 +01:00
Diego Guerini 1575ef8825 Merge upstream/main into copy-list-labels
main added privateClipboard (owns_clipboard) to the two clipboard checks
in paste.rs that this PR moved to Session::clipboard_text; both are
kept.
2026-11-15 17:14:57 +01:00
Diego Guerini 7659c56182 Merge upstream/main into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-11-07 16:44:59 +01:00
Diego GueriniandClaude Opus 5.5 d94773663c #2015: the test edits the numbering through Arc::make_mut after merging main
Main shares the numbering between undo steps (#2694), so `Document::numbering` is an
`Arc<Numbering>`; this PR's test wrote to it directly and no longer built once merged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 20:00:24 +01:00
Diego Guerini e077bfd06e Merge remote-tracking branch 'upstream/main' into copy-list-labels 2026-11-04 19:55:33 +01:00
Diego Guerini f43e8b1cd9 Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-11-04 12:53:39 +01:00
Diego Guerini 667a5cb0ab Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-11-03 12:50:54 +01:00
Diego Guerini 5edee413ce Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-11-01 18:24:52 +01:00
Diego GueriniandClaude Opus 5.5 c210879b85 #2015: a test of a copied nested list item
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 11:33:08 +01:00
Diego Guerini 8cb6a7a48b Merge remote-tracking branch 'upstream/main' into copy-list-labels 2026-10-30 06:43:39 +01:00
Diego Guerini 4109b592d4 Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-10-26 16:04:06 +01:00
Diego GueriniandClaude Opus 5.5 62f71654e8 Merge upstream/main into copy-list-labels
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 08:03:46 +01:00
Diego GueriniandClaude Opus 5.5 3bb2bd93ad #2015 review: Paste Special as text pastes the copy's labels; no list numbering for part of one paragraph
- With no system clipboard text, edit.pasteSpecial {"as": "text"} pastes the text Copy put on the clipboard (list labels and all), not the copy's bare text.
- copy_text returns early for part of one paragraph, before numbering the body's lists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 17:43:09 +02:00
Diego GueriniandClaude Opus 5.5 a57fae4fdb Merge upstream/main into copy-list-labels
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:06:03 +02:00
Diego Guerini e451caec50 Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	crates/engine/src/tests.rs
#	docs/typing-parity.md
2026-10-18 23:27:14 +02:00
Diego Guerini 4ac343519a Merge remote-tracking branch 'upstream/main' into copy-list-labels 2026-10-18 16:09:06 +02:00
Diego Guerini 00ca7859ef Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-10-18 11:29:39 +02:00
Diego GueriniandClaude Opus 5.5 da6816a565 #2015: a copy that crosses a table keeps the list labels outside it
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 11:29:07 +02:00
Diego Guerini 66eae86296 Merge remote-tracking branch 'upstream/main' into copy-list-labels
# Conflicts:
#	docs/typing-parity.md
2026-10-18 10:29:38 +02:00
Diego GueriniandClaude Opus 5.5 aefa4298da Copy puts list numbers and bullets in the clipboard's text (#2015)
Copying a list and pasting it into another program as plain text lost
the numbers and bullets: the copy's text came from the copied fragment,
which, as a document of its own, no longer knows the source's lists.

`Document::copy_text` builds Copy's text from the source document: each
copied list paragraph starts with its label and the character after it
(`1.` and a tab, `•` and a tab), counted from the top of the body with
the same counters layout uses, so it reads as the page shows it. The
label is inserted in the level's own font, so a Symbol-font bullet comes
out as `•` through the existing symbol mapping. A paragraph copied from
its middle, or one the selection only reaches the start of, gets no
label; a selection inside one paragraph only when it is all of it.
Paragraphs in tables, headers and notes keep their text without labels.

Paste tells our own copy from someone else's by comparing the system
clipboard's text with the text Copy put there (`s.clipboard_text`)
instead of recomputing it from the fragment, so pasting the copy back
still pastes the list, not its labels as text. (A column copy already
stored a different text than the fragment's.)

Tests: the labels for a numbered and a bulleted list, a Symbol-font
bullet, pasting the copy back, and the partial selections.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 09:33:34 +02:00
6 changed files with 231 additions and 16 deletions
+72
View File
@@ -1127,6 +1127,78 @@ impl Document {
Fragment { blocks, parts, media }
}
/// The text Copy puts on the clipboard for `a..b`, whose copy is `f`: [`Fragment::clipboard_text`]
/// with the list label and what follows it (`1.` and a tab, `•` and a tab) before each list
/// paragraph, as Word's plain-text copy has them (#2015). A paragraph gets its label when its
/// start is copied and some of it with it: not one copied from its middle, nor one the
/// selection only reaches the start of; a selection inside one paragraph only when it is all
/// of it. Lists are counted from the top of the body, as the page numbers them. Paragraphs in
/// tables, headers and notes keep their text without labels.
pub fn copy_text(&self, f: &Fragment, a: &Pos, b: &Pos) -> String {
let (a, b) = order(a, b);
if a.story != crate::StoryRef::Body {
return f.clipboard_text();
}
// The path each copied block comes from, as `copy_blocks` copies them: the blocks between
// two places in one container, or every paragraph between them when the selection
// crosses a table (the ones in its cells included).
let sources: Vec<Path> = if a.path.parent() == b.path.parent() {
(a.path.last()..=b.path.last()).map(|i| a.path.with_last(i)).collect()
} else {
self.paths_between(&a, &b).into_iter().filter(|p| self.para(a.story, p).is_some()).collect()
};
let whole_one = a.path != b.path || (a.off == 0 && self.para(a.story, &a.path).is_some_and(|p| b.off >= p.len()));
// Part of one paragraph: no label to give.
if !whole_one {
return f.clipboard_text();
}
let labels = self.body_list_labels();
let mut labelled = f.clone();
let mut any = false;
for (blk, path) in labelled.blocks.iter_mut().zip(&sources) {
// Only top-level paragraphs get labels; the ones in tables keep their text.
if path.0.len() != 1 {
continue;
}
let (is_first, is_last) = (*path == a.path, *path == b.path);
let start_copied = !is_first || a.off == 0;
let reached = !(is_last && b.off == 0 && !is_first);
let (Block::Para(p), Some(Some((label, level)))) = (blk, labels.get(path.last())) else { continue };
if !(start_copied && reached) {
continue;
}
let after = match level.suffix {
crate::numbering::LevelSuffix::Tab => "\t",
crate::numbering::LevelSuffix::Space => " ",
crate::numbering::LevelSuffix::Nothing => "",
};
// In the level's own font, so a Symbol-font bullet reads as its Unicode character.
any |= p.insert_text(0, &format!("{label}{after}"), &level.chr).is_ok();
}
if any { labelled.clipboard_text() } else { f.clipboard_text() }
}
/// The list label (and its level) each top-level body block shows, `None` for a table or a
/// paragraph without one, counted in reading order with the paragraphs in tables, as layout
/// counts them.
fn body_list_labels(&self) -> Vec<Option<(String, crate::numbering::Level)>> {
let mut counters = crate::numbering::Counters::default();
let mut out = Vec::with_capacity(self.body.len());
for b in &self.body {
let top = matches!(&**b, Block::Para(_));
let mut label = None;
each_para(b, 0, &mut |p| {
let n = p.props.numbering.or_else(|| self.styles.resolve_para(&p.props).numbering).filter(|n| n.num != 0);
let l = n.and_then(|n| counters.next_label(&self.numbering, n.num, n.level));
if top {
label = l;
}
});
out.push(label);
}
out
}
/// A copy of the block at `path` (a whole table, say) as a fragment, with its text boxes.
pub fn copy_block(&self, story: crate::StoryRef, path: &Path) -> Option<Fragment> {
Some(self.fragment_of(vec![self.block(story, path)?.clone()]))
+8 -5
View File
@@ -203,12 +203,13 @@ fn copy_with(s: &mut Session, whole: Option<&Path>) -> CmdResult {
(None, Some(r)) => s.doc.copy_table_cells(r.story, &r.table, r.rows, r.cols),
(None, None) => None,
};
let f = match table {
Some(f) => f,
let (f, range) = match table {
Some(f) => (f, false),
None if a == b => return Ok(json!({"text": ""})),
None => s.doc.copy_range(&a, &b),
None => (s.doc.copy_range(&a, &b), true),
};
let text = f.clipboard_text();
// A range copies with its list labels, as Word's plain-text copy has them (#2015).
let text = if range { s.doc.copy_text(&f, &a, &b) } else { f.clipboard_text() };
let r = copy_result(s, &f, &text)?;
s.clip_history.push(&f, &text);
Ok(r)
@@ -630,6 +631,8 @@ fn search_matches(s: &Session, story: StoryRef, with_rep: bool, chain: bool) ->
Some(Pos { story, path: paths.get(sg.para)?.clone(), off: sg.raw + (x - sg.hay) })
};
cuts.push(hay.len());
// `^c`: the copied text without the list labels the plain-text clipboard has (#2015 review).
let clip = s.clipboard.as_ref().map_or_else(|| s.clipboard_text.clone(), |f| f.clipboard_text());
let mut from = 0;
// Where the last match ends and the character that stands there once it is replaced.
let mut last: Option<(usize, Option<char>)> = None;
@@ -668,7 +671,7 @@ fn search_matches(s: &Session, story: StoryRef, with_rep: bool, chain: bool) ->
let quotes = if smart { find_pattern::Quotes::Smart { before } } else { find_pattern::Quotes::Straight };
let rep = pieces.as_ref().map(|pc| {
let group = |n: usize| caps.get_group(n).and_then(|g| hay.get(g.range())).map(str::to_string);
find_pattern::expand(pc, found, &group, &s.clipboard_text, quotes)
find_pattern::expand(pc, found, &group, &clip, quotes)
});
let keep = smart && rep.as_deref().is_some_and(|r| find_pattern::already_curled(found, r));
let stays = if keep { found } else { rep.as_deref().unwrap_or(found) };
+5 -2
View File
@@ -53,7 +53,10 @@ fn in_use(s: &Session, rev: u32) -> bool {
/// done) when it isn't such a cut.
pub fn cut_tracked(s: &mut Session) -> Result<bool, CmdError> {
let (a, b) = s.sel.ordered();
if !s.doc.settings.track_changes || !s.doc.settings.track_moves || a == b || a.story != b.story || !move_sized(&s.clipboard_text) {
// The cut's own text, as the paste compares it (`take_paste`): the plain-text clipboard also
// has the list labels of the paragraphs cut (#2015 review).
let text = s.clipboard.as_ref().map_or_else(|| s.clipboard_text.clone(), Fragment::plain_text);
if !s.doc.settings.track_changes || !s.doc.settings.track_moves || a == b || a.story != b.story || !move_sized(&text) {
return Ok(false);
}
s.doc.revisions.push(crate::cmd::made_revision(RevisionKind::Delete, s.author.clone(), now_iso()));
@@ -62,7 +65,7 @@ pub fn cut_tracked(s: &mut Session) -> Result<bool, CmdError> {
s.sel = Selection::caret(at);
// Only the author's own insertions were cut: they are gone, not moved.
if in_use(s, rid) {
s.pending_move = Some(PendingMove { rev: rid, text: s.clipboard_text.clone(), author: s.author.clone() });
s.pending_move = Some(PendingMove { rev: rid, text, author: s.author.clone() });
}
Ok(true)
}
+8 -8
View File
@@ -41,11 +41,12 @@ pub fn specs() -> Vec<CommandSpec> {
]
}
/// Clipboard text from the params (system clipboard), else WordCraft's own copy.
/// Clipboard text from the params (system clipboard), else WordCraft's own copy: the text Copy
/// put on the clipboard, list labels and all (#2015).
fn clip_text(s: &Session, v: &Value) -> Option<String> {
match p::str(v, "text") {
Some(t) => Some(t.replace("\r\n", "\n")),
None => s.clipboard.as_ref().map(Fragment::plain_text),
None => s.clipboard.as_ref().map(|f| if s.clipboard_text.is_empty() { f.plain_text() } else { s.clipboard_text.clone() }),
}
}
@@ -101,12 +102,11 @@ pub(crate) fn matches_session_clipboard(s: &Session, v: &Value) -> bool {
let rtf_matches = rtf.is_none_or(|r| r == s.clipboard_rtf);
owns_clipboard(v)
&& s.clipboard.as_ref().is_some_and(|f| {
text.as_ref().is_none_or(|t| f.clipboard_text() == *t || (t.is_empty() && has_rich))
&& html_matches
&& rtf_matches
&& (text.is_some() || has_rich || (html.is_none() && rtf.is_none()))
})
&& s.clipboard.is_some()
&& text.as_ref().is_none_or(|t| s.clipboard_text == *t || (t.is_empty() && has_rich))
&& html_matches
&& rtf_matches
&& (text.is_some() || has_rich || (html.is_none() && rtf.is_none()))
}
/// The source for a format, if the clipboard has it.
+135
View File
@@ -2044,6 +2044,141 @@ fn copying_symbol_font_text_puts_the_unicode_symbols_on_the_clipboard() {
assert_eq!(text(&s), "ok J\u{F0FC}ok J\u{F0FC}");
}
/// A session holding "Intro", a numbered list (Item 1, Item 2) and a bulleted one (Point A,
/// Point B).
fn session_with_lists() -> Session {
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Intro\nItem 1\nItem 2\nPoint A\nPoint B"}));
run(&mut s, "select.range", json!({"anchor": Pos::body(1, 0), "focus": Pos::body(2, 6)}));
run(&mut s, "para.numbering", json!({}));
run(&mut s, "select.range", json!({"anchor": Pos::body(3, 0), "focus": Pos::body(4, 7)}));
run(&mut s, "para.bullets", json!({}));
s
}
/// #2015 review: with Track Changes (and Track Moves) on, numbered items cut and pasted elsewhere
/// are a tracked move, though the clipboard's text has their labels; and `^c` in Replace puts in
/// the copied text without them.
#[test]
fn a_cut_list_item_pasted_elsewhere_is_a_tracked_move() {
let mut s = session_with_lists();
run(&mut s, "review.trackChanges", json!({"value": true}));
run(&mut s, "select.range", json!({"anchor": Pos::body(1, 0), "focus": Pos::body(3, 0)}));
run(&mut s, "edit.cut", json!({}));
assert!(s.clipboard_text.starts_with("1.\tItem 1"), "{:?}", s.clipboard_text);
run(&mut s, "caret.docEnd", json!({}));
let clip = s.clipboard_text.clone();
run(&mut s, "edit.paste", json!({"text": clip}));
let moves: Vec<wordcraft_doc::RevisionKind> = s.doc.revisions.iter().filter(|r| r.move_name.is_some()).map(|r| r.kind).collect();
assert_eq!(moves, [wordcraft_doc::RevisionKind::Delete, wordcraft_doc::RevisionKind::Insert], "a move, its source and its destination");
let mut s = session_with_lists();
run(&mut s, "select.range", json!({"anchor": Pos::body(1, 0), "focus": Pos::body(1, 6)}));
run(&mut s, "edit.copy", json!({}));
assert_eq!(s.clipboard_text, "1.\tItem 1");
run(&mut s, "edit.replaceAll", json!({"text": "Intro", "with": "^c"}));
assert!(text(&s).starts_with("Item 1\n"), "{:?}", text(&s));
}
/// #2015: Copy puts each list paragraph's number or bullet, and the tab after it, in the
/// clipboard's text, as Word's plain-text copy has them. Pasting that copy back here still pastes
/// our own copy: the lists, not their labels typed out as text.
#[test]
fn copying_a_list_puts_its_numbers_and_bullets_on_the_clipboard() {
let mut s = session_with_lists();
run(&mut s, "select.all", json!({}));
run(&mut s, "edit.copy", json!({}));
assert_eq!(s.clipboard_text, "Intro\n1.\tItem 1\n2.\tItem 2\n•\tPoint A\n•\tPoint B");
run(&mut s, "caret.docEnd", json!({}));
run(&mut s, "text.newParagraph", json!({}));
let clip = s.clipboard_text.clone();
run(&mut s, "edit.paste", json!({"text": clip}));
assert!(!text(&s).contains('\t') && !text(&s).contains('•'), "{}", text(&s));
let numbered = |s: &Session, i: usize| s.doc.para(StoryRef::Body, &wordcraft_doc::Path::top(i)).and_then(|p| p.props.numbering).is_some();
assert!(numbered(&s, 6) && numbered(&s, 7), "the pasted items are list items");
// A bullet stored as a Symbol-font character (as Word documents have them) reads as •.
let mut s = session_with_lists();
let num = s.doc.para(StoryRef::Body, &wordcraft_doc::Path::top(3)).and_then(|p| p.props.numbering).map(|n| n.num).unwrap();
let abs = s.doc.numbering.num(num).map(|n| n.abstract_id).unwrap();
let level = std::sync::Arc::make_mut(&mut s.doc.numbering).abstracts.iter_mut().find(|a| a.id == abs).and_then(|a| a.levels.first_mut()).unwrap();
level.text = "\u{F0B7}".into();
level.chr.font = Some("Symbol".into());
run(&mut s, "select.range", json!({"anchor": Pos::body(3, 0), "focus": Pos::body(4, 7)}));
run(&mut s, "edit.copy", json!({}));
assert_eq!(s.clipboard_text, "•\tPoint A\n•\tPoint B");
// Paste Special › Unformatted Text with no system clipboard text (a command, not the app)
// pastes the copy's text as Copy put it: the labels typed out.
run(&mut s, "caret.docEnd", json!({}));
run(&mut s, "text.newParagraph", json!({}));
run(&mut s, "edit.pasteSpecial", json!({"as": "text"}));
assert!(text(&s).ends_with("•\tPoint A\n•\tPoint B"), "{:?}", text(&s));
}
/// #2015: a list paragraph gets its label only when its start is copied with some of it: not one
/// copied from its middle, nor one the selection only reaches; inside one paragraph only when it
/// is all of it.
#[test]
fn copied_list_labels_follow_what_the_selection_covers() {
let mut s = session_with_lists();
let copy = |s: &mut Session, a: Pos, b: Pos| {
run(s, "select.range", json!({"anchor": a, "focus": b}));
run(s, "edit.copy", json!({}));
s.clipboard_text.clone()
};
assert_eq!(copy(&mut s, Pos::body(1, 2), Pos::body(2, 6)), "em 1\n2.\tItem 2", "from the middle of an item");
assert_eq!(copy(&mut s, Pos::body(1, 1), Pos::body(1, 4)), "tem", "inside one item");
assert_eq!(copy(&mut s, Pos::body(1, 0), Pos::body(1, 6)), "1.\tItem 1", "all of one item");
let up_to_next = copy(&mut s, Pos::body(1, 0), Pos::body(3, 0));
assert!(up_to_next.starts_with("1.\tItem 1\n2.\tItem 2") && !up_to_next.contains('•'), "{up_to_next:?}");
assert_eq!(copy(&mut s, Pos::body(0, 0), Pos::body(0, 5)), "Intro", "no list, no label");
}
/// #2015: a nested list item's copy has its own level's label, and the item after it on the
/// first level goes on counting from the one before the nested item.
#[test]
fn a_copied_nested_list_item_has_its_level_s_label() {
let mut s = session_with_lists();
run(&mut s, "document.setText", json!({"text": "Item 1\nSub item\nItem 2"}));
run(&mut s, "select.all", json!({}));
run(&mut s, "para.numbering", json!({}));
let path = wordcraft_doc::Path::top(1);
let sub = s.doc.para_mut(StoryRef::Body, &path).unwrap();
sub.props.numbering = sub.props.numbering.map(|n| wordcraft_doc::props::NumRef { level: 1, ..n });
run(&mut s, "select.all", json!({}));
run(&mut s, "edit.copy", json!({}));
assert_eq!(s.clipboard_text, "1.\tItem 1\na.\tSub item\n2.\tItem 2");
}
/// #2015: a selection that crosses a table (Select All in a document that starts with one, or a
/// list down into a table) keeps the labels of the list paragraphs outside the table; the
/// paragraphs in its cells keep their text without labels.
#[test]
fn copied_list_labels_survive_a_selection_across_a_table() {
use wordcraft_doc::{Block, Path, Table};
let cell_table = |s: &mut Session, at: usize| {
s.doc.insert_block(StoryRef::Body, &Path::top(at), Block::Table(Table::new(1, 1, 300.0))).unwrap();
let cell = Path(vec![at as u32, 0, 0, 0]);
s.doc.para_mut(StoryRef::Body, &cell).unwrap().insert_text(0, "Cell", &Default::default()).unwrap();
Pos { story: StoryRef::Body, path: cell, off: 0 }
};
let copy = |s: &mut Session, a: Pos, b: Pos| {
run(s, "select.range", json!({"anchor": a, "focus": b}));
run(s, "edit.copy", json!({}));
s.clipboard_text.clone()
};
// A table first: from its cell to the end of the last bullet.
let mut s = session_with_lists();
let cell = cell_table(&mut s, 0);
assert_eq!(copy(&mut s, cell, Pos::body(5, 7)), "Cell\nIntro\n1.\tItem 1\n2.\tItem 2\n•\tPoint A\n•\tPoint B");
// A table last: from the first item down into its cell.
let mut s = session_with_lists();
let cell = cell_table(&mut s, 5);
assert_eq!(copy(&mut s, Pos::body(1, 0), Pos { off: 4, ..cell }), "1.\tItem 1\n2.\tItem 2\n•\tPoint A\n•\tPoint B\nCell");
}
/// The text drawn on the first page.
fn drawn_text(s: &mut Session) -> String {
let layout = s.layout();
File diff suppressed because one or more lines are too long