From f922ad9f7fe98aa54c530c3e5a9e61ac36cdcfcc Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 30 Nov 2023 14:24:00 -0500 Subject: [PATCH] Fix bug preventing spaces from being used in filename (zed2) Co-Authored-By: Mikayla Maki --- crates/project_panel2/src/project_panel.rs | 108 ++++++++++----------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index b9b50e0d7f..caca5402fa 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -10,9 +10,9 @@ use anyhow::{anyhow, Result}; use gpui::{ actions, div, overlay, px, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle, Focusable, FocusableView, - InteractiveElement, Model, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, - PromptLevel, Render, Stateful, Styled, Subscription, Task, UniformListScrollHandle, View, - ViewContext, VisualContext as _, WeakView, WindowContext, + InteractiveElement, KeyContext, Model, MouseButton, MouseDownEvent, ParentElement, Pixels, + Point, PromptLevel, Render, Stateful, Styled, Subscription, Task, UniformListScrollHandle, + View, ViewContext, VisualContext as _, WeakView, WindowContext, }; use menu::{Confirm, SelectNext, SelectPrev}; use project::{ @@ -1355,7 +1355,7 @@ impl ProjectPanel { details: EntryDetails, // dragged_entry_destination: &mut Option>, cx: &mut ViewContext, - ) -> ListItem { + ) -> Div { let kind = details.kind; let settings = ProjectPanelSettings::get_global(cx); let show_editor = details.is_editing && !details.is_processing; @@ -1374,44 +1374,46 @@ impl ProjectPanel { }) .unwrap_or(theme.status().info); - ListItem::new(entry_id.to_proto() as usize) - .indent_level(details.depth) - .indent_step_size(px(settings.indent_size)) - .selected(is_selected) - .child(if let Some(icon) = &details.icon { - div().child(IconElement::from_path(icon.to_string())) - } else { - div() - }) - .child( - if let (Some(editor), true) = (Some(&self.filename_editor), show_editor) { - div().h_full().w_full().child(editor.clone()) + div().key_context(self.dispatch_context(cx)).child( + ListItem::new(entry_id.to_proto() as usize) + .indent_level(details.depth) + .indent_step_size(px(settings.indent_size)) + .selected(is_selected) + .child(if let Some(icon) = &details.icon { + div().child(IconElement::from_path(icon.to_string())) } else { div() - .text_color(filename_text_color) - .child(Label::new(details.filename.clone())) - } - .ml_1(), - ) - .on_click(cx.listener(move |this, event: &gpui::ClickEvent, cx| { - if event.down.button == MouseButton::Right { - return; - } - if !show_editor { - if kind.is_dir() { - this.toggle_expanded(entry_id, cx); + }) + .child( + if let (Some(editor), true) = (Some(&self.filename_editor), show_editor) { + div().h_full().w_full().child(editor.clone()) } else { - if event.down.modifiers.command { - this.split_entry(entry_id, cx); + div() + .text_color(filename_text_color) + .child(Label::new(details.filename.clone())) + } + .ml_1(), + ) + .on_click(cx.listener(move |this, event: &gpui::ClickEvent, cx| { + if event.down.button == MouseButton::Right { + return; + } + if !show_editor { + if kind.is_dir() { + this.toggle_expanded(entry_id, cx); } else { - this.open_entry(entry_id, event.up.click_count > 1, cx); + if event.down.modifiers.command { + this.split_entry(entry_id, cx); + } else { + this.open_entry(entry_id, event.up.click_count > 1, cx); + } } } - } - })) - .on_secondary_mouse_down(cx.listener(move |this, event: &MouseDownEvent, cx| { - this.deploy_context_menu(event.position, entry_id, cx); - })) + })) + .on_secondary_mouse_down(cx.listener(move |this, event: &MouseDownEvent, cx| { + this.deploy_context_menu(event.position, entry_id, cx); + })), + ) // .on_drop::(|this, event, cx| { // this.move_entry( // *dragged_entry, @@ -1421,6 +1423,22 @@ impl ProjectPanel { // ); // }) } + + fn dispatch_context(&self, cx: &ViewContext) -> KeyContext { + let mut dispatch_context = KeyContext::default(); + dispatch_context.add("menu"); + dispatch_context.add("not_editing"); + + let identifier = if self.filename_editor.focus_handle(cx).is_focused(cx) { + "editing" + } else { + "not_editing" + }; + + dispatch_context.add(identifier); + + dispatch_context + } } impl Render for ProjectPanel { @@ -3011,21 +3029,3 @@ mod tests { .unwrap(); } } - -// TODO - implement this in the new keymap system -// fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &AppContext) { -// Self::reset_to_default_keymap_context(keymap); -// keymap.add_identifier("menu"); - -// if let Some(window) = cx.active_window() { -// window.read_with(cx, |cx| { -// let identifier = if self.filename_editor.is_focused(cx) { -// "editing" -// } else { -// "not_editing" -// }; - -// keymap.add_identifier(identifier); -// }); -// } -// }