Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix up keybindings propagation

Piotr Osiewicz194d61569166
diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json
index b18cb4a7ae2..ef6a655bdce 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 dd0490082ea..46b099ea3c2 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<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> 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 3e77a669364..8dbe989b1f4 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 a546c1b40b9..51efde62c11 100644
--- a/crates/gpui2/src/interactive.rs
+++ b/crates/gpui2/src/interactive.rs
@@ -414,6 +414,7 @@ pub trait ElementInteractivity<V: 'static>: 'static {
Box::new(move |_, key_down, context, phase, cx| {
if phase == DispatchPhase::Bubble {
let key_down = key_down.downcast_ref::<KeyDownEvent>().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 829f7a3b2cf..67041dc4885 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 c2033a95953..c86b65c47e5 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 a5760380f5e..fc85ae83513 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<AnyView>,
subscription: Option<Subscription>,
- registered_modals: Vec<(TypeId, Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>)>,
+ registered_modals: Vec<(
+ TypeId,
+ Box<
+ dyn Fn(
+ Div<Workspace, StatefulInteractivity<Workspace>>,
+ ) -> Div<Workspace, StatefulInteractivity<Workspace>>,
+ >,
+ )>,
}
pub enum ModalEvent {
@@ -64,8 +71,11 @@ impl ModalLayer {
cx.notify();
}
- pub fn wrapper_element(&self, cx: &ViewContext<Workspace>) -> Div<Workspace> {
- let mut parent = div().relative().size_full();
+ pub fn wrapper_element(
+ &self,
+ cx: &ViewContext<Workspace>,
+ ) -> Div<Workspace, StatefulInteractivity<Workspace>> {
+ 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 c91c388f2af..54c8709d7ed 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<Workspace>, cx: &mut AsyncA
impl EventEmitter<Event> for Workspace {}
impl Render for Workspace {
- type Element = Div<Self>;
+ type Element = Div<Self, StatefulInteractivity<Self>>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let mut context = DispatchContext::default();
context.insert("Workspace");
cx.with_key_dispatch_context(context, |cx| {
div()
+ .id("workspace")
.relative()
.size_full()
.flex()