Rearranged mouse handling

This commit is contained in:
Mikayla Maki 2022-10-16 17:31:19 -07:00
parent 3e23d1f48d
commit f1ff557a25

View File

@ -1018,33 +1018,13 @@ impl Terminal {
self.last_content.size,
self.last_content.display_offset,
);
// let side = mouse_side(position, self.last_content.size);
if self.mouse_mode(e.shift) {
if let Some(bytes) = mouse_button_report(point, e, true, self.last_content.mode) {
self.pty_tx.notify(bytes);
}
} else if e.button == MouseButton::Left {
self.left_click(e, origin)
}
}
pub fn left_click(&mut self, e: &DownRegionEvent, origin: Vector2F) {
let position = e.position.sub(origin);
if !self.mouse_mode(e.shift) {
//Hyperlinks
{
let mouse_cell_index = content_index_for_mouse(position, &self.last_content);
if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() {
open_uri(link.uri()).log_err();
} else {
self.events
.push_back(InternalEvent::FindHyperlink(position, true));
}
}
// Selections
{
let point = grid_point(
position,
self.last_content.size,
@ -1060,8 +1040,8 @@ impl Terminal {
_ => None,
};
let selection = selection_type
.map(|selection_type| Selection::new(selection_type, point, side));
let selection =
selection_type.map(|selection_type| Selection::new(selection_type, point, side));
if let Some(sel) = selection {
self.events
@ -1069,7 +1049,6 @@ impl Terminal {
}
}
}
}
pub fn mouse_up(&mut self, e: &UpRegionEvent, origin: Vector2F, cx: &mut ModelContext<Self>) {
let settings = cx.global::<Settings>();
@ -1094,10 +1073,23 @@ impl Terminal {
if let Some(bytes) = mouse_button_report(point, e, false, self.last_content.mode) {
self.pty_tx.notify(bytes);
}
} else if e.button == MouseButton::Left && copy_on_select {
} else {
if e.button == MouseButton::Left && copy_on_select {
self.copy();
}
//Hyperlinks
if self.selection_phase == SelectionPhase::Ended {
let mouse_cell_index = content_index_for_mouse(position, &self.last_content);
if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() {
open_uri(link.uri()).log_err();
} else {
self.events
.push_back(InternalEvent::FindHyperlink(position, true));
}
}
}
self.selection_phase = SelectionPhase::Ended;
self.last_mouse = None;
}