From bff7f36c5b079a7aade369280c9eebee5a717737 Mon Sep 17 00:00:00 2001 From: Bu5hm4nn Date: Fri, 27 Oct 2023 17:22:24 -0600 Subject: [PATCH] Tagging: Fix crash when not iterating replacements in order --- gossip-bin/src/ui/feed/post.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gossip-bin/src/ui/feed/post.rs b/gossip-bin/src/ui/feed/post.rs index 1ee9487d..d02853f2 100644 --- a/gossip-bin/src/ui/feed/post.rs +++ b/gossip-bin/src/ui/feed/post.rs @@ -56,6 +56,12 @@ pub fn textarea_highlighter(theme: Theme, text: String, interests: Vec) 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()) {