Fix mention color of non-ascii nicks

The old code included the @ in mention color computations. If the nick
consisted only of weird unicode characters, this resulted in an
incorrect color being computed.
This commit is contained in:
Joscha 2025-02-23 22:03:42 +01:00
parent 9435fbece6
commit b4c4a89625
2 changed files with 16 additions and 2 deletions

View file

@ -138,8 +138,8 @@ pub fn apply_spans(
let text = &content[range.start..range.end]; let text = &content[range.start..range.end];
result = match span { result = match span {
SpanType::Mention if exact => result.and_then(util::style_nick_exact(text, base)), SpanType::Mention if exact => result.and_then(util::style_mention_exact(text, base)),
SpanType::Mention => result.and_then(util::style_nick(text, base)), SpanType::Mention => result.and_then(util::style_mention(text, base)),
SpanType::Room => result.then(text, base.blue().bold()), SpanType::Room => result.then(text, base.blue().bold()),
SpanType::Emoji if exact => result.then(text, base.magenta()), SpanType::Emoji if exact => result.then(text, base.magenta()),
SpanType::Emoji => { SpanType::Emoji => {

View file

@ -55,3 +55,17 @@ pub fn style_nick(nick: &str, base: Style) -> Styled {
pub fn style_nick_exact(nick: &str, base: Style) -> Styled { pub fn style_nick_exact(nick: &str, base: Style) -> Styled {
Styled::new(nick, nick_style(nick, base)) Styled::new(nick, nick_style(nick, base))
} }
pub fn style_mention(mention: &str, base: Style) -> Styled {
let nick = mention
.strip_prefix('@')
.expect("mention must start with @");
Styled::new(EMOJI.replace(mention), nick_style(nick, base))
}
pub fn style_mention_exact(mention: &str, base: Style) -> Styled {
let nick = mention
.strip_prefix('@')
.expect("mention must start with @");
Styled::new(mention, nick_style(nick, base))
}