Compare commits

...
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 ddf88c39df CP4.3: craft-i18n.rev at 20467b6 (#116 merged): builds embed the Language data language-packs-2 was built from (#5385)
Claude-Session: https://claude.ai/code/session_01FypgCYmv6UJmY2QcuhfXco

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 22:10:18 +00:00
Luis VacaandClaude Opus 5.5 a591879294 Comments: a long comment's card and balloon stop at ten lines (#3382) (#3899)
* #3382: a long comment's card and balloon stop at ten lines

A comment or reply field, in the Comments pane and in a selected balloon,
is at most ten lines tall and scrolls beyond that, keeping its caret in
view. A balloon that isn't selected shows the first ten lines of the
comment and of each reply and cuts off the rest; clicking it opens the
scrolling field. The buttons and the next comment stay in view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #3382: record the ten-line comment cap in the UI parity doc; test the drawn rows

The Comments entry of the UI parity doc notes that a long comment's card,
balloon and fields stop at ten lines. A new test checks what an unselected
long balloon paints: its first ten rows inside the card's clip and none of
the rows after them, in Latin and Arabic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #3382: check the shown balloon rows start inside the clip

The drawn-rows test now also checks that each of the first ten rows starts
at or below the top of the balloon body's clip, so a clip that hid the
first rows would fail it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:45:39 +00:00
Dylan M. TaylorandBrandon Thomas ae5c65b9dd Paste: charge copied text box stories for the formatting they clone (#5379)
Co-authored-by: Brandon Thomas <echelon@gmail.com>
2026-11-03 09:05:14 -05:00
1f8f9e8e2c DOC import: keep one override per table cell instead of a copy per repeated sprm (#5374)
* fix(docbin): keep one override per table cell instead of a copy per repeated sprm

* DOC import: vertical alignment reads only the cells a row can hold, like the other cell-range sprms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 09:04:13 -05:00
Dylan M. TaylorandBrandon Thomas cf23ca73c9 DOC import: attach sections to their paragraphs through an index of paragraph ends (#5373)
Co-authored-by: Brandon Thomas <echelon@gmail.com>
2026-11-03 09:03:10 -05:00
15 changed files with 278 additions and 39 deletions
+6 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
059cbf95c2a3eb95d637ca8584faca1129d17f48
20467b63558f04fe075e83aaea501bd10f7fa684
+5
View File
@@ -228,6 +228,11 @@ fn block_cost(b: &Block) -> (usize, bool) {
.saturating_add(p.objects.len().saturating_mul(std::mem::size_of::<InlineObject>()));
let objects = p.objects.iter().fold(0usize, |n, o| n.saturating_add(object_cost(o)));
cost = cost.saturating_add(p.text.len()).saturating_add(items).saturating_add(objects);
// The formatting a clone copies too: style ids, font names and the like in the runs,
// the mark and the paragraph's properties.
let runs = p.runs.iter().filter(|r| !r.props.is_empty()).fold(0usize, |n, r| n.saturating_add(serialized_len(&r.props)));
let props = serialized_len(&p.props).saturating_add(serialized_len(&p.mark)).saturating_add(p.section.as_ref().map_or(0, serialized_len));
cost = cost.saturating_add(runs).saturating_add(props);
boxes |= box_ids(p).next().is_some();
});
(cost, boxes)
+18
View File
@@ -415,6 +415,24 @@ fn pasted_box_copies_are_capped_in_bytes() {
assert_eq!(got.iter().flatten().count(), added);
}
#[test]
fn pasted_box_copies_count_the_formatting_they_copy() {
// A story holding a text box and a run whose font name is 1 MiB: each copy clones the
// formatting too, so 64 copies used to copy 64 MiB of it past the 32 MiB cap.
let props = CharProps { font: Some("f".repeat(1 << 20)), ..CharProps::default() };
let mut p = Paragraph::with_text("x", props);
p.insert_object(0, box_shape(Some(999)), &CharProps::default()).unwrap();
let f = fan_out(vec![para_block(p)], 64);
let mut d = doc(&["x"]);
let before = d.parts.len();
d.insert_fragment(&Pos::body(0, 1), &f).unwrap();
let added = d.parts.len() - before;
let font = |p: &Paragraph| p.runs.iter().map(|r| r.props.font.as_ref().map_or(0, String::len)).sum::<usize>();
let copied: usize = d.parts.values().flat_map(|p| p.blocks.iter()).map(|b| if let Block::Para(p) = &**b { font(p) } else { 0 }).sum();
assert!((1..64).contains(&added), "{added}");
assert!(copied <= MAX_PASTED_BOX_BYTES, "{copied}");
}
#[test]
fn pasted_box_copies_count_the_objects_they_copy() {
// #3614 review: a story holding a text box and a 1 MiB kept-for-round-trip object costs
+7 -5
View File
@@ -364,6 +364,11 @@ pub fn read_with_password(bytes: &[u8], password: Option<&str>) -> Result<Docume
// Sections: each section's properties attach to the paragraph that ends it (its story of
// header/footer parts included); the section reaching the end of the text is the final one.
let mut paras = walk(&ctx, 0, fib.ccp.text, &mut pics);
// The first paragraph ending at each CP, found once rather than by a scan per section.
let mut ending: std::collections::HashMap<u32, usize> = std::collections::HashMap::new();
for (i, p) in paras.iter().enumerate() {
ending.entry(p.end_cp).or_insert(i);
}
let last = sects.last().map(|s| s.props.clone());
for (si, sec) in sects.iter().enumerate() {
let mut props = sec.props.clone();
@@ -374,11 +379,8 @@ pub fn read_with_password(bytes: &[u8], password: Option<&str>) -> Result<Docume
if is_final {
continue; // handled below through `last`
}
for p in paras.iter_mut() {
if p.end_cp == sec.end_cp {
p.para.section = Some(Box::new(props));
break;
}
if let Some(p) = ending.get(&sec.end_cp).and_then(|&i| paras.get_mut(i)) {
p.para.section = Some(Box::new(props));
}
}
if let Some(mut l) = last {
+26 -8
View File
@@ -101,6 +101,12 @@ impl RowInfo {
self.widths.iter().rfind(|(k, _)| *k == i).map(|(_, w)| *w)
}
/// How many per-cell overrides the row keeps, for tests.
#[cfg(test)]
pub(crate) fn overrides(&self) -> usize {
self.vmerge.len() + self.shading.len() + self.widths.len() + self.width_pcts.len() + self.valign.len() + self.merges.len()
}
/// The width percentage cell `i` ends up with, for tests.
#[cfg(test)]
pub(crate) fn width_pct_of(&self, i: u8) -> Option<f32> {
@@ -108,6 +114,15 @@ impl RowInfo {
}
}
/// Set cell `c`'s override to `v`, replacing an earlier one: one slot per cell, however often
/// a PAPX repeats the sprm, so a shared PAPX can't pile up copies on every paragraph mark.
fn set<T>(slots: &mut Vec<(u8, T)>, c: u8, v: T) {
match slots.iter_mut().find(|(k, _)| *k == c) {
Some(slot) => slot.1 = v,
None => slots.push((c, v)),
}
}
pub(crate) fn decode(papx: &[u8]) -> RowInfo {
let mut r = RowInfo::default();
let mut gap_half: Option<i16> = None;
@@ -144,8 +159,10 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
T_DXA_GAP_HALF => gap_half = s16(&prl),
T_TABLE_BORDERS_80 => r.borders = table_borders(prl.operand),
T_MERGE => {
// Rows apply only the first MAX_COLS merges.
if let [a, b, ..] = prl.operand
&& b > a
&& r.merges.len() < MAX_COLS
{
r.merges.push((*a, *b));
}
@@ -158,7 +175,8 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
1 => VMerge::Continue,
_ => VMerge::None,
};
if m != VMerge::None {
// The first override for a cell wins.
if m != VMerge::None && !r.vmerge.iter().any(|(k, _)| k == itc) {
r.vmerge.push((*itc, m));
}
}
@@ -168,7 +186,7 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
&& let [a, b, ..] = prl.operand.get(1..3).unwrap_or(&[])
{
for c in *a..(*b).min(MAX_COLS as u8) {
r.shading.push((c, Some(rgb)));
set(&mut r.shading, c, Some(rgb));
}
}
}
@@ -176,7 +194,7 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
let cells = prl.operand.get(1..).unwrap_or(&[]);
for (i, b) in cells.as_chunks::<2>().0.iter().take(MAX_COLS).enumerate() {
if let Some(rgb) = shd80_rgb(b) {
r.shading.push((i as u8, Some(rgb)));
set(&mut r.shading, i as u8, Some(rgb));
}
}
}
@@ -196,7 +214,7 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
if raw && b.get(8..10) == Some(&[0xFF, 0xFF]) {
continue;
}
r.shading.push(((first + i) as u8, shd_rgb(b)));
set(&mut r.shading, (first + i) as u8, shd_rgb(b));
}
}
T_CELL_WIDTH => {
@@ -207,12 +225,12 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
if *fts == 3 {
let w = (i16::from_le_bytes([*w0, *w1]) as f32 / 20.0).clamp(0.0, 1584.0);
for c in *a..(*b).min(MAX_COLS as u8) {
r.widths.push((c, w));
set(&mut r.widths, c, w);
}
} else if *fts == 2 {
let pct = (u16::from_le_bytes([*w0, *w1]) as f32 / 50.0).clamp(0.0, 100.0);
for c in *a..(*b).min(MAX_COLS as u8) {
r.width_pcts.push((c, pct));
set(&mut r.width_pcts, c, pct);
}
}
}
@@ -224,8 +242,8 @@ pub(crate) fn decode(papx: &[u8]) -> RowInfo {
2 => VAlign::Bottom,
_ => VAlign::Top,
};
for c in *a..*b {
r.valign.push((c, v));
for c in *a..(*b).min(MAX_COLS as u8) {
set(&mut r.valign, c, v);
}
}
}
+43
View File
@@ -1018,6 +1018,32 @@ fn two_sections_box_the_first() {
assert!(!doc.last_section.title_page);
}
#[test]
fn sections_ending_off_a_paragraph_mark_attach_nowhere() {
// Hostile section ends that miss every paragraph mark are skipped; the one that ends a
// paragraph still boxes it. Paragraphs are found by their end, not scanned per section.
let mut sections: Vec<(u32, Vec<u8>)> = (1..6).map(|cp| (cp, Vec::new())).collect();
sections.push((6, grpprl(&[(0x300A, &[0x01])])));
sections.push((12, Vec::new()));
let spec = StructSpec {
text: "first\rsecond\r",
header_stories: vec![],
sections,
chpx_runs: vec![(0, Vec::new())],
papx_entries: vec![(0, 0, Vec::new()), (6, 0, Vec::new())],
plf_lst: Vec::new(),
plf_lfo: Vec::new(),
note_stories: vec![],
endnote_stories: vec![],
extra_pairs: Vec::new(),
data_stream: Vec::new(),
};
let doc = read(&struct_doc(&spec)).expect("opens");
let paras: Vec<_> = doc.body.iter().filter_map(|b| b.as_para()).collect();
assert!(paras.first().and_then(|p| p.section.as_ref()).expect("first paragraph boxed").title_page);
assert_eq!(paras.iter().filter(|p| p.section.is_some()).count(), 1, "the missing ends attach nowhere");
}
#[test]
fn header_story_becomes_part() {
let spec = StructSpec {
@@ -2375,6 +2401,23 @@ fn second_table_gets_its_own_grid() {
assert_eq!(tables[1].props.indent, None, "indent reset");
}
#[test]
fn repeated_cell_sprms_keep_one_override_per_cell() {
// A PAPX repeating cell-range sprms (shared by every paragraph mark that names it) keeps one
// slot per cell, the last value winning, instead of a copy per repetition.
let mut sprms = Vec::new();
for w in 0..200u16 {
let [w0, w1] = (w * 20).to_le_bytes();
sprms.push(sprm_cb(0xD635, &[0, 63, 3, w0, w1]));
sprms.push(sprm_cb(0xD62C, &[0, 255, 1]));
sprms.push([0x24, 0x56, 0, 2].to_vec());
}
let row = crate::table::decode(&sprms.concat());
assert_eq!(row.width_of(0), Some(199.0), "the last width wins");
assert_eq!(row.width_of(62), Some(199.0));
assert!(row.overrides() <= 63 + 255 + 63, "{}", row.overrides());
}
#[test]
fn sprm_t_cell_width_twips_and_percentage() {
// [MS-DOC] §2.9.290 sprmTCellWidth (0xD635):
+29 -9
View File
@@ -103,8 +103,8 @@ pub(super) fn balloons(app: &mut WordApp, ui: &mut Ui, painter: &egui::Painter,
let top = (anchor.y + if over_page { 4.0 } else { -12.0 }).max(next_y);
let active = app.canvas.balloon == Some(*id);
// Lay out a read-only balloon's text: the comment, then each reply under a rule,
// each with who wrote it and when. (galley, gap above, a rule above)
let mut lines: Vec<(craft_ui::text::AlignedGalley, f32, bool)> = Vec::new();
// each with who wrote it and when. (galley, gap above, a rule above, height shown)
let mut lines: Vec<(craft_ui::text::AlignedGalley, f32, bool, f32)> = Vec::new();
let card = if active {
Rect::from_min_size(pos2(x0, top), vec2(w, app.canvas.balloon_h.max(24.0)))
} else {
@@ -113,15 +113,21 @@ pub(super) fn balloons(app: &mut WordApp, ui: &mut Ui, painter: &egui::Painter,
for (i, cid) in std::iter::once(*id).chain(thread.iter().copied()).enumerate() {
let Some(r) = app.session.doc.comments.get(&cid) else { continue };
let gap = if i == 0 { 0.0 } else { 9.0 };
lines.push((balloon_text(painter, author_name(&r.author), semibold(fs), t.text, w - 16.0), gap, i > 0));
let g = balloon_text(painter, author_name(&r.author), semibold(fs), t.text, w - 16.0);
let h = g.height();
lines.push((g, gap, i > 0, h));
let when = crate::local_time::comment_time(r);
if !when.is_empty() {
lines.push((balloon_text(painter, when, small.clone(), t.text_dim, w - 16.0), 1.0, false));
let g = balloon_text(painter, when, small.clone(), t.text_dim, w - 16.0);
let h = g.height();
lines.push((g, 1.0, false, h));
}
let text = app.session.doc.plain_text(StoryRef::Part(r.part));
lines.push((balloon_text(painter, text.trim().to_string(), regular(fs), dim(resolved), w - 16.0), 4.0, false));
let g = balloon_text(painter, text.trim().to_string(), regular(fs), dim(resolved), w - 16.0);
let h = shown_height(&g);
lines.push((g, 4.0, false, h));
}
let h = lines.iter().map(|(g, gap, _)| g.height() + gap).sum::<f32>() + 12.0;
let h = lines.iter().map(|(_, gap, _, h)| h + gap).sum::<f32>() + 12.0;
Rect::from_min_size(pos2(x0, top), vec2(w, h))
};
if !card.intersects(clip) {
@@ -145,14 +151,19 @@ pub(super) fn balloons(app: &mut WordApp, ui: &mut Ui, painter: &egui::Painter,
card_shapes(painter, &t, card, color, selected, None);
let text_painter = painter.with_clip_rect(card.intersect(clip));
let mut y = card.min.y + 6.0;
for (g, gap, rule) in lines {
for (g, gap, rule, h) in lines {
y += gap;
if rule {
// A reply starts: a hairline between it and what it answers.
painter.hline(card.min.x + 10.0..=card.max.x - 8.0, y - gap / 2.0, Stroke::new(1.0, t.border));
}
let h = g.height();
g.paint(&text_painter, pos2(card.min.x + 10.0, y), t.text);
// A body cut off at its shown rows paints none of the rows below them.
let shown = if h < g.height() {
text_painter.with_clip_rect(text_painter.clip_rect().intersect(Rect::from_x_y_ranges(card.x_range(), y..=y + h)))
} else {
text_painter.clone()
};
g.paint(&shown, pos2(card.min.x + 10.0, y), t.text);
y += h;
}
let r = ui.interact(card, ui.scope_id().with(("balloon", *id)), Sense::click());
@@ -263,6 +274,15 @@ fn card_shapes(painter: &egui::Painter, t: &Tokens, card: Rect, color: Color32,
}
}
/// The height of a balloon body's first [`COMMENT_ROWS`](crate::panes::COMMENT_ROWS) rows; the
/// rest is cut off until the balloon is selected and its field scrolls.
fn shown_height(g: &craft_ui::text::AlignedGalley) -> f32 {
match g {
craft_ui::text::AlignedGalley::Aligned { galley, .. } => galley.rows.get(crate::panes::COMMENT_ROWS).map_or(g.height(), |r| r.pos.y),
craft_ui::text::AlignedGalley::InvalidWidth { .. } => g.height(),
}
}
/// A read-only balloon's text, wrapped to `width`. The fork's layout orders right-to-left and
/// mixed-direction paragraphs itself; `TextDirection::Auto` takes each paragraph's first strong
/// character. Place each already-shaped row against the card's start edge, including neutral
+84
View File
@@ -4809,3 +4809,87 @@ fn the_view_key_changes_when_a_drag_takes_an_object_off_the_page() {
assert_ne!(hidden, view_key(&app, false, None), "the page without the dragged object is rendered again");
assert_eq!(hidden, view_key(&app, false, Some(&object)), "the same drag keeps the key: no re-render every frame");
}
/// A two-paragraph document with a 200-line comment (`line` gives each line's text) on the first
/// and a short one on the second, drawn without the Comments pane; returns both comment ids.
fn long_comment_balloons(line: fn(usize) -> String) -> (egui_kittest::Harness<'static, WordApp>, u32, u32) {
let mut a = WordApp::new(
wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("Alpha paragraph one.\n\nBeta paragraph two.")),
Default::default(),
);
a.run("select.text", json!({"text": "Alpha"})).unwrap();
let long = (1..=200).map(line).collect::<Vec<_>>().join("\n");
let first = a.run("review.newComment", json!({"text": long})).unwrap()["id"].as_u64().unwrap() as u32;
a.run("select.text", json!({"text": "Beta"})).unwrap();
let second = a.run("review.newComment", json!({"text": "Short note."})).unwrap()["id"].as_u64().unwrap() as u32;
a.run("view.commentsPane", json!({"value": false})).unwrap();
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
for _ in 0..6 {
h.step();
}
(h, first, second)
}
fn balloon_rect(h: &egui_kittest::Harness<'static, WordApp>, id: u32) -> Option<egui::Rect> {
h.state().canvas.balloon_rects.iter().find(|(i, _)| *i == id).map(|(_, r)| *r)
}
/// #3382: a long comment's balloon, once selected, stops at about ten lines of text: its field
/// scrolls, so its buttons and the next comment's balloon stay in view.
#[test]
fn a_long_comment_selected_balloon_keeps_the_next_one_in_view() {
let (mut h, first, second) = long_comment_balloons(|i| format!("Line {i}"));
click_balloon(&mut h, first);
let selected = balloon_rect(&h, first).expect("the selected balloon");
assert!(selected.height() < 350.0, "the selected balloon's field scrolls instead of growing: {selected:?}");
assert!(balloon_rect(&h, second).is_some_and(|r| r.max.y < 900.0), "the next balloon is in view");
}
/// #3382: a long comment's balloon that isn't selected shows its first ten lines and cuts off the
/// rest, in either reading direction, so the next comment's balloon stays in view.
#[test]
fn a_long_comment_balloon_shows_ten_lines_and_keeps_the_next_one_in_view() {
for line in [(|i| format!("Line {i}")) as fn(usize) -> String, |i| format!("سطر {i}")] {
let (h, first, second) = long_comment_balloons(line);
let card = balloon_rect(&h, first).expect("the long balloon");
assert!(card.height() < 350.0, "the balloon stops at ten lines of its comment: {card:?}");
assert!(balloon_rect(&h, second).is_some_and(|r| r.max.y < 900.0), "the next balloon is in view");
}
}
/// #3382: a long comment's balloon that isn't selected paints its first ten rows inside the
/// card's clip and none of the rows after them, in either reading direction.
#[test]
fn a_long_comment_balloon_paints_only_its_first_ten_rows() {
for line in [(|i| format!("Line {i}")) as fn(usize) -> String, |i| format!("سطر {i}")] {
let (mut h, first, _) = long_comment_balloons(line);
h.step();
let body = (1..=200).map(line).collect::<Vec<_>>().join("\n");
let card = balloon_rect(&h, first).expect("the long balloon");
let (clip, rows) = h
.output()
.shapes
.iter()
.find_map(|clipped| match &clipped.shape {
egui::Shape::Text(text) if text.galley.text() == body => {
Some((clipped.clip_rect, text.galley.rows.iter().map(|r| r.rect().translate(text.pos.to_vec2())).collect::<Vec<_>>()))
}
_ => None,
})
.expect("the long comment's body is painted");
assert!(card.contains_rect(clip), "the body is clipped to its card: {clip:?} in {card:?}");
let (shown, hidden) = rows.split_at(crate::panes::COMMENT_ROWS);
assert!(
shown.iter().all(|r| r.min.y >= clip.min.y - 0.5 && r.max.y <= clip.max.y + 0.5),
"the first ten rows are inside the clip: {shown:?}, clip {clip:?}"
);
assert!(hidden.iter().all(|r| r.min.y >= clip.max.y - 0.5), "the rows after the tenth are cut off: {:?}, clip {clip:?}", hidden.first());
}
}
+3 -1
View File
@@ -27,7 +27,9 @@ mod state;
#[cfg(test)]
pub(crate) use comments::comment_draft;
use comments::comments;
pub(crate) use comments::{CommentDrafts, comment_editor, commit_comment, commit_reply, flush_comment_drafts, has_comment_drafts, reply_editor};
pub(crate) use comments::{
COMMENT_ROWS, CommentDrafts, comment_editor, commit_comment, commit_reply, flush_comment_drafts, has_comment_drafts, reply_editor,
};
use host::Content;
#[cfg(test)]
pub(crate) use host::apply;
+28 -10
View File
@@ -119,16 +119,17 @@ pub(crate) fn comment_editor(app: &mut WordApp, ui: &mut Ui, id: u32, font: Opti
let mut text = draft.unwrap_or_else(|| app.session.doc.plain_text(StoryRef::Part(part)));
// Read-only where comments can't change (a protected document), so nothing is typed in vain.
let editable = crate::widgets::enabled(app, "review.editComment");
let field = field_id(app, ui, "comment_edit", id);
let mut edit = egui::TextEdit::multiline(&mut text)
.id(field_id(app, ui, "comment_edit", id))
.id(field)
.interactive(editable)
.desired_rows(1)
.desired_width(f32::INFINITY)
.hint_text(tl!("Add a comment"));
if let Some(f) = font {
edit = edit.font(f);
if let Some(f) = &font {
edit = edit.font(f.clone());
}
let r = ui.add(edit);
let r = capped_field(ui, field.with("scroll"), font.as_ref(), edit);
if focus {
r.request_focus();
}
@@ -146,8 +147,24 @@ pub(crate) fn comment_editor(app: &mut WordApp, ui: &mut Ui, id: u32, font: Opti
}
}
/// A comment field's widget id, per document: egui's own state for the field (its cursor and
/// undo history) never carries over to another document's comment with the same id.
/// Lines of a comment's text that its card or balloon shows; longer text scrolls in its field and
/// is cut off in a balloon that isn't selected (#3382).
pub(crate) const COMMENT_ROWS: usize = 10;
/// The height a text field's frame and padding add to its text, in points.
const FIELD_FRAME: f32 = 4.0;
/// A comment or reply field at most [`COMMENT_ROWS`] lines tall. Longer text scrolls inside it,
/// and the field keeps its caret in view.
fn capped_field(ui: &mut Ui, scroll_id: egui::Id, font: Option<&egui::FontId>, edit: egui::TextEdit<'_>) -> egui::Response {
let font = font.cloned().unwrap_or_else(|| egui::FontSelection::Default.resolve(ui.style()));
let row = ui.fonts_mut(|f| f.row_height(&font));
let max = row * COMMENT_ROWS as f32 + FIELD_FRAME;
egui::ScrollArea::vertical().id_salt(scroll_id).max_height(max).auto_shrink([false, true]).show(ui, |ui| ui.add(edit)).inner
}
/// A comment field's widget id, per document: egui's own state for the field (its cursor, undo
/// history and scroll position) never carries over to another document's comment with the same id.
fn field_id(app: &WordApp, ui: &Ui, kind: &str, id: u32) -> egui::Id {
ui.scope_id().with((kind, app.session.document_id(), id))
}
@@ -179,16 +196,17 @@ fn thread_root(app: &WordApp, id: u32) -> u32 {
pub(crate) fn reply_editor(app: &mut WordApp, ui: &mut Ui, id: u32, font: Option<egui::FontId>, focus: bool) -> bool {
let mut text = drafts(app).replies.get(&id).cloned().unwrap_or_default();
let editable = crate::widgets::enabled(app, "review.reply");
let field = field_id(app, ui, "comment_reply", id);
let mut edit = egui::TextEdit::multiline(&mut text)
.id(field_id(app, ui, "comment_reply", id))
.id(field)
.interactive(editable)
.desired_rows(1)
.desired_width(f32::INFINITY)
.hint_text(tl!("Write a reply"));
if let Some(f) = font {
edit = edit.font(f);
if let Some(f) = &font {
edit = edit.font(f.clone());
}
let r = ui.add(edit);
let r = capped_field(ui, field.with("scroll"), font.as_ref(), edit);
if focus {
r.request_focus();
}
+23
View File
@@ -445,3 +445,26 @@ fn built_in_styles_grey_out_delete_in_the_styles_pane() {
assert!(delete_is_disabled("Normal"), "the built-in style's Delete is greyed out");
assert!(!delete_is_disabled("Callout"), "the custom style's Delete stays enabled");
}
/// #3382: a long comment's card in the Comments pane stops at ten lines of text, so its buttons
/// and the card after it stay in view.
#[test]
#[cfg(not(target_arch = "wasm32"))]
fn a_long_comment_card_keeps_its_buttons_and_the_next_card_in_view() {
use egui_kittest::kittest::Queryable;
let mut app = crate::WordApp::new(
wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("Alpha paragraph one.\n\nBeta paragraph two.")),
crate::Services::default(),
);
app.run("select.text", serde_json::json!({"text": "Alpha"})).unwrap();
let long = (1..=200).map(|i| format!("Line {i}")).collect::<Vec<_>>().join("\n");
app.run("review.newComment", serde_json::json!({"text": long})).unwrap();
app.run("select.text", serde_json::json!({"text": "Beta"})).unwrap();
app.run("review.newComment", serde_json::json!({"text": "Short note."})).unwrap();
app.run("view.commentsPane", serde_json::json!({"value": true})).unwrap();
let h = pane_harness(app);
let go_to: Vec<egui::Rect> = h.get_all_by_label("Go to").map(|n| n.rect()).collect();
assert_eq!(go_to.len(), 2, "one Go to button per card");
assert!(go_to.iter().all(|r| r.max.y < 900.0), "both cards' buttons are in view: {go_to:?}");
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -2
View File
File diff suppressed because one or more lines are too long
@@ -126,6 +126,6 @@ modules:
# the two equal).
- type: git
url: https://github.com/storytold/craft-i18n
commit: 059cbf95c2a3eb95d637ca8584faca1129d17f48
commit: 20467b63558f04fe075e83aaea501bd10f7fa684
dest: craft-i18n
- cargo-sources.json