Skip to content

Commit

Permalink
Merge branch 'nushell:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma authored Feb 13, 2024
2 parents 9421aa9 + f773192 commit 0911696
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/painting/styled_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl StyledText {
match (start_position, end_position) {
(Position::Before, Position::After) => {
let mut in_range = pair.1.split_off(from - current_idx);
let after_range = in_range.split_off(to - current_idx - from);
let after_range = in_range.split_off(to - from);
let in_range = (new_style, in_range);
let after_range = (pair.0, after_range);
self.buffer.insert(pair_idx + 1, in_range);
Expand Down Expand Up @@ -255,4 +255,21 @@ mod test {
assert_eq!(styled_text.buffer[1], (after_style, "d".into()));
assert_eq!(styled_text.buffer[2], (before_style, "f".into()));
}
#[test]
fn regression_style_range_cargo_run() {
let (_, before_style, after_style) = get_styled_text_template();
let mut styled_text = StyledText {
buffer: vec![
(before_style, "cargo".into()),
(before_style, " ".into()),
(before_style, "run".into()),
],
};
styled_text.style_range(8, 7, after_style);
assert_eq!(styled_text.buffer[0], (before_style, "cargo".into()));
assert_eq!(styled_text.buffer[1], (before_style, " ".into()));
assert_eq!(styled_text.buffer[2], (before_style, "r".into()));
assert_eq!(styled_text.buffer[3], (after_style, "u".into()));
assert_eq!(styled_text.buffer[4], (before_style, "n".into()));
}
}

0 comments on commit 0911696

Please sign in to comment.