Skip to content

Commit

Permalink
Fix off by one error in highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
vesdev committed Aug 3, 2024
1 parent f8cfa57 commit 2aeec9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/handlers/data.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -396,8 +397,9 @@ impl MessageData {
static EMOTE_FINDER: Lazy<memmem::Finder> =
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())
{
Expand All @@ -407,7 +409,7 @@ impl MessageData {
default_style,
search_highlight,
username_highlight,
)
);
} else {
let mut spans: Vec<Span<'s>> = vec![];

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2aeec9e

Please sign in to comment.