mirror of
https://github.com/alacritty/alacritty.git
synced 2025-10-09 23:24:56 -04:00
Fix selection in scrollback
There were a few issues with selection in scrollback that were mainly off-by-one errors. This aims at fixing these issues. This also fixes a bug that currently exists in master where the last cell is not selected when the mouse leaves the window to the right.
This commit is contained in:
parent
a741193bc0
commit
f8e36d1663
3 changed files with 15 additions and 8 deletions
|
@ -274,7 +274,10 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
||||||
let cell_x = (x as usize - size_info.padding_x as usize) % size_info.cell_width as usize;
|
let cell_x = (x as usize - size_info.padding_x as usize) % size_info.cell_width as usize;
|
||||||
let half_cell_width = (size_info.cell_width / 2.0) as usize;
|
let half_cell_width = (size_info.cell_width / 2.0) as usize;
|
||||||
|
|
||||||
let cell_side = if cell_x > half_cell_width {
|
let cell_side = if cell_x > half_cell_width
|
||||||
|
// Edge case when mouse leaves the window
|
||||||
|
|| x as f32 >= size_info.width - size_info.padding_x
|
||||||
|
{
|
||||||
Side::Right
|
Side::Right
|
||||||
} else {
|
} else {
|
||||||
Side::Left
|
Side::Left
|
||||||
|
|
|
@ -191,8 +191,6 @@ impl Selection {
|
||||||
(region.end, region.start)
|
(region.end, region.start)
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("BEFORE front={:?}, start={:?}, tail={:?}, end={:?}", front, start, tail, end);
|
|
||||||
|
|
||||||
if front < tail && front.line == tail.line {
|
if front < tail && front.line == tail.line {
|
||||||
start = grid.semantic_search_left(front);
|
start = grid.semantic_search_left(front);
|
||||||
end = grid.semantic_search_right(tail);
|
end = grid.semantic_search_right(tail);
|
||||||
|
@ -201,8 +199,6 @@ impl Selection {
|
||||||
end = grid.semantic_search_left(tail);
|
end = grid.semantic_search_left(tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("AFTER front={:?}, start={:?}, tail={:?}, end={:?}", front, start, tail, end);
|
|
||||||
|
|
||||||
if start > end {
|
if start > end {
|
||||||
::std::mem::swap(&mut start, &mut end);
|
::std::mem::swap(&mut start, &mut end);
|
||||||
}
|
}
|
||||||
|
@ -249,12 +245,21 @@ impl Selection {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span_simple<G: Dimensions>(grid: &G, region: &Range<Anchor>) -> Option<Span> {
|
fn span_simple<G: Dimensions>(grid: &G, region: &Range<Anchor>) -> Option<Span> {
|
||||||
let start = region.start.point;
|
let mut start = region.start.point;
|
||||||
let start_side = region.start.side;
|
let start_side = region.start.side;
|
||||||
let end = region.end.point;
|
let mut end = region.end.point;
|
||||||
let end_side = region.end.side;
|
let end_side = region.end.side;
|
||||||
let cols = grid.dimensions().col;
|
let cols = grid.dimensions().col;
|
||||||
|
|
||||||
|
// Handle some edge cases
|
||||||
|
if start.line > end.line {
|
||||||
|
start.col += 1;
|
||||||
|
end.col -= 1;
|
||||||
|
} else if start.line < end.line {
|
||||||
|
start.col -= 1;
|
||||||
|
end.col += 1;
|
||||||
|
}
|
||||||
|
|
||||||
let (front, tail, front_side, tail_side) = if start > end {
|
let (front, tail, front_side, tail_side) = if start > end {
|
||||||
// Selected upward; start/end are swapped
|
// Selected upward; start/end are swapped
|
||||||
(end, start, end_side, start_side)
|
(end, start, end_side, start_side)
|
||||||
|
|
|
@ -1058,7 +1058,6 @@ impl Term {
|
||||||
let selection = self.grid.selection.as_ref()
|
let selection = self.grid.selection.as_ref()
|
||||||
.and_then(|s| s.to_span(self))
|
.and_then(|s| s.to_span(self))
|
||||||
.map(|span| {
|
.map(|span| {
|
||||||
// println!("span={:?}, locations={:?}", span, span.to_locations());
|
|
||||||
span.to_locations()
|
span.to_locations()
|
||||||
});
|
});
|
||||||
let cursor = if window_focused {
|
let cursor = if window_focused {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue