Tagging: Fix crash when not iterating replacements in order

This commit is contained in:
Bu5hm4nn 2023-10-27 17:22:24 -06:00
parent cadaa89d15
commit bff7f36c5b

View File

@ -56,6 +56,12 @@ pub fn textarea_highlighter(theme: Theme, text: String, interests: Vec<String>)
let chunk = shattered_content.slice(span).unwrap();
let mut pos = 0;
// following code only works if interests are sorted the way
// they occur in the text
let mut interests = interests.to_owned();
interests.sort_by(|a, b| { chunk.find(a).cmp(&chunk.find(b)) });
// any entry in interests gets it's own layout section
for interest in &interests {
if let Some(ipos) = chunk.find(interest.as_str()) {