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 bd57967
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 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.

12 changes: 9 additions & 3 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 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 bd57967

Please sign in to comment.