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::{Event, EventListener, Notify, OnResize, WindowSize},
event_loop::{EventLoop, Msg, Notifier}, event_loop::{EventLoop, Msg, Notifier},
grid::Dimensions, grid::Dimensions,
index::Point,
sync::FairMutex, sync::FairMutex,
term::{ term::{
cell::Flags, cell::Flags,
color::{Colors, Rgb}, color::{Colors, Rgb},
TermMode, viewport_to_point, TermMode,
}, },
tty, Term, tty, Term,
}; };
@ -399,6 +400,11 @@ impl Terminal {
self.buffer.redraw() 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 { impl Drop for Terminal {

View file

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