Fix get_contents for headlines.

This commit is contained in:
Tom Alexander
2023-12-15 13:14:49 -05:00
parent bb472b63cc
commit ffa5349f25
2 changed files with 9 additions and 26 deletions

View File

@@ -35,6 +35,7 @@ pub struct Heading<'s> {
pub scheduled: Option<Timestamp<'s>>,
pub deadline: Option<Timestamp<'s>>,
pub closed: Option<Timestamp<'s>>,
pub contents: Option<&'s str>,
}
#[derive(Debug)]
@@ -119,32 +120,7 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
let first_child = self.children.first();
let last_child = self.children.last();
match (first_child, last_child) {
(None, None) => None,
(None, Some(_)) | (Some(_), None) => unreachable!(),
(Some(first_child), Some(last_child)) => {
let first_child_offset = first_child.get_source().as_ptr() as usize;
let last_child_offset = {
let last_child_source = last_child.get_source();
last_child_source.as_ptr() as usize + last_child_source.len()
};
let source_offset = self.source.as_ptr() as usize;
debug_assert!(super::lesser_element::is_slice_of(
self.source,
first_child.get_source()
));
debug_assert!(super::lesser_element::is_slice_of(
self.source,
last_child.get_source()
));
Some(
&self.source[(first_child_offset - source_offset)
..(last_child_offset - first_child_offset)],
)
}
}
self.contents
}
fn get_post_blank(&self) -> PostBlank {