diff --git a/Cargo.lock b/Cargo.lock index b0d51e53..e1b24b7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,13 +19,14 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -3041,6 +3042,26 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zeroize" version = "1.8.1" diff --git a/src/handlers/data.rs b/src/handlers/data.rs index 5df06dd8..15d4dd06 100644 --- a/src/handlers/data.rs +++ b/src/handlers/data.rs @@ -1,4 +1,5 @@ use chrono::{offset::Local, DateTime}; +use futures::stream::Next; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; use log::{error, warn}; use memchr::memmem; @@ -396,8 +397,9 @@ impl MessageData { static EMOTE_FINDER: Lazy = Lazy::new(|| memmem::Finder::new(ZERO_WIDTH_SPACE_STR)); + let line_is_empty = line.is_empty(); // A line contains emotes if `emotes` is not empty and `line` starts with a unicode placeholder or contains ZWS. - if emotes.is_empty() + let spans = if emotes.is_empty() || (!line.starts_with(PRIVATE_USE_UNICODE) && EMOTE_FINDER.find(line.as_bytes()).is_none()) { @@ -407,7 +409,7 @@ impl MessageData { default_style, search_highlight, username_highlight, - ) + ); } else { let mut spans: Vec> = vec![]; @@ -436,7 +438,11 @@ impl MessageData { *start_index = start_index.saturating_sub(ZERO_WIDTH_SPACE_STR.len()); spans + }; + if !line_is_empty { + *start_index += 1; } + spans } pub fn to_vec( @@ -846,7 +852,7 @@ mod tests { assert_eq!(emotes, EMOTES_ID_PID); - assert_eq!(start_index, line.len()); + assert_eq!(start_index - 1, line.len()); assert_eq!( spans, @@ -899,7 +905,7 @@ mod tests { ); assert!(emotes.is_empty()); - assert_eq!(start_index, line.len()); + assert_eq!(start_index - 1, line.len()); assert_eq!( spans,