Add code to set selection

This commit is contained in:
Jeremy Soller 2023-12-21 15:09:18 -07:00
parent 81e1062211
commit 968955230c
2 changed files with 53 additions and 28 deletions

View file

@ -27,10 +27,10 @@ pub use alacritty_terminal::grid::Scroll as TerminalScroll;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Size { pub struct Size {
width: u32, pub width: u32,
height: u32, pub height: u32,
cell_width: f32, pub cell_width: f32,
cell_height: f32, pub cell_height: f32,
} }
impl Dimensions for Size { impl Dimensions for Size {
@ -59,7 +59,7 @@ impl From<Size> for WindowSize {
} }
#[derive(Clone)] #[derive(Clone)]
struct EventProxy( pub struct EventProxy(
segmented_button::Entity, segmented_button::Entity,
mpsc::Sender<(segmented_button::Entity, Event)>, mpsc::Sender<(segmented_button::Entity, Event)>,
); );
@ -96,7 +96,7 @@ pub struct Terminal {
default_attrs: Attrs<'static>, default_attrs: Attrs<'static>,
buffer: Arc<Buffer>, buffer: Arc<Buffer>,
size: Size, size: Size,
term: Arc<FairMutex<Term<EventProxy>>>, pub term: Arc<FairMutex<Term<EventProxy>>>,
colors: Colors, colors: Colors,
notifier: Notifier, notifier: Notifier,
} }

View file

@ -1,5 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use alacritty_terminal::{
index::{Column as TermColumn, Line as TermLine, Point as TermPoint, Side as TermSide},
selection::{Selection, SelectionType},
};
use cosmic::{ use cosmic::{
iced::{ iced::{
advanced::graphics::text::{font_system, Raw}, advanced::graphics::text::{font_system, Raw},
@ -453,22 +457,32 @@ where
} else { } else {
ClickKind::Single ClickKind::Single
}; };
/*TODO //TODO: better calculation of position
match click_kind { let col = x / terminal.size().cell_width;
ClickKind::Single => editor.action(Action::Click { let row = y / terminal.size().cell_height;
x: x as i32, //TODO: scroll row
y: y as i32, let location =
}), TermPoint::new(TermLine(row as i32), TermColumn(col as usize));
ClickKind::Double => editor.action(Action::DoubleClick { let side = if col.fract() < 0.5 {
x: x as i32, TermSide::Left
y: y as i32, } else {
}), TermSide::Right
ClickKind::Triple => editor.action(Action::TripleClick { };
x: x as i32, let selection = match click_kind {
y: y as i32, ClickKind::Single => {
}), Selection::new(SelectionType::Simple, location, side)
}
ClickKind::Double => {
Selection::new(SelectionType::Semantic, location, side)
}
ClickKind::Triple => {
Selection::new(SelectionType::Lines, location, side)
}
};
{
let mut term = terminal.term.lock();
term.selection = Some(selection);
} }
*/
state.click = Some((click_kind, Instant::now())); state.click = Some((click_kind, Instant::now()));
state.dragging = Some(Dragging::Buffer); state.dragging = Some(Dragging::Buffer);
} else if scrollbar_rect.contains(Point::new(x, y)) { } else if scrollbar_rect.contains(Point::new(x, y)) {
@ -514,16 +528,27 @@ where
Event::Mouse(MouseEvent::CursorMoved { .. }) => { Event::Mouse(MouseEvent::CursorMoved { .. }) => {
if let Some(dragging) = &state.dragging { if let Some(dragging) = &state.dragging {
if let Some(p) = cursor_position.position() { if let Some(p) = cursor_position.position() {
let _x = (p.x - layout.bounds().x) - self.padding.left; let x = (p.x - layout.bounds().x) - self.padding.left;
let y = (p.y - layout.bounds().y) - self.padding.top; let y = (p.y - layout.bounds().y) - self.padding.top;
match dragging { match dragging {
Dragging::Buffer => { Dragging::Buffer => {
/*TODO //TODO: better calculation of position
editor.action(Action::Drag { let col = x / terminal.size().cell_width;
x: x as i32, let row = y / terminal.size().cell_height;
y: y as i32, //TODO: scroll row
}); let location =
*/ TermPoint::new(TermLine(row as i32), TermColumn(col as usize));
let side = if col.fract() < 0.5 {
TermSide::Left
} else {
TermSide::Right
};
{
let mut term = terminal.term.lock();
if let Some(selection) = &mut term.selection {
selection.update(location, side);
}
}
} }
Dragging::Scrollbar { Dragging::Scrollbar {
start_y, start_y,