Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] 32984c6c80 Merge main (060ce2c6) into the pull request
Resolved the only conflict, in crates/engine/src/tests.rs, where both si

Resolved the only conflict, in crates/engine/src/tests.rs, where both sides appended tests at the same spot. I kept the PR's three tests and the default branch's tests, each as its own function, and removed all three conflict markers. No other file needed changing. I could not compile or run the tests: the offline build fails on the winit git dependency and the shell kept dropping its connection. A final whole-file marker search did not complete, but I read the start of the section after the edits and saw no marker there.
2026-12-02 18:08:51 +00:00
Zach BerryandClaude Opus 5.5 c86b62966b Font toggles and format.state read the selected table cell
current_run read the shape's own text, which a table does not have, so
a second Bold on a selected cell range still saw "not bold" and kept
bold on, and format.state reported the default. It now reads the first
selected cell (the first cell when the whole table is selected).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 23:03:00 -06:00
aiongg 067a81c812 Apply review fixes
- crates/engine/src/cmd/text/caret.rs
2026-11-06 04:44:25 +00:00
aiongg 0e97d11789 Apply review fixes
- crates/engine/src/cmd/format.rs
- crates/engine/src/cmd/text/formatting.rs
2026-11-06 04:38:37 +00:00
Zach BerryandClaude Opus 5.5 196accb4b6 Formatting set on an empty shape survives the text that is set or typed next
format.size, format.bold and format.color on a shape that has no text yet kept nothing, so the
size vanished when text.set then landed the text. An empty body now keeps that formatting on a
paragraph's end mark, and text.set keeps the first run's properties or, for text that is still
empty, those. The text-editing path gets the same guard: an empty body with no paragraph at all
dropped a bold set before typing. A test for each. Split out of the connector default-sites
change at review, as it is unrelated to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 21:55:15 -06:00
4 changed files with 92 additions and 3 deletions
+10 -2
View File
@@ -287,8 +287,16 @@ fn current_run(s: &Session) -> RunProps {
}
None => {
let Some(sh) = st.selected_shapes().first().map(|x| (*x).clone()) else { return RunProps::default() };
let para = sh.text.as_ref().and_then(|t| t.paragraphs.first().cloned()).unwrap_or_default();
let rp = para.runs.first().map(|r| r.props.clone()).unwrap_or_default();
// A selected table reads its first selected cell (the whole table without a range: its first cell).
let body = match &sh.kind {
deckcraft_model::ShapeKind::Table(tb) => {
let first = super::table::selected_range(st.selection.cells, sh.id, tb).map_or((0, 0), |(a, _)| a);
tb.cell(first.0, first.1).map(|c| &c.text)
}
_ => sh.text.as_ref(),
};
let para = body.and_then(|t| t.paragraphs.first().cloned()).unwrap_or_default();
let rp = para.runs.first().map(|r| r.props.clone()).unwrap_or_else(|| para.end_props.clone());
(sh, para, rp)
}
};
+9 -1
View File
@@ -338,7 +338,10 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result<Value> {
_ => Some(sh.text.get_or_insert_with(TextBody::default)),
};
let Some(body) = target else { return Err(bad("text.set", "no text here (tables need `cell`)")) };
let keep = body.paragraphs.first().and_then(|p| p.runs.first()).map(|r| r.props.clone()).unwrap_or_default();
// The first run's formatting, or for text that is still empty the formatting its end
// mark holds (format.* before any text lands there), so a size set before text.set survives.
let keep =
body.paragraphs.first().map(|p| p.runs.first().map(|r| r.props.clone()).unwrap_or_else(|| p.end_props.clone())).unwrap_or_default();
let levels: Vec<(u8, deckcraft_model::text::ParaProps)> = body.paragraphs.iter().map(|p| (p.level, p.props.clone())).collect();
let mut nb = TextBody::from_text(&text);
for (i, para) in nb.paragraphs.iter_mut().enumerate() {
@@ -353,6 +356,11 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result<Value> {
for r in &mut para.runs {
r.props = keep.clone();
}
// The end mark keeps it too, so an empty `text` (no runs) carries the formatting to
// the text set next.
para.end_props = keep.clone();
// A run emptied by stripping leading tabs would shadow the end mark for the text typed next.
para.normalize();
}
body.paragraphs = nb.paragraphs;
Ok(())
+12
View File
@@ -25,6 +25,10 @@ pub(crate) fn format_run_levels(
// Only the levels of the paragraphs the selected range touches.
let levels = if a == b { Vec::new() } else { master_levels(st, &t, t.ordered()) };
edit_text(s, |body, _| {
// A body with no paragraph has no end mark to hold the formatting of the text typed next.
if body.paragraphs.is_empty() {
body.paragraphs.push(Default::default());
}
if levels.is_empty() {
ed::format(body, a, b, f);
} else {
@@ -65,6 +69,9 @@ pub(crate) fn format_run_levels(
for (r, row) in t.rows.iter_mut().enumerate() {
for (c, cell) in row.cells.iter_mut().enumerate() {
if crate::cmd::table::in_range(range, r, c) {
if cell.text.paragraphs.is_empty() {
cell.text.paragraphs.push(Default::default());
}
ed::format_all(&mut cell.text, f);
}
}
@@ -72,6 +79,11 @@ pub(crate) fn format_run_levels(
}
_ => {
let body = sh.text.get_or_insert_with(TextBody::default);
// Text that is still empty keeps the formatting on an end mark, so a size set
// before the text lands survives it; a body with no paragraph has none.
if body.paragraphs.is_empty() {
body.paragraphs.push(Default::default());
}
let eff = effective.iter().find(|(i, _)| *i == id).map(|(_, e)| e);
match eff {
Some(eff) => {
+61
View File
@@ -7215,6 +7215,67 @@ fn invalid_slide_index_never_falls_back_to_the_selection_in_export_commands() {
let _ = std::fs::remove_dir_all(&dir);
}
/// A size (or colour, bold…) set on a shape before it has any text survives the text that is
/// then set: text.set keeps the first run's properties, and an empty paragraph keeps them on its
/// end mark, which is what the agent's format.size then set_text sequence relies on.
#[test]
fn text_set_keeps_the_formatting_of_an_empty_shape() {
let mut s = session();
let id = s.execute("shape.insert", &json!({"preset": "rect", "rect": [10, 10, 300, 60]})).unwrap()["id"].as_u64().unwrap();
s.execute("format.size", &json!({"size": 30})).unwrap();
s.execute("format.bold", &json!({"on": true})).unwrap();
s.execute("text.set", &json!({"id": id, "text": "Hello"})).unwrap();
let props =
|s: &Session| s.doc().unwrap().shape(deckcraft_model::ShapeId(id as u32)).unwrap().text.as_ref().unwrap().paragraphs[0].runs[0].props.clone();
let run = props(&s);
assert_eq!((run.size, run.bold), (Some(30.0), Some(true)), "{run:?}");
// Emptied and filled again: the empty paragraph's end mark carried the formatting.
s.execute("text.set", &json!({"id": id, "text": ""})).unwrap();
s.execute("text.set", &json!({"id": id, "text": "Again"})).unwrap();
let run = props(&s);
assert_eq!((run.size, run.bold), (Some(30.0), Some(true)), "after an empty text.set: {run:?}");
}
/// The same while editing the text: a bold set in the text editor of a shape with an empty body
/// (no paragraph at all) is what the next typed text gets.
#[test]
fn text_insert_keeps_the_formatting_set_in_an_empty_editor() {
let mut s = session();
let id = s.execute("shape.insert", &json!({"preset": "rect", "rect": [10, 10, 300, 60]})).unwrap()["id"].as_u64().unwrap();
s.edit(|doc, sel| {
let sh = deckcraft_model::find_shape_mut(crate::shapes_mut(doc, sel).unwrap(), deckcraft_model::ShapeId(id as u32)).unwrap();
sh.text = Some(deckcraft_model::text::TextBody::default());
Ok(())
})
.unwrap();
s.execute("text.edit", &json!({"id": id})).unwrap();
s.execute("format.bold", &json!({"on": true})).unwrap();
s.execute("text.insert", &json!({"text": "Hi"})).unwrap();
let run = s.doc().unwrap().shape(deckcraft_model::ShapeId(id as u32)).unwrap().text.as_ref().unwrap().paragraphs[0].runs[0].props.clone();
assert_eq!(run.bold, Some(true), "{run:?}");
}
/// Font toggles on a selected table read the first selected cell, so the second Bold turns it off
/// again, also for a cell whose empty text got its paragraph from the first toggle.
#[test]
fn bold_toggles_on_a_selected_table_cell() {
let mut s = session();
let id = table_at(&mut s, &[100.0, 100.0], json!([["", "b"], ["c", "d"]]));
let bold = |s: &Session, r: usize, c: usize| {
let st = s.doc().unwrap();
let deckcraft_model::ShapeKind::Table(t) = &st.shape(id).unwrap().kind else { panic!("table") };
let p = &t.cell(r, c).unwrap().text.paragraphs[0];
p.runs.first().map_or(p.end_props.bold, |r| r.props.bold)
};
s.execute("table.selectCells", &json!({"id": id, "from": [0, 0], "to": [0, 1]})).unwrap();
s.execute("format.bold", &json!({})).unwrap();
assert_eq!((bold(&s, 0, 0), bold(&s, 0, 1)), (Some(true), Some(true)));
assert_eq!(s.execute("format.state", &json!({})).unwrap()["bold"], json!(true));
s.execute("format.bold", &json!({})).unwrap();
assert_eq!((bold(&s, 0, 0), bold(&s, 0, 1)), (Some(false), Some(false)));
assert_eq!(bold(&s, 1, 0), None, "cells outside the range keep their formatting");
}
/// G6: with no sites given, shape.connect joins the sites that face each other along the
/// dominant direction between the two shapes (a box mostly below leaves from the bottom), not
/// "the closest pair", which for a diagonal neighbour picked a side site and crossed boxes.