Fix right click handler for tabs (#4130)
Also, some fun test helpers Co-Authored-By: Mikayla <mikayla@zed.dev> You can now use .debug_selector() to make it possible for tests to find a given element, and .debug_bounds() to find the coordinates of where it was painted. Release Notes: - (Added|Fixed|Improved) ... ([#<public_issue_number_if_exists>](https://github.com/zed-industries/community/issues/<public_issue_number_if_exists>)).
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::{
|
||||
Action, AnyElement, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
|
||||
AvailableSpace, BackgroundExecutor, ClipboardItem, Context, Entity, EventEmitter,
|
||||
AvailableSpace, BackgroundExecutor, Bounds, ClipboardItem, Context, Entity, EventEmitter,
|
||||
ForegroundExecutor, InputEvent, Keystroke, Model, ModelContext, Pixels, Platform, Point,
|
||||
Render, Result, Size, Task, TestDispatcher, TestPlatform, TestWindow, TextSystem, View,
|
||||
ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
|
||||
@@ -618,6 +618,16 @@ impl<'a> VisualTestContext {
|
||||
self.cx.simulate_input(self.window, input)
|
||||
}
|
||||
|
||||
/// Simulates the user resizing the window to the new size.
|
||||
pub fn simulate_resize(&self, size: Size<Pixels>) {
|
||||
self.simulate_window_resize(self.window, size)
|
||||
}
|
||||
|
||||
/// debug_bounds returns the bounds of the element with the given selector.
|
||||
pub fn debug_bounds(&mut self, selector: &'static str) -> Option<Bounds<Pixels>> {
|
||||
self.update(|cx| cx.window.rendered_frame.debug_bounds.get(selector).copied())
|
||||
}
|
||||
|
||||
/// Draw an element to the window. Useful for simulating events or actions
|
||||
pub fn draw(
|
||||
&mut self,
|
||||
|
||||
@@ -416,6 +416,18 @@ pub trait InteractiveElement: Sized {
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fn debug_selector(mut self, f: impl FnOnce() -> String) -> Self {
|
||||
self.interactivity().debug_selector = Some(f());
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(not(any(test, feature = "test-support")))]
|
||||
#[inline]
|
||||
fn debug_selector(self, _: impl FnOnce() -> String) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn capture_any_mouse_down(
|
||||
mut self,
|
||||
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
|
||||
@@ -911,6 +923,9 @@ pub struct Interactivity {
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub location: Option<core::panic::Location<'static>>,
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub debug_selector: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -980,6 +995,14 @@ impl Interactivity {
|
||||
let style = self.compute_style(Some(bounds), element_state, cx);
|
||||
let z_index = style.z_index.unwrap_or(0);
|
||||
|
||||
#[cfg(any(feature = "test-support", test))]
|
||||
if let Some(debug_selector) = &self.debug_selector {
|
||||
cx.window
|
||||
.next_frame
|
||||
.debug_bounds
|
||||
.insert(debug_selector.clone(), bounds);
|
||||
}
|
||||
|
||||
let paint_hover_group_handler = |cx: &mut WindowContext| {
|
||||
let hover_group_bounds = self
|
||||
.group_hover_style
|
||||
|
||||
@@ -30,7 +30,7 @@ use std::{
|
||||
borrow::{Borrow, BorrowMut, Cow},
|
||||
cell::RefCell,
|
||||
collections::hash_map::Entry,
|
||||
fmt::Debug,
|
||||
fmt::{Debug, Display},
|
||||
future::Future,
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
@@ -318,6 +318,9 @@ pub(crate) struct Frame {
|
||||
requested_cursor_style: Option<CursorStyle>,
|
||||
pub(crate) view_stack: Vec<EntityId>,
|
||||
pub(crate) reused_views: FxHashSet<EntityId>,
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub(crate) debug_bounds: collections::FxHashMap<String, Bounds<Pixels>>,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
@@ -341,6 +344,9 @@ impl Frame {
|
||||
requested_cursor_style: None,
|
||||
view_stack: Vec::new(),
|
||||
reused_views: FxHashSet::default(),
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
debug_bounds: FxHashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3380,6 +3386,20 @@ pub enum ElementId {
|
||||
NamedInteger(SharedString, usize),
|
||||
}
|
||||
|
||||
impl Display for ElementId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ElementId::View(entity_id) => write!(f, "view-{}", entity_id)?,
|
||||
ElementId::Integer(ix) => write!(f, "{}", ix)?,
|
||||
ElementId::Name(name) => write!(f, "{}", name)?,
|
||||
ElementId::FocusHandle(__) => write!(f, "FocusHandle")?,
|
||||
ElementId::NamedInteger(s, i) => write!(f, "{}-{}", s, i)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ElementId {
|
||||
pub(crate) fn from_entity_id(entity_id: EntityId) -> Self {
|
||||
ElementId::View(entity_id)
|
||||
|
||||
Reference in New Issue
Block a user