Fix selection when scrolling

This commit is contained in:
Jeremy Soller 2023-12-21 22:21:01 -07:00
parent 4ffad110b6
commit 94dd278f53
2 changed files with 16 additions and 8 deletions

View file

@ -4,11 +4,12 @@ use alacritty_terminal::{
event::{Event, EventListener, Notify, OnResize, WindowSize},
event_loop::{EventLoop, Msg, Notifier},
grid::Dimensions,
index::Point,
sync::FairMutex,
term::{
cell::Flags,
color::{Colors, Rgb},
TermMode,
viewport_to_point, TermMode,
},
tty, Term,
};
@ -399,6 +400,11 @@ impl Terminal {
self.buffer.redraw()
}
pub fn viewport_to_point(&self, point: Point<usize>) -> Point {
let term = self.term.lock();
viewport_to_point(term.grid().display_offset(), point)
}
}
impl Drop for Terminal {

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
use alacritty_terminal::{
index::{Column as TermColumn, Line as TermLine, Point as TermPoint, Side as TermSide},
index::{Column as TermColumn, Point as TermPoint, Side as TermSide},
selection::{Selection, SelectionType},
};
use cosmic::{
@ -466,9 +466,10 @@ where
//TODO: better calculation of position
let col = x / terminal.size().cell_width;
let row = y / terminal.size().cell_height;
//TODO: scroll row
let location =
TermPoint::new(TermLine(row as i32), TermColumn(col as usize));
let location = terminal.viewport_to_point(TermPoint::new(
row as usize,
TermColumn(col as usize),
));
let side = if col.fract() < 0.5 {
TermSide::Left
} else {
@ -542,9 +543,10 @@ where
//TODO: better calculation of position
let col = x / terminal.size().cell_width;
let row = y / terminal.size().cell_height;
//TODO: scroll row
let location =
TermPoint::new(TermLine(row as i32), TermColumn(col as usize));
let location = terminal.viewport_to_point(TermPoint::new(
row as usize,
TermColumn(col as usize),
));
let side = if col.fract() < 0.5 {
TermSide::Left
} else {