Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributedString::set_text_color uses range end as a length #124

Open
mndstrmr opened this issue Aug 9, 2024 · 1 comment
Open

AttributedString::set_text_color uses range end as a length #124

mndstrmr opened this issue Aug 9, 2024 · 1 comment

Comments

@mndstrmr
Copy link

mndstrmr commented Aug 9, 2024

In AttributedString::set_text_color and AttributedString::set_font, range.end is used as the length field to CFRange::init, which unless I am mistaken seems wrong to me.

The documentation implies that if I set the set range 3..4 to red, I would change only character 3 to be red, not 3 through 6, which is what currently happens.

The relevant code is here:

/// Sets the text (foreground) color for the specified range.
pub fn set_text_color<C: AsRef<Color>>(&mut self, color: C, range: Range<isize>) {
let color: id = color.as_ref().into();
let range = CFRange::init(range.start, range.end);
unsafe {
let _: () = msg_send![
&*self.0,
addAttribute: NSForegroundColorAttributeName,
value: color,
range: range,
];
}
}

@ryanmcgrath
Copy link
Owner

which unless I am mistaken

I do not believe you are. :)

A PR is welcome, otherwise I'll get to it in the next batch of fixes once I find the time. Thanks for the callout!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants