fix: limit linewise highlighting to copied text

This commit is contained in:
2026-10-10 17:46:11 +02:00
parent 27b94744f0
commit 287865735f
3 changed files with 26 additions and 11 deletions
+24 -9
View File
@@ -670,9 +670,13 @@ fn draw(
let first = (*rows.start()).max(*top);
let last = (*rows.end()).min(top.saturating_add(height - 1));
for row in first..=last {
let end = display_column(&editor.lines()[row], usize::MAX)
.saturating_add(1)
.min(left.saturating_add(width));
let y = viewport.y + (row - *top) as u16;
for x in viewport.x..viewport.x + viewport.width {
frame.buffer_mut()[(x, y)].set_style(selection_style);
for column in *left..end {
frame.buffer_mut()[(viewport.x + (column - *left) as u16, y)]
.set_style(selection_style);
}
}
}
@@ -5568,19 +5572,21 @@ end
}
#[test]
fn linewise_selection_fills_blank_and_final_rows_without_coloring_gutter() {
fn linewise_selection_highlights_copied_text_and_newlines_without_filling_rows() {
let mut editor = Editor::open(None, vec![]).unwrap();
editor
.apply(vec![crate::editor::Effect::Replace("long text\n\n".into())])
.apply(vec![crate::editor::Effect::Replace(
"\t界e\u{301} \n\n".into(),
)])
.unwrap();
editor.handle(Input::Char('V'));
editor.handle(Input::Down);
editor.handle(Input::Down);
let before = (editor.lines().to_vec(), editor.cursor(), editor.carets());
for width in [12, 3, 1] {
for width in [16, 3, 1] {
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(width, 6)).unwrap();
let (mut top, mut left) = (0, 0);
terminal
let frame = terminal
.draw(|frame| {
draw(
frame,
@@ -5593,8 +5599,8 @@ end
)
})
.unwrap();
let buffer = terminal.backend().buffer();
if width == 12 {
let buffer = frame.buffer;
if width == 16 {
let status: String = (0..width).map(|x| buffer[(x, 4)].symbol()).collect();
assert!(status.contains("VISUAL LINE"), "{status}");
}
@@ -5603,8 +5609,17 @@ end
for x in 0..gutter {
assert_ne!(buffer[(x, row)].bg, Color::Blue);
}
let selected_width = if row == 0 { 10 } else { 1 };
for x in gutter..width {
assert_eq!(buffer[(x, row)].bg, Color::Blue);
if x - gutter < selected_width {
assert_eq!(
buffer[(x, row)].bg,
Color::Blue,
"width {width}, row {row}, x {x}"
);
} else {
assert_ne!(buffer[(x, row)].bg, Color::Blue);
}
}
}
for x in 0..width {