diff --git a/CHANGELOG.md b/CHANGELOG.md index f1c8c5d..1fbbb25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file. ### ๐Ÿ› Bug Fixes -- PR comment emoji prefix detection - ([1e36edf](https://codeberg.org/ThetaDev/artifactview/commit/1e36edf49978e8ba24a85d4663ff3ebaf9642a29)) +- PR comment emoji prefix detection - ([ed0fbc3](https://codeberg.org/ThetaDev/artifactview/commit/ed0fbc38b2a1e76f070697f766812a20c84149ee)) ## [v0.4.1](https://codeberg.org/ThetaDev/artifactview/compare/v0.4.0..v0.4.1) - 2024-06-22 diff --git a/src/app.rs b/src/app.rs index ea76c4d..b737943 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,5 @@ use std::{ + borrow::Cow, collections::{BTreeMap, HashMap}, fmt::Write, net::{IpAddr, SocketAddr}, @@ -865,7 +866,19 @@ fn pr_comment_text(p: PrCommentTextParams) -> String { }; let write_link_icon = |s: &mut String, title: &str, href: &str| { - let (title_pfx, title) = util::split_icon_prefix(title); + // Move leading emoji into a prefix variable since including them in the link does not look good + let mut title_pfx = String::new(); + let mut title = Cow::Borrowed(title); + if let Some((i, c)) = title + .char_indices() + .find(|(_, c)| c.is_ascii() || c.is_alphanumeric()) + { + if i > 0 && c == ' ' { + title[..i + 1].clone_into(&mut title_pfx); + title = title[i + 1..].to_owned().into(); + } + } + _ = write!( s, r#"{title_pfx}{title}"#, diff --git a/src/util.rs b/src/util.rs index d5d43c0..4fa6dba 100644 --- a/src/util.rs +++ b/src/util.rs @@ -302,18 +302,6 @@ pub fn extract_delim<'a>(s: &'a str, start: &str, end: &str) -> Option<&'a str> None } -pub fn split_icon_prefix(s: &str) -> (&str, &str) { - if let Some((i, c)) = s - .char_indices() - .find(|(_, c)| c.is_ascii() || c.is_alphanumeric()) - { - if i > 0 && c == ' ' && s.get(i + 1..).is_some() { - return (&s[..i + 1], &s[i + 1..]); - } - } - ("", s) -} - #[cfg(test)] pub(crate) mod tests { use std::path::{Path, PathBuf}; @@ -402,16 +390,4 @@ pub(crate) mod tests { let res = super::filename_ext(filename); assert_eq!(res, expect); } - - #[rstest] - #[case("๐Ÿงช Test", ("๐Ÿงช ", "Test"))] - #[case("๐Ÿงช๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ Test", ("๐Ÿงช๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ ", "Test"))] - #[case("๐Ÿงช ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ Test", ("๐Ÿงช ", "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ Test"))] - #[case("", ("", ""))] - #[case("Test", ("", "Test"))] - #[case("้‹ๅ‘ฝ Test", ("", "้‹ๅ‘ฝ Test"))] - fn split_icon_prefix(#[case] s: &str, #[case] expect: (&str, &str)) { - let res = super::split_icon_prefix(s); - assert_eq!(res, expect); - } }