diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index b18cb4a7ae245f7906a7d1c50b097e90209a8911..ef6a655bdcead3cd64f29e9aa25b90d0d4e4d626 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -387,8 +387,7 @@ } }, { - // todo!() fix context - // "context": "Workspace", + "context": "Workspace", "bindings": { "cmd-1": ["workspace::ActivatePane", 0], "cmd-2": ["workspace::ActivatePane", 1], diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rs index dd0490082ea04d450b86d93893c1754c2cd0e72d..46b099ea3c2d5e10c2fd9e1250e6351842f9bddb 100644 --- a/crates/command_palette2/src/command_palette.rs +++ b/crates/command_palette2/src/command_palette.rs @@ -3,8 +3,8 @@ use collections::{CommandPaletteFilter, HashMap}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ actions, div, Action, AnyElement, AnyWindowHandle, AppContext, BorrowWindow, Div, Element, - EventEmitter, FocusHandle, Keystroke, ParentElement, Render, View, ViewContext, VisualContext, - WeakView, + EventEmitter, FocusHandle, Keystroke, ParentElement, Render, Styled, View, ViewContext, + VisualContext, WeakView, }; use picker::{Picker, PickerDelegate}; use std::cmp::{self, Reverse}; @@ -60,7 +60,6 @@ impl Render for CommandPalette { type Element = Div; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { - dbg!("Rendering"); modal(cx).w_96().child(self.picker.clone()) } } diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 3e77a66936443aa872fc6f196fb71257bfede82f..8dbe989b1f4d5e38842eb00b6bca71701845bc1e 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -4149,12 +4149,16 @@ fn build_key_listeners( build_key_listener( move |editor, key_down: &KeyDownEvent, dispatch_context, phase, cx| { if phase == DispatchPhase::Bubble { + dbg!(&dispatch_context); if let KeyMatch::Some(action) = cx.match_keystroke( &global_element_id, &key_down.keystroke, dispatch_context, ) { + dbg!("got action", &action); return Some(action); + } else { + dbg!("not action"); } } diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index a546c1b40b9cbb073f3539133c29b1714fffd951..51efde62c11e7b33bf5bb50f39114040108166d0 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -414,6 +414,7 @@ pub trait ElementInteractivity: 'static { Box::new(move |_, key_down, context, phase, cx| { if phase == DispatchPhase::Bubble { let key_down = key_down.downcast_ref::().unwrap(); + dbg!(&context); if let KeyMatch::Some(action) = cx.match_keystroke(&global_id, &key_down.keystroke, context) { diff --git a/crates/gpui2/src/keymap/binding.rs b/crates/gpui2/src/keymap/binding.rs index 829f7a3b2cfa7a816b76ebc7c1acd3229b57aa18..67041dc4885cbe1ec05bf8db16ec25880d11288b 100644 --- a/crates/gpui2/src/keymap/binding.rs +++ b/crates/gpui2/src/keymap/binding.rs @@ -44,6 +44,19 @@ impl KeyBinding { pending_keystrokes: &[Keystroke], contexts: &[&DispatchContext], ) -> KeyMatch { + let should_debug = self.keystrokes.len() == 1 + && self.keystrokes[0].key == "p" + && self.keystrokes[0].modifiers.command == true + && self.keystrokes[0].modifiers.shift == true; + + if false && should_debug { + dbg!( + &self.keystrokes, + &pending_keystrokes, + &contexts, + &self.matches_context(contexts) + ); + } if self.keystrokes.as_ref().starts_with(&pending_keystrokes) && self.matches_context(contexts) { diff --git a/crates/gpui2/src/keymap/matcher.rs b/crates/gpui2/src/keymap/matcher.rs index c2033a95953a46479c02bfef69f432f0c877b3ae..c86b65c47e55fff8b689f8fd477e3a2569513e5f 100644 --- a/crates/gpui2/src/keymap/matcher.rs +++ b/crates/gpui2/src/keymap/matcher.rs @@ -46,6 +46,7 @@ impl KeyMatcher { keystroke: &Keystroke, context_stack: &[&DispatchContext], ) -> KeyMatch { + dbg!(keystroke, &context_stack); let keymap = self.keymap.lock(); // Clear pending keystrokes if the keymap has changed since the last matched keystroke. if keymap.version() != self.keymap_version { diff --git a/crates/workspace2/src/modal_layer.rs b/crates/workspace2/src/modal_layer.rs index a5760380f5efa6f138f237a0eb3ae3a0e34216de..fc85ae835130964b4a0fd67ff74d579030a2e34d 100644 --- a/crates/workspace2/src/modal_layer.rs +++ b/crates/workspace2/src/modal_layer.rs @@ -1,7 +1,7 @@ use crate::Workspace; use gpui::{ - div, px, AnyView, Component, Div, EventEmitter, ParentElement, Render, StatelessInteractive, - Styled, Subscription, View, ViewContext, + div, px, AnyView, Component, Div, EventEmitter, ParentElement, Render, StatefulInteractivity, + StatelessInteractive, Styled, Subscription, View, ViewContext, }; use std::{any::TypeId, sync::Arc}; use ui::v_stack; @@ -9,7 +9,14 @@ use ui::v_stack; pub struct ModalLayer { open_modal: Option, subscription: Option, - registered_modals: Vec<(TypeId, Box) -> Div>)>, + registered_modals: Vec<( + TypeId, + Box< + dyn Fn( + Div>, + ) -> Div>, + >, + )>, } pub enum ModalEvent { @@ -64,8 +71,11 @@ impl ModalLayer { cx.notify(); } - pub fn wrapper_element(&self, cx: &ViewContext) -> Div { - let mut parent = div().relative().size_full(); + pub fn wrapper_element( + &self, + cx: &ViewContext, + ) -> Div> { + let mut parent = div().id("modal layer").relative().size_full(); for (_, action) in self.registered_modals.iter() { parent = (action)(parent); diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index c91c388f2afb1b43a6e9f9cc10214d6795a9c70e..54c8709d7ed817748637581a13b0c92211ce6065 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -39,8 +39,8 @@ use gpui::{ actions, div, point, rems, size, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, DispatchContext, Div, Entity, EntityId, EventEmitter, FocusHandle, GlobalPixels, Model, ModelContext, ParentElement, Point, Render, Size, - StatefulInteractive, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, - WindowBounds, WindowContext, WindowHandle, WindowOptions, + StatefulInteractive, StatefulInteractivity, Styled, Subscription, Task, View, ViewContext, + VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem}; use itertools::Itertools; @@ -3706,13 +3706,14 @@ fn notify_if_database_failed(workspace: WindowHandle, cx: &mut AsyncA impl EventEmitter for Workspace {} impl Render for Workspace { - type Element = Div; + type Element = Div>; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { let mut context = DispatchContext::default(); context.insert("Workspace"); cx.with_key_dispatch_context(context, |cx| { div() + .id("workspace") .relative() .size_full() .flex()