Add more debugging

This commit is contained in:
Mikayla 2023-12-05 17:31:33 -08:00
parent 2ee0ecb677
commit 735f2029e9
No known key found for this signature in database
3 changed files with 87 additions and 63 deletions

View file

@ -1,10 +1,10 @@
use crate::{ use crate::{
green, point, px, red, Action, AnyDrag, AnyDragState, AnyElement, AnyTooltip, AnyView, point, px, Action, AnyDrag, AnyDragState, AnyElement, AnyTooltip, AnyView, AppContext,
AppContext, BorrowAppContext, BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, BorrowAppContext, BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, ElementId,
ElementId, FocusEvent, FocusHandle, IntoElement, KeyContext, KeyDownEvent, KeyUpEvent, FocusEvent, FocusHandle, IntoElement, KeyContext, KeyDownEvent, KeyUpEvent, LayoutId,
LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point,
Point, Render, ScrollWheelEvent, SharedString, Size, StackingOrder, Style, StyleRefinement, Render, ScrollWheelEvent, SharedString, Size, StackingOrder, Style, StyleRefinement, Styled,
Styled, Task, View, Visibility, WindowContext, Task, View, Visibility, WindowContext,
}; };
use collections::HashMap; use collections::HashMap;
use refineable::Refineable; use refineable::Refineable;
@ -95,6 +95,32 @@ pub trait InteractiveElement: Sized + Element {
self self
} }
fn on_mouse_down_weird(
mut self,
button: MouseButton,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
) -> Self {
self.interactivity().mouse_down_listeners.push(Box::new(
move |event, bounds, phase, cx| {
dbg!("HEREEEE");
let contains = dbg!(dbg!(&bounds.bounds).contains_point(dbg!(&event.position)))
&& dbg!(cx.was_top_layer(&event.position, &bounds.stacking_order));
dbg!(contains);
if phase == DispatchPhase::Bubble
&& event.button == button
&& bounds.visibly_contains(&event.position, cx)
{
dbg!("HEREEEE2");
(listener)(event, cx)
}
},
));
self
}
fn on_any_mouse_down( fn on_any_mouse_down(
mut self, mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@ -767,7 +793,7 @@ pub struct Interactivity {
pub tooltip_builder: Option<TooltipBuilder>, pub tooltip_builder: Option<TooltipBuilder>,
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct InteractiveBounds { pub struct InteractiveBounds {
pub bounds: Bounds<Pixels>, pub bounds: Bounds<Pixels>,
pub stacking_order: StackingOrder, pub stacking_order: StackingOrder,

View file

@ -638,7 +638,7 @@ impl TerminalElement {
let connection = self.terminal.clone(); let connection = self.terminal.clone();
let mut this = self let mut this = self
.on_mouse_down(MouseButton::Left, { .on_mouse_down_weird(MouseButton::Left, {
let connection = connection.clone(); let connection = connection.clone();
let focus = focus.clone(); let focus = focus.clone();
move |e, cx| { move |e, cx| {
@ -814,6 +814,7 @@ impl Element for TerminalElement {
state: &mut Self::State, state: &mut Self::State,
cx: &mut WindowContext<'_>, cx: &mut WindowContext<'_>,
) { ) {
dbg!(bounds);
let mut layout = self.compute_layout(bounds, cx); let mut layout = self.compute_layout(bounds, cx);
let theme = cx.theme(); let theme = cx.theme();
@ -832,7 +833,6 @@ impl Element for TerminalElement {
let mut this = self.register_mouse_listeners(origin, layout.mode, bounds, cx); let mut this = self.register_mouse_listeners(origin, layout.mode, bounds, cx);
let interactivity = mem::take(&mut this.interactivity); let interactivity = mem::take(&mut this.interactivity);
cx.with_z_index(0, |cx| {
interactivity.paint(bounds, bounds.size, state, cx, |_, _, cx| { interactivity.paint(bounds, bounds.size, state, cx, |_, _, cx| {
this.register_key_listeners(cx); this.register_key_listeners(cx);
@ -841,8 +841,7 @@ impl Element for TerminalElement {
} }
cx.with_z_index(1, |cx| { cx.with_z_index(1, |cx| {
for (relative_highlighted_range, color) in for (relative_highlighted_range, color) in layout.relative_highlighted_ranges.iter()
layout.relative_highlighted_ranges.iter()
{ {
if let Some((start_y, highlighted_range_lines)) = if let Some((start_y, highlighted_range_lines)) =
to_highlighted_range_lines(relative_highlighted_range, &layout, origin) to_highlighted_range_lines(relative_highlighted_range, &layout, origin)
@ -880,7 +879,6 @@ impl Element for TerminalElement {
element.draw(origin, Size { width, height }, cx) element.draw(origin, Size { width, height }, cx)
} }
}); });
});
} }
} }

View file

@ -266,18 +266,18 @@ impl TerminalView {
.detach(); .detach();
let focus = cx.focus_handle(); let focus = cx.focus_handle();
let focus_in = cx.on_focus_in(&focus, |this, cx| { // let focus_in = cx.on_focus_in(&focus, |this, cx| {
this.has_new_content = false; // this.has_new_content = false;
this.terminal.read(cx).focus_in(); // this.terminal.read(cx).focus_in();
this.blink_cursors(this.blink_epoch, cx); // this.blink_cursors(this.blink_epoch, cx);
cx.notify(); // cx.notify();
}); // });
let focus_out = cx.on_focus_out(&focus, |this, cx| { // let focus_out = cx.on_focus_out(&focus, |this, cx| {
this.terminal.update(cx, |terminal, _| { // this.terminal.update(cx, |terminal, _| {
terminal.focus_out(); // terminal.focus_out();
}); // });
cx.notify(); // cx.notify();
}); // });
Self { Self {
terminal, terminal,
@ -291,7 +291,7 @@ impl TerminalView {
blink_epoch: 0, blink_epoch: 0,
can_navigate_to_selected_word: false, can_navigate_to_selected_word: false,
workspace_id, workspace_id,
_subscriptions: vec![focus_in, focus_out], _subscriptions: vec![/*focus_in, focus_out*/],
} }
} }