mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-02 22:50:27 -06:00
Lists: an empty paragraph gets no bullet or number
A list paragraph with no characters before its return draws no label, and numbering carries on past it: in a story's own list, in named lists (also across stories) and in cross-reference paragraph numbers.
This commit is contained in:
@@ -235,9 +235,9 @@ impl crate::Document {
|
||||
before.sort_by_key(|st| key(st));
|
||||
let mut n = 0u32;
|
||||
for st in before {
|
||||
for p in &st.paras {
|
||||
for (p, r) in st.paras.iter().zip(st.para_ranges()) {
|
||||
let (pp, _) = self.styles.resolve_para(p);
|
||||
if pp.list_type == crate::ListType::Numbers && pp.list_name == name {
|
||||
if pp.list_type == crate::ListType::Numbers && pp.list_name == name && !r.is_empty() {
|
||||
n = pp.start_at.map_or(n.saturating_add(1), |s| s.max(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,12 +347,17 @@ impl Document {
|
||||
let (sid, pos) = self.find_anchor(id)?;
|
||||
let st = self.story(sid)?;
|
||||
let pi = st.para_at(pos);
|
||||
let r = st.para_ranges()[pi].clone();
|
||||
let ranges = st.para_ranges();
|
||||
let r = ranges[pi].clone();
|
||||
let (pp, _) = self.styles.resolve_para(&st.paras[pi]);
|
||||
let para_num = match pp.list_type {
|
||||
crate::ListType::Numbers => {
|
||||
// Count the run of numbered paragraphs before this one.
|
||||
let n = (0..=pi).rev().take_while(|&k| self.styles.resolve_para(&st.paras[k]).0.list_type == crate::ListType::Numbers).count();
|
||||
crate::ListType::Numbers if !r.is_empty() => {
|
||||
// Count the run of numbered paragraphs before this one (empty ones have no number).
|
||||
let n = (0..=pi)
|
||||
.rev()
|
||||
.take_while(|&k| self.styles.resolve_para(&st.paras[k]).0.list_type == crate::ListType::Numbers)
|
||||
.filter(|&k| ranges.get(k).is_some_and(|r| !r.is_empty()))
|
||||
.count();
|
||||
pp.number_label(u32::try_from(n).unwrap_or(u32::MAX)).trim_end().to_string()
|
||||
}
|
||||
_ => String::new(),
|
||||
|
||||
Reference in New Issue
Block a user