In the middle of stuff

This commit is contained in:
Conrad Irwin 2023-11-14 14:38:23 -07:00
parent 80b7f75d24
commit 3b01a032ba
5 changed files with 1278 additions and 1473 deletions

View File

@ -1448,6 +1448,7 @@ impl EditorElement {
let snapshot = editor.snapshot(cx);
let style = self.style.clone();
dbg!(&style.text.font());
let font_id = cx.text_system().font_id(&style.text.font()).unwrap();
let font_size = style.text.font_size.to_pixels(cx.rem_size());
let line_height = style.text.line_height_in_pixels(cx.rem_size());

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
use crate::{
div, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext, BackgroundExecutor,
Context, Div, EventEmitter, ForegroundExecutor, InputEvent, KeyDownEvent, Keystroke, Model,
ModelContext, Render, Result, Task, TestDispatcher, TestPlatform, View, ViewContext,
VisualContext, WindowContext, WindowHandle, WindowOptions,
div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
BackgroundExecutor, Context, Div, EventEmitter, ForegroundExecutor, InputEvent, KeyDownEvent,
Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher, TestPlatform, TextStyle,
View, ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
};
use anyhow::{anyhow, bail};
use futures::{Stream, StreamExt};
@ -83,8 +83,16 @@ impl TestAppContext {
));
let asset_source = Arc::new(());
let http_client = util::http::FakeHttpClient::with_404_response();
let cx = AppContext::new(platform, asset_source, http_client);
let lock = cx.borrow_mut();
lock.push_text_style(crate::TextStyleRefinement {
font_family: "Helvetica".into(),
..Default::default()
});
drop(lock);
Self {
app: AppContext::new(platform, asset_source, http_client),
app: cx,
background_executor,
foreground_executor,
dispatcher: dispatcher.clone(),
@ -199,6 +207,15 @@ impl TestAppContext {
}
}
pub fn dispatch_action<A>(&mut self, window: AnyWindowHandle, action: A)
where
A: Action,
{
window
.update(self, |_, cx| cx.dispatch_action(action.boxed_clone()))
.unwrap()
}
pub fn dispatch_keystroke(
&mut self,
window: AnyWindowHandle,
@ -376,6 +393,13 @@ impl<'a> VisualTestContext<'a> {
pub fn from_window(window: AnyWindowHandle, cx: &'a mut TestAppContext) -> Self {
Self { cx, window }
}
pub fn dispatch_action<A>(&mut self, action: A)
where
A: Action,
{
self.cx.dispatch_action(self.window, action)
}
}
impl<'a> Context for VisualTestContext<'a> {

View File

@ -422,8 +422,11 @@ impl<'a> WindowContext<'a> {
}
pub fn dispatch_action(&mut self, action: Box<dyn Action>) {
dbg!("BEFORE FOCUS");
if let Some(focus_handle) = self.focused() {
dbg!("BEFORE DEFER", focus_handle.id);
self.defer(move |cx| {
dbg!("AFTER DEFER");
if let Some(node_id) = cx
.window
.current_frame

View File

@ -38,10 +38,10 @@ use futures::{
use gpui::{
actions, div, point, rems, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter,
FocusHandle, GlobalPixels, KeyContext, Model, ModelContext, ParentElement, Point, Render, Size,
StatefulInteractive, StatelessInteractive, StatelessInteractivity, Styled, Subscription, Task,
View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle,
WindowOptions,
FocusHandle, FocusableKeyDispatch, GlobalPixels, KeyContext, Model, ModelContext,
ParentElement, Point, Render, Size, StatefulInteractive, StatefulInteractivity,
StatelessInteractive, StatelessInteractivity, Styled, Subscription, Task, View, ViewContext,
VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
use itertools::Itertools;
@ -3409,10 +3409,6 @@ impl Workspace {
// });
}
// todo!()
// #[cfg(any(test, feature = "test-support"))]
// pub fn test_new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
// use node_runtime::FakeNodeRuntime;
#[cfg(any(test, feature = "test-support"))]
pub fn test_new(project: Model<Project>, cx: &mut ViewContext<Self>) -> Self {
use gpui::Context;
@ -3432,7 +3428,10 @@ impl Workspace {
initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
node_runtime: FakeNodeRuntime::new(),
});
Self::new(0, project, app_state, cx)
let workspace = Self::new(0, project, app_state, cx);
dbg!(&workspace.focus_handle);
workspace.focus_handle.focus(cx);
workspace
}
// fn render_dock(&self, position: DockPosition, cx: &WindowContext) -> Option<AnyElement<Self>> {
@ -3710,13 +3709,14 @@ fn notify_if_database_failed(workspace: WindowHandle<Workspace>, cx: &mut AsyncA
impl EventEmitter<Event> for Workspace {}
impl Render for Workspace {
type Element = Div<Self>;
type Element = Div<Self, StatefulInteractivity<Self>, FocusableKeyDispatch<Self>>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let mut context = KeyContext::default();
context.add("Workspace");
self.add_workspace_actions_listeners(div())
.track_focus(&self.focus_handle)
.context(context)
.relative()
.size_full()