Fix terminal selection when cursor leaves terminal bounds

This commit is contained in:
Max Brunsfeld 2024-01-04 14:08:18 -08:00
parent 5e3d4885bf
commit 0c4e2ef419

View file

@ -2,10 +2,11 @@ use editor::{Cursor, HighlightedRange, HighlightedRangeLine};
use gpui::{ use gpui::{
div, fill, point, px, red, relative, AnyElement, AsyncWindowContext, AvailableSpace, div, fill, point, px, red, relative, AnyElement, AsyncWindowContext, AvailableSpace,
BorrowWindow, Bounds, DispatchPhase, Element, ElementId, ExternalPaths, FocusHandle, Font, BorrowWindow, Bounds, DispatchPhase, Element, ElementId, ExternalPaths, FocusHandle, Font,
FontStyle, FontWeight, HighlightStyle, Hsla, InteractiveElement, InteractiveElementState, FontStyle, FontWeight, HighlightStyle, Hsla, InteractiveBounds, InteractiveElement,
Interactivity, IntoElement, LayoutId, Model, ModelContext, ModifiersChangedEvent, MouseButton, InteractiveElementState, Interactivity, IntoElement, LayoutId, Model, ModelContext,
Pixels, PlatformInputHandler, Point, ShapedLine, StatefulInteractiveElement, StyleRefinement, ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels, PlatformInputHandler, Point,
Styled, TextRun, TextStyle, TextSystem, UnderlineStyle, WhiteSpace, WindowContext, ShapedLine, StatefulInteractiveElement, StyleRefinement, Styled, TextRun, TextStyle,
TextSystem, UnderlineStyle, WhiteSpace, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use language::CursorShape; use language::CursorShape;
@ -598,33 +599,48 @@ impl TerminalElement {
) { ) {
let focus = self.focus.clone(); let focus = self.focus.clone();
let terminal = self.terminal.clone(); let terminal = self.terminal.clone();
let interactive_bounds = InteractiveBounds {
bounds: bounds.intersect(&cx.content_mask().bounds),
stacking_order: cx.stacking_order().clone(),
};
self.interactivity.on_mouse_down(MouseButton::Left, { self.interactivity.on_mouse_down(MouseButton::Left, {
let terminal = terminal.clone(); let terminal = terminal.clone();
let focus = focus.clone(); let focus = focus.clone();
move |e, cx| { move |e, cx| {
cx.focus(&focus); cx.focus(&focus);
//todo!(context menu)
// v.context_menu.update(cx, |menu, _cx| menu.delay_cancel());
terminal.update(cx, |terminal, cx| { terminal.update(cx, |terminal, cx| {
terminal.mouse_down(&e, origin); terminal.mouse_down(&e, origin);
cx.notify(); cx.notify();
}) })
} }
}); });
self.interactivity.on_mouse_move({
let terminal = terminal.clone(); cx.on_mouse_event({
let focus = focus.clone(); let bounds = bounds.clone();
move |e, cx| { let focus = self.focus.clone();
if e.pressed_button.is_some() && focus.is_focused(cx) && !cx.has_active_drag() { let terminal = self.terminal.clone();
move |e: &MouseMoveEvent, phase, cx| {
if phase != DispatchPhase::Bubble || !focus.is_focused(cx) {
return;
}
if e.pressed_button.is_some() && !cx.has_active_drag() {
terminal.update(cx, |terminal, cx| { terminal.update(cx, |terminal, cx| {
terminal.mouse_drag(e, origin, bounds); terminal.mouse_drag(e, origin, bounds);
cx.notify(); cx.notify();
}) })
} }
if interactive_bounds.visibly_contains(&e.position, cx) {
terminal.update(cx, |terminal, cx| {
terminal.mouse_move(&e, origin);
cx.notify();
})
}
} }
}); });
self.interactivity.on_mouse_up( self.interactivity.on_mouse_up(
MouseButton::Left, MouseButton::Left,
TerminalElement::generic_button_handler( TerminalElement::generic_button_handler(
@ -651,19 +667,6 @@ impl TerminalElement {
} }
} }
}); });
self.interactivity.on_mouse_move({
let terminal = terminal.clone();
let focus = focus.clone();
move |e, cx| {
if focus.is_focused(cx) {
terminal.update(cx, |terminal, cx| {
terminal.mouse_move(&e, origin);
cx.notify();
})
}
}
});
self.interactivity.on_scroll_wheel({ self.interactivity.on_scroll_wheel({
let terminal = terminal.clone(); let terminal = terminal.clone();
move |e, cx| { move |e, cx| {