Keep separators at start of the croped string

This commit is contained in:
ManyTheFish 2022-03-30 14:00:06 +02:00
parent 29c5f76d7f
commit bd30ee97b8

View File

@ -247,6 +247,15 @@ impl<'t> Matcher<'t, '_> {
last_token_position += 1;
}
// same for start
while let Some(_separator_kind) = first_token_position
.checked_sub(1)
.and_then(|i| self.tokens.get(i))
.and_then(|t| t.is_separator())
{
first_token_position -= 1;
}
(first_token_position, last_token_position)
}
@ -563,7 +572,7 @@ mod tests {
// should crop the phrase instead of croping around the match.
assert_eq!(
&matcher.format(highlight, crop),
"Split The World is a book written by Emily Henry. …"
". Split The World is a book written by Emily Henry. …"
);
// Text containing some matches.