Choose primary label from inside the context

This commit is contained in:
Lucas Holten 2023-12-13 12:55:05 +01:00
parent d4f30ec501
commit 997a3ea782
1 changed files with 9 additions and 3 deletions

View File

@ -446,10 +446,16 @@ impl GraphicalReportHandler {
) -> fmt::Result {
let (contents, lines) = self.get_lines(source, context.inner())?;
let primary_label = labels
.iter()
// only consider labels from the context as primary label
let ctx_labels = labels.iter().filter(|l| {
context.inner().offset() <= l.inner().offset()
&& l.inner().offset() + l.inner().len()
<= context.inner().offset() + context.inner().len()
});
let primary_label = ctx_labels
.clone()
.find(|label| label.primary())
.or_else(|| labels.first());
.or_else(|| ctx_labels.clone().next());
// sorting is your friend
let labels = labels