Skip to content

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

@mndstrmr

Description

@mndstrmr

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,
];
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions