Compare commits

...
Sign in to create a new pull request.

17 commits

Author SHA1 Message Date
Mikayla Maki
ce18bed403
zed 0.84.5 2023-05-08 11:44:55 -07:00
Mikayla Maki
5fcb296434
Merge pull request #2453 from zed-industries/fix-click-fallthrough
Fixed clicks falling through the modal terminal
2023-05-08 11:43:27 -07:00
Antonio Scandurra
83ef9ebce8 Merge pull request #2443 from zed-industries/fix-vim-mode-rename
Avoid calling `update_window` twice in `blurred` event handler
2023-05-04 16:29:45 +02:00
Antonio Scandurra
53c78ed80c Merge pull request #2442 from zed-industries/filter-vim-commands
Filter out vim commands when vim mode is disabled
2023-05-04 15:00:46 +02:00
Antonio Scandurra
5273cce0bd zed 0.84.4 2023-05-04 14:24:15 +02:00
Antonio Scandurra
9e50435e7c Merge pull request #2439 from zed-industries/fix-keystrokes-for-action
Cache view's type id and keymap context into a separate map
2023-05-04 14:23:45 +02:00
Joseph Lyons
e724d7fae9 v0.84.x stable 2023-05-03 14:38:06 -04:00
Antonio Scandurra
7ad90fd0a7 Merge pull request #2436 from zed-industries/close-window-end-call
Move methods querying window state into `AsyncAppContext`
2023-05-03 10:33:09 +02:00
Antonio Scandurra
4df6b75ba3 Merge pull request #2431 from zed-industries/fix-broken-contact-finder
Fix broken styling in contact finder
2023-05-02 13:55:39 +02:00
Antonio Scandurra
1908d3cf43 zed 0.84.3 2023-05-02 12:02:09 +02:00
Antonio Scandurra
b4531235ef Merge pull request #2430 from zed-industries/fix-toggle-contacts-panic
Fix panic when showing contacts popover via keybinding
2023-05-02 12:02:01 +02:00
Antonio Scandurra
c3212e559f Merge pull request #2429 from zed-industries/fix-debug-elements-panic
Move `debug_elements` to `AsyncAppContext`
2023-05-02 11:19:11 +02:00
Max Brunsfeld
1c7fb0f0cb zed 0.84.2 2023-04-27 10:50:15 -07:00
Max Brunsfeld
df26ef9770 Merge pull request #2418 from zed-industries/vim-inactive-window-crash
Fix vim mode crash when active editor changes in inactive window
2023-04-27 10:49:21 -07:00
Max Brunsfeld
74d5e22cec zed 0.84.1 2023-04-26 16:13:30 -07:00
Max Brunsfeld
80efdb13be Merge pull request #2416 from zed-industries/outline-view-leaving-lines-highlighted
Remove highlighted rows when confirming outline view
2023-04-26 16:13:03 -07:00
Joseph Lyons
3f8415b62e v0.84.x preview 2023-04-26 14:19:40 -04:00
29 changed files with 391 additions and 405 deletions

2
Cargo.lock generated
View file

@ -8539,7 +8539,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]] [[package]]
name = "zed" name = "zed"
version = "0.84.0" version = "0.84.5"
dependencies = [ dependencies = [
"activity_indicator", "activity_indicator",
"anyhow", "anyhow",

View file

@ -4,7 +4,7 @@ use crate::{
ToggleScreenSharing, ToggleScreenSharing,
}; };
use call::{ActiveCall, ParticipantLocation, Room}; use call::{ActiveCall, ParticipantLocation, Room};
use client::{proto::PeerId, ContactEventKind, SignIn, SignOut, User, UserStore}; use client::{proto::PeerId, Client, ContactEventKind, SignIn, SignOut, User, UserStore};
use clock::ReplicaId; use clock::ReplicaId;
use contacts_popover::ContactsPopover; use contacts_popover::ContactsPopover;
use context_menu::{ContextMenu, ContextMenuItem}; use context_menu::{ContextMenu, ContextMenuItem};
@ -19,6 +19,7 @@ use gpui::{
AppContext, Entity, ImageData, ModelHandle, SceneBuilder, Subscription, View, ViewContext, AppContext, Entity, ImageData, ModelHandle, SceneBuilder, Subscription, View, ViewContext,
ViewHandle, WeakViewHandle, ViewHandle, WeakViewHandle,
}; };
use project::Project;
use settings::Settings; use settings::Settings;
use std::{ops::Range, sync::Arc}; use std::{ops::Range, sync::Arc};
use theme::{AvatarStyle, Theme}; use theme::{AvatarStyle, Theme};
@ -51,8 +52,10 @@ pub fn init(cx: &mut AppContext) {
} }
pub struct CollabTitlebarItem { pub struct CollabTitlebarItem {
workspace: WeakViewHandle<Workspace>, project: ModelHandle<Project>,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
client: Arc<Client>,
workspace: WeakViewHandle<Workspace>,
contacts_popover: Option<ViewHandle<ContactsPopover>>, contacts_popover: Option<ViewHandle<ContactsPopover>>,
user_menu: ViewHandle<ContextMenu>, user_menu: ViewHandle<ContextMenu>,
collaborator_list_popover: Option<ViewHandle<CollaboratorListPopover>>, collaborator_list_popover: Option<ViewHandle<CollaboratorListPopover>>,
@ -75,7 +78,7 @@ impl View for CollabTitlebarItem {
return Empty::new().into_any(); return Empty::new().into_any();
}; };
let project = workspace.read(cx).project().read(cx); let project = self.project.read(cx);
let mut project_title = String::new(); let mut project_title = String::new();
for (i, name) in project.worktree_root_names(cx).enumerate() { for (i, name) in project.worktree_root_names(cx).enumerate() {
if i > 0 { if i > 0 {
@ -100,8 +103,8 @@ impl View for CollabTitlebarItem {
.left(), .left(),
); );
let user = workspace.read(cx).user_store().read(cx).current_user(); let user = self.user_store.read(cx).current_user();
let peer_id = workspace.read(cx).client().peer_id(); let peer_id = self.client.peer_id();
if let Some(((user, peer_id), room)) = user if let Some(((user, peer_id), room)) = user
.zip(peer_id) .zip(peer_id)
.zip(ActiveCall::global(cx).read(cx).room().cloned()) .zip(ActiveCall::global(cx).read(cx).room().cloned())
@ -135,20 +138,23 @@ impl View for CollabTitlebarItem {
impl CollabTitlebarItem { impl CollabTitlebarItem {
pub fn new( pub fn new(
workspace: &ViewHandle<Workspace>, workspace: &Workspace,
user_store: &ModelHandle<UserStore>, workspace_handle: &ViewHandle<Workspace>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
let project = workspace.project().clone();
let user_store = workspace.user_store().clone();
let client = workspace.client().clone();
let active_call = ActiveCall::global(cx); let active_call = ActiveCall::global(cx);
let mut subscriptions = Vec::new(); let mut subscriptions = Vec::new();
subscriptions.push(cx.observe(workspace, |_, _, cx| cx.notify())); subscriptions.push(cx.observe(workspace_handle, |_, _, cx| cx.notify()));
subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx))); subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
subscriptions.push(cx.observe_window_activation(|this, active, cx| { subscriptions.push(cx.observe_window_activation(|this, active, cx| {
this.window_activation_changed(active, cx) this.window_activation_changed(active, cx)
})); }));
subscriptions.push(cx.observe(user_store, |_, _, cx| cx.notify())); subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
subscriptions.push( subscriptions.push(
cx.subscribe(user_store, move |this, user_store, event, cx| { cx.subscribe(&user_store, move |this, user_store, event, cx| {
if let Some(workspace) = this.workspace.upgrade(cx) { if let Some(workspace) = this.workspace.upgrade(cx) {
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
if let client::Event::Contact { user, kind } = event { if let client::Event::Contact { user, kind } = event {
@ -171,8 +177,10 @@ impl CollabTitlebarItem {
); );
Self { Self {
workspace: workspace.downgrade(), workspace: workspace.weak_handle(),
user_store: user_store.clone(), project,
user_store,
client,
contacts_popover: None, contacts_popover: None,
user_menu: cx.add_view(|cx| { user_menu: cx.add_view(|cx| {
let mut menu = ContextMenu::new(cx); let mut menu = ContextMenu::new(cx);
@ -185,16 +193,14 @@ impl CollabTitlebarItem {
} }
fn window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) { fn window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade(cx) { let project = if active {
let project = if active { Some(self.project.clone())
Some(workspace.read(cx).project().clone()) } else {
} else { None
None };
}; ActiveCall::global(cx)
ActiveCall::global(cx) .update(cx, |call, cx| call.set_location(project.as_ref(), cx))
.update(cx, |call, cx| call.set_location(project.as_ref(), cx)) .detach_and_log_err(cx);
.detach_and_log_err(cx);
}
} }
fn active_call_changed(&mut self, cx: &mut ViewContext<Self>) { fn active_call_changed(&mut self, cx: &mut ViewContext<Self>) {
@ -205,23 +211,19 @@ impl CollabTitlebarItem {
} }
fn share_project(&mut self, _: &ShareProject, cx: &mut ViewContext<Self>) { fn share_project(&mut self, _: &ShareProject, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade(cx) { let active_call = ActiveCall::global(cx);
let active_call = ActiveCall::global(cx); let project = self.project.clone();
let project = workspace.read(cx).project().clone(); active_call
active_call .update(cx, |call, cx| call.share_project(project, cx))
.update(cx, |call, cx| call.share_project(project, cx)) .detach_and_log_err(cx);
.detach_and_log_err(cx);
}
} }
fn unshare_project(&mut self, _: &UnshareProject, cx: &mut ViewContext<Self>) { fn unshare_project(&mut self, _: &UnshareProject, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade(cx) { let active_call = ActiveCall::global(cx);
let active_call = ActiveCall::global(cx); let project = self.project.clone();
let project = workspace.read(cx).project().clone(); active_call
active_call .update(cx, |call, cx| call.unshare_project(project, cx))
.update(cx, |call, cx| call.unshare_project(project, cx)) .log_err();
.log_err();
}
} }
pub fn toggle_collaborator_list_popover( pub fn toggle_collaborator_list_popover(
@ -256,22 +258,20 @@ impl CollabTitlebarItem {
pub fn toggle_contacts_popover(&mut self, _: &ToggleContactsMenu, cx: &mut ViewContext<Self>) { pub fn toggle_contacts_popover(&mut self, _: &ToggleContactsMenu, cx: &mut ViewContext<Self>) {
if self.contacts_popover.take().is_none() { if self.contacts_popover.take().is_none() {
if let Some(workspace) = self.workspace.upgrade(cx) { let view = cx.add_view(|cx| {
let project = workspace.read(cx).project().clone(); ContactsPopover::new(self.project.clone(), self.user_store.clone(), cx)
let user_store = workspace.read(cx).user_store().clone(); });
let view = cx.add_view(|cx| ContactsPopover::new(project, user_store, cx)); cx.subscribe(&view, |this, _, event, cx| {
cx.subscribe(&view, |this, _, event, cx| { match event {
match event { contacts_popover::Event::Dismissed => {
contacts_popover::Event::Dismissed => { this.contacts_popover = None;
this.contacts_popover = None;
}
} }
}
cx.notify(); cx.notify();
}) })
.detach(); .detach();
self.contacts_popover = Some(view); self.contacts_popover = Some(view);
}
} }
cx.notify(); cx.notify();

View file

@ -52,13 +52,16 @@ fn join_project(action: &JoinProject, app_state: Arc<AppState>, cx: &mut AppCont
let project_id = action.project_id; let project_id = action.project_id;
let follow_user_id = action.follow_user_id; let follow_user_id = action.follow_user_id;
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let existing_workspace = cx.update(|cx| { let existing_workspace = cx
cx.window_ids() .window_ids()
.filter_map(|window_id| cx.root_view(window_id)?.clone().downcast::<Workspace>()) .into_iter()
.find(|workspace| { .filter_map(|window_id| cx.root_view(window_id)?.clone().downcast::<Workspace>())
.find(|workspace| {
cx.read_window(workspace.window_id(), |cx| {
workspace.read(cx).project().read(cx).remote_id() == Some(project_id) workspace.read(cx).project().read(cx).remote_id() == Some(project_id)
}) })
}); .unwrap_or(false)
});
let workspace = if let Some(existing_workspace) = existing_workspace { let workspace = if let Some(existing_workspace) = existing_workspace {
existing_workspace.downgrade() existing_workspace.downgrade()

View file

@ -23,6 +23,7 @@ pub fn build_contact_finder(
}, },
cx, cx,
) )
.with_theme(|theme| theme.contact_finder.picker.clone())
} }
pub struct ContactFinderDelegate { pub struct ContactFinderDelegate {

View file

@ -1289,10 +1289,9 @@ impl View for ContactList {
"ContactList" "ContactList"
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
let mut cx = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
cx.add_identifier("menu"); keymap.add_identifier("menu");
cx
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {

View file

@ -62,14 +62,14 @@ pub fn init(cx: &mut AppContext) {
room::Event::RemoteProjectUnshared { project_id } => { room::Event::RemoteProjectUnshared { project_id } => {
if let Some(window_ids) = notification_windows.remove(&project_id) { if let Some(window_ids) = notification_windows.remove(&project_id) {
for window_id in window_ids { for window_id in window_ids {
cx.remove_window(window_id); cx.update_window(window_id, |cx| cx.remove_window());
} }
} }
} }
room::Event::Left => { room::Event::Left => {
for (_, window_ids) in notification_windows.drain() { for (_, window_ids) in notification_windows.drain() {
for window_id in window_ids { for window_id in window_ids {
cx.remove_window(window_id); cx.update_window(window_id, |cx| cx.remove_window());
} }
} }
} }

View file

@ -20,10 +20,10 @@ pub fn init(cx: &mut AppContext) {
status_indicator = Some(cx.add_status_bar_item(|_| SharingStatusIndicator)); status_indicator = Some(cx.add_status_bar_item(|_| SharingStatusIndicator));
} }
} else if let Some((window_id, _)) = status_indicator.take() { } else if let Some((window_id, _)) = status_indicator.take() {
cx.remove_status_bar_item(window_id); cx.update_window(window_id, |cx| cx.remove_window());
} }
} else if let Some((window_id, _)) = status_indicator.take() { } else if let Some((window_id, _)) = status_indicator.take() {
cx.remove_status_bar_item(window_id); cx.update_window(window_id, |cx| cx.remove_window());
} }
}) })
.detach(); .detach();

View file

@ -137,10 +137,9 @@ impl View for ContextMenu {
"ContextMenu" "ContextMenu"
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
let mut cx = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
cx.add_identifier("menu"); keymap.add_identifier("menu");
cx
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {

View file

@ -33,14 +33,13 @@ pub fn init(cx: &mut AppContext) {
crate::Status::SigningIn { prompt } => { crate::Status::SigningIn { prompt } => {
if let Some(code_verification_handle) = code_verification.as_mut() { if let Some(code_verification_handle) = code_verification.as_mut() {
let window_id = code_verification_handle.window_id(); let window_id = code_verification_handle.window_id();
if cx.has_window(window_id) { let updated = cx.update_window(window_id, |cx| {
cx.update_window(window_id, |cx| { code_verification_handle.update(cx, |code_verification, cx| {
code_verification_handle.update(cx, |code_verification, cx| { code_verification.set_status(status.clone(), cx)
code_verification.set_status(status, cx)
});
cx.activate_window();
}); });
} else { cx.activate_window();
});
if updated.is_none() {
code_verification = Some(create_copilot_auth_window(cx, &status)); code_verification = Some(create_copilot_auth_window(cx, &status));
} }
} else if let Some(_prompt) = prompt { } else if let Some(_prompt) = prompt {
@ -62,7 +61,7 @@ pub fn init(cx: &mut AppContext) {
} }
_ => { _ => {
if let Some(code_verification) = code_verification.take() { if let Some(code_verification) = code_verification.take() {
cx.remove_window(code_verification.window_id()); cx.update_window(code_verification.window_id(), |cx| cx.remove_window());
} }
} }
} }

View file

@ -1414,13 +1414,19 @@ impl Editor {
} }
} }
pub fn set_keymap_context_layer<Tag: 'static>(&mut self, context: KeymapContext) { pub fn set_keymap_context_layer<Tag: 'static>(
&mut self,
context: KeymapContext,
cx: &mut ViewContext<Self>,
) {
self.keymap_context_layers self.keymap_context_layers
.insert(TypeId::of::<Tag>(), context); .insert(TypeId::of::<Tag>(), context);
cx.notify();
} }
pub fn remove_keymap_context_layer<Tag: 'static>(&mut self) { pub fn remove_keymap_context_layer<Tag: 'static>(&mut self, cx: &mut ViewContext<Self>) {
self.keymap_context_layers.remove(&TypeId::of::<Tag>()); self.keymap_context_layers.remove(&TypeId::of::<Tag>());
cx.notify();
} }
pub fn set_input_enabled(&mut self, input_enabled: bool) { pub fn set_input_enabled(&mut self, input_enabled: bool) {
@ -7116,28 +7122,26 @@ impl View for Editor {
false false
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
let mut context = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
let mode = match self.mode { let mode = match self.mode {
EditorMode::SingleLine => "single_line", EditorMode::SingleLine => "single_line",
EditorMode::AutoHeight { .. } => "auto_height", EditorMode::AutoHeight { .. } => "auto_height",
EditorMode::Full => "full", EditorMode::Full => "full",
}; };
context.add_key("mode", mode); keymap.add_key("mode", mode);
if self.pending_rename.is_some() { if self.pending_rename.is_some() {
context.add_identifier("renaming"); keymap.add_identifier("renaming");
} }
match self.context_menu.as_ref() { match self.context_menu.as_ref() {
Some(ContextMenu::Completions(_)) => context.add_identifier("showing_completions"), Some(ContextMenu::Completions(_)) => keymap.add_identifier("showing_completions"),
Some(ContextMenu::CodeActions(_)) => context.add_identifier("showing_code_actions"), Some(ContextMenu::CodeActions(_)) => keymap.add_identifier("showing_code_actions"),
None => {} None => {}
} }
for layer in self.keymap_context_layers.values() { for layer in self.keymap_context_layers.values() {
context.extend(layer); keymap.extend(layer);
} }
context
} }
fn text_for_range(&self, range_utf16: Range<usize>, cx: &AppContext) -> Option<String> { fn text_for_range(&self, range_utf16: Range<usize>, cx: &AppContext) -> Option<String> {

View file

@ -43,6 +43,7 @@ use window_input_handler::WindowInputHandler;
use crate::{ use crate::{
elements::{AnyElement, AnyRootElement, RootElement}, elements::{AnyElement, AnyRootElement, RootElement},
executor::{self, Task}, executor::{self, Task},
json,
keymap_matcher::{self, Binding, KeymapContext, KeymapMatcher, Keystroke, MatchResult}, keymap_matcher::{self, Binding, KeymapContext, KeymapMatcher, Keystroke, MatchResult},
platform::{ platform::{
self, FontSystem, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, MouseButton, self, FontSystem, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, MouseButton,
@ -82,14 +83,15 @@ pub trait View: Entity + Sized {
false false
} }
fn keymap_context(&self, _: &AppContext) -> keymap_matcher::KeymapContext { fn update_keymap_context(&self, keymap: &mut keymap_matcher::KeymapContext, _: &AppContext) {
Self::default_keymap_context() Self::reset_to_default_keymap_context(keymap);
} }
fn default_keymap_context() -> keymap_matcher::KeymapContext {
let mut cx = keymap_matcher::KeymapContext::default(); fn reset_to_default_keymap_context(keymap: &mut keymap_matcher::KeymapContext) {
cx.add_identifier(Self::ui_name()); keymap.clear();
cx keymap.add_identifier(Self::ui_name());
} }
fn debug_json(&self, _: &AppContext) -> serde_json::Value { fn debug_json(&self, _: &AppContext) -> serde_json::Value {
serde_json::Value::Null serde_json::Value::Null
} }
@ -301,6 +303,14 @@ impl AsyncAppContext {
self.0.borrow_mut().update(callback) self.0.borrow_mut().update(callback)
} }
pub fn read_window<T, F: FnOnce(&WindowContext) -> T>(
&self,
window_id: usize,
callback: F,
) -> Option<T> {
self.0.borrow_mut().read_window(window_id, callback)
}
pub fn update_window<T, F: FnOnce(&mut WindowContext) -> T>( pub fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
&mut self, &mut self,
window_id: usize, window_id: usize,
@ -309,6 +319,30 @@ impl AsyncAppContext {
self.0.borrow_mut().update_window(window_id, callback) self.0.borrow_mut().update_window(window_id, callback)
} }
pub fn debug_elements(&self, window_id: usize) -> Option<json::Value> {
self.0.borrow().read_window(window_id, |cx| {
let root_view = cx.window.root_view();
let root_element = cx.window.rendered_views.get(&root_view.id())?;
root_element.debug(cx).log_err()
})?
}
pub fn has_window(&self, window_id: usize) -> bool {
self.read(|cx| cx.windows.contains_key(&window_id))
}
pub fn window_is_active(&self, window_id: usize) -> bool {
self.read(|cx| cx.windows.get(&window_id).map_or(false, |w| w.is_active))
}
pub fn root_view(&self, window_id: usize) -> Option<AnyViewHandle> {
self.read(|cx| cx.windows.get(&window_id).map(|w| w.root_view().clone()))
}
pub fn window_ids(&self) -> Vec<usize> {
self.read(|cx| cx.windows.keys().copied().collect())
}
pub fn add_model<T, F>(&mut self, build_model: F) -> ModelHandle<T> pub fn add_model<T, F>(&mut self, build_model: F) -> ModelHandle<T>
where where
T: Entity, T: Entity,
@ -330,7 +364,7 @@ impl AsyncAppContext {
} }
pub fn remove_window(&mut self, window_id: usize) { pub fn remove_window(&mut self, window_id: usize) {
self.update(|cx| cx.remove_window(window_id)) self.update_window(window_id, |cx| cx.remove_window());
} }
pub fn activate_window(&mut self, window_id: usize) { pub fn activate_window(&mut self, window_id: usize) {
@ -393,6 +427,7 @@ type WindowShouldCloseSubscriptionCallback = Box<dyn FnMut(&mut AppContext) -> b
pub struct AppContext { pub struct AppContext {
models: HashMap<usize, Box<dyn AnyModel>>, models: HashMap<usize, Box<dyn AnyModel>>,
views: HashMap<(usize, usize), Box<dyn AnyView>>, views: HashMap<(usize, usize), Box<dyn AnyView>>,
views_metadata: HashMap<(usize, usize), ViewMetadata>,
pub(crate) parents: HashMap<(usize, usize), ParentId>, pub(crate) parents: HashMap<(usize, usize), ParentId>,
windows: HashMap<usize, Window>, windows: HashMap<usize, Window>,
globals: HashMap<TypeId, Box<dyn Any>>, globals: HashMap<TypeId, Box<dyn Any>>,
@ -455,6 +490,7 @@ impl AppContext {
Self { Self {
models: Default::default(), models: Default::default(),
views: Default::default(), views: Default::default(),
views_metadata: Default::default(),
parents: Default::default(), parents: Default::default(),
windows: Default::default(), windows: Default::default(),
globals: Default::default(), globals: Default::default(),
@ -529,7 +565,7 @@ impl AppContext {
App(self.weak_self.as_ref().unwrap().upgrade().unwrap()) App(self.weak_self.as_ref().unwrap().upgrade().unwrap())
} }
pub fn quit(&mut self) { fn quit(&mut self) {
let mut futures = Vec::new(); let mut futures = Vec::new();
self.update(|cx| { self.update(|cx| {
@ -546,7 +582,8 @@ impl AppContext {
} }
}); });
self.remove_all_windows(); self.windows.clear();
self.flush_effects();
let futures = futures::future::join_all(futures); let futures = futures::future::join_all(futures);
if self if self
@ -558,11 +595,6 @@ impl AppContext {
} }
} }
pub fn remove_all_windows(&mut self) {
self.windows.clear();
self.flush_effects();
}
pub fn foreground(&self) -> &Rc<executor::Foreground> { pub fn foreground(&self) -> &Rc<executor::Foreground> {
&self.foreground &self.foreground
} }
@ -679,32 +711,14 @@ impl AppContext {
} }
} }
pub fn has_window(&self, window_id: usize) -> bool {
self.window_ids()
.find(|window| window == &window_id)
.is_some()
}
pub fn window_is_active(&self, window_id: usize) -> bool {
self.windows.get(&window_id).map_or(false, |w| w.is_active)
}
pub fn root_view(&self, window_id: usize) -> Option<&AnyViewHandle> {
self.windows.get(&window_id).map(|w| w.root_view())
}
pub fn window_ids(&self) -> impl Iterator<Item = usize> + '_ {
self.windows.keys().copied()
}
pub fn view_ui_name(&self, window_id: usize, view_id: usize) -> Option<&'static str> { pub fn view_ui_name(&self, window_id: usize, view_id: usize) -> Option<&'static str> {
Some(self.views.get(&(window_id, view_id))?.ui_name()) Some(self.views.get(&(window_id, view_id))?.ui_name())
} }
pub fn view_type_id(&self, window_id: usize, view_id: usize) -> Option<TypeId> { pub fn view_type_id(&self, window_id: usize, view_id: usize) -> Option<TypeId> {
self.views self.views_metadata
.get(&(window_id, view_id)) .get(&(window_id, view_id))
.map(|view| view.as_any().type_id()) .map(|metadata| metadata.type_id)
} }
pub fn active_labeled_tasks<'a>( pub fn active_labeled_tasks<'a>(
@ -1020,9 +1034,10 @@ impl AppContext {
.read_window(window_id, |cx| { .read_window(window_id, |cx| {
if let Some(focused_view_id) = cx.focused_view_id() { if let Some(focused_view_id) = cx.focused_view_id() {
for view_id in cx.ancestors(focused_view_id) { for view_id in cx.ancestors(focused_view_id) {
if let Some(view) = cx.views.get(&(window_id, view_id)) { if let Some(view_metadata) =
let view_type = view.as_any().type_id(); cx.views_metadata.get(&(window_id, view_id))
if let Some(actions) = cx.actions.get(&view_type) { {
if let Some(actions) = cx.actions.get(&view_metadata.type_id) {
if actions.contains_key(&action_type) { if actions.contains_key(&action_type) {
return true; return true;
} }
@ -1266,15 +1281,6 @@ impl AppContext {
}) })
} }
pub fn remove_status_bar_item(&mut self, id: usize) {
self.remove_window(id);
}
pub fn remove_window(&mut self, window_id: usize) {
self.windows.remove(&window_id);
self.flush_effects();
}
pub fn build_window<V, F>( pub fn build_window<V, F>(
&mut self, &mut self,
window_id: usize, window_id: usize,
@ -1333,7 +1339,7 @@ impl AppContext {
{ {
let mut app = self.upgrade(); let mut app = self.upgrade();
platform_window.on_close(Box::new(move || { platform_window.on_close(Box::new(move || {
app.update(|cx| cx.remove_window(window_id)); app.update(|cx| cx.update_window(window_id, |cx| cx.remove_window()));
})); }));
} }
@ -1436,6 +1442,7 @@ impl AppContext {
for (window_id, view_id) in dropped_views { for (window_id, view_id) in dropped_views {
self.subscriptions.remove(view_id); self.subscriptions.remove(view_id);
self.observations.remove(view_id); self.observations.remove(view_id);
self.views_metadata.remove(&(window_id, view_id));
let mut view = self.views.remove(&(window_id, view_id)).unwrap(); let mut view = self.views.remove(&(window_id, view_id)).unwrap();
view.release(self); view.release(self);
let change_focus_to = self.windows.get_mut(&window_id).and_then(|window| { let change_focus_to = self.windows.get_mut(&window_id).and_then(|window| {
@ -1794,9 +1801,11 @@ impl AppContext {
observed_window_id: usize, observed_window_id: usize,
observed_view_id: usize, observed_view_id: usize,
) { ) {
if self let view_key = (observed_window_id, observed_view_id);
if let Some((view, mut view_metadata)) = self
.views .views
.contains_key(&(observed_window_id, observed_view_id)) .remove(&view_key)
.zip(self.views_metadata.remove(&view_key))
{ {
if let Some(window) = self.windows.get_mut(&observed_window_id) { if let Some(window) = self.windows.get_mut(&observed_window_id) {
window window
@ -1806,6 +1815,10 @@ impl AppContext {
.insert(observed_view_id); .insert(observed_view_id);
} }
view.update_keymap_context(&mut view_metadata.keymap_context, self);
self.views.insert(view_key, view);
self.views_metadata.insert(view_key, view_metadata);
let mut observations = self.observations.clone(); let mut observations = self.observations.clone();
observations.emit(observed_view_id, |callback| callback(self)); observations.emit(observed_view_id, |callback| callback(self));
} }
@ -2063,6 +2076,11 @@ pub enum ParentId {
Root, Root,
} }
struct ViewMetadata {
type_id: TypeId,
keymap_context: KeymapContext,
}
#[derive(Default, Clone)] #[derive(Default, Clone)]
pub struct WindowInvalidation { pub struct WindowInvalidation {
pub updated: HashSet<usize>, pub updated: HashSet<usize>,
@ -2403,7 +2421,7 @@ pub trait AnyView {
cx: &mut WindowContext, cx: &mut WindowContext,
view_id: usize, view_id: usize,
) -> bool; ) -> bool;
fn keymap_context(&self, cx: &AppContext) -> KeymapContext; fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &AppContext);
fn debug_json(&self, cx: &WindowContext) -> serde_json::Value; fn debug_json(&self, cx: &WindowContext) -> serde_json::Value;
fn text_for_range(&self, range: Range<usize>, cx: &WindowContext) -> Option<String>; fn text_for_range(&self, range: Range<usize>, cx: &WindowContext) -> Option<String>;
@ -2475,11 +2493,10 @@ where
cx.handle().into_any() cx.handle().into_any()
} else { } else {
let focused_type = cx let focused_type = cx
.views .views_metadata
.get(&(cx.window_id, focused_id)) .get(&(cx.window_id, focused_id))
.unwrap() .unwrap()
.as_any() .type_id;
.type_id();
AnyViewHandle::new( AnyViewHandle::new(
cx.window_id, cx.window_id,
focused_id, focused_id,
@ -2496,11 +2513,10 @@ where
cx.handle().into_any() cx.handle().into_any()
} else { } else {
let blurred_type = cx let blurred_type = cx
.views .views_metadata
.get(&(cx.window_id, blurred_id)) .get(&(cx.window_id, blurred_id))
.unwrap() .unwrap()
.as_any() .type_id;
.type_id();
AnyViewHandle::new( AnyViewHandle::new(
cx.window_id, cx.window_id,
blurred_id, blurred_id,
@ -2531,8 +2547,8 @@ where
View::modifiers_changed(self, event, &mut cx) View::modifiers_changed(self, event, &mut cx)
} }
fn keymap_context(&self, cx: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &AppContext) {
View::keymap_context(self, cx) View::update_keymap_context(self, keymap, cx)
} }
fn debug_json(&self, cx: &WindowContext) -> serde_json::Value { fn debug_json(&self, cx: &WindowContext) -> serde_json::Value {
@ -4708,7 +4724,7 @@ mod tests {
assert!(model_release_observed.get()); assert!(model_release_observed.get());
drop(view); drop(view);
cx.remove_window(window_id); cx.update_window(window_id, |cx| cx.remove_window());
assert!(view_released.get()); assert!(view_released.get());
assert!(view_release_observed.get()); assert!(view_release_observed.get());
} }
@ -5611,8 +5627,8 @@ mod tests {
"View" "View"
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
self.keymap_context.clone() *keymap = self.keymap_context.clone();
} }
} }
@ -5716,7 +5732,7 @@ mod tests {
} }
#[crate::test(self)] #[crate::test(self)]
fn test_keystrokes_for_action(cx: &mut AppContext) { fn test_keystrokes_for_action(cx: &mut TestAppContext) {
actions!(test, [Action1, Action2, GlobalAction]); actions!(test, [Action1, Action2, GlobalAction]);
struct View1 {} struct View1 {}
@ -5746,70 +5762,76 @@ mod tests {
} }
} }
let (window_id, view_1) = cx.add_window(Default::default(), |_| View1 {}); let (_, view_1) = cx.add_window(|_| View1 {});
let view_2 = cx.add_view(&view_1, |cx| { let view_2 = cx.add_view(&view_1, |cx| {
cx.focus_self(); cx.focus_self();
View2 {} View2 {}
}); });
cx.add_action(|_: &mut View1, _: &Action1, _cx| {}); cx.update(|cx| {
cx.add_action(|_: &mut View2, _: &Action2, _cx| {}); cx.add_action(|_: &mut View1, _: &Action1, _cx| {});
cx.add_global_action(|_: &GlobalAction, _| {}); cx.add_action(|_: &mut View2, _: &Action2, _cx| {});
cx.add_global_action(|_: &GlobalAction, _| {});
cx.add_bindings(vec![ cx.add_bindings(vec![
Binding::new("a", Action1, Some("View1")), Binding::new("a", Action1, Some("View1")),
Binding::new("b", Action2, Some("View1 > View2")), Binding::new("b", Action2, Some("View1 > View2")),
Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist
]); ]);
});
cx.update_window(window_id, |cx| { // Here we update the views to ensure that, even if they are on the stack,
// Sanity check // we can still retrieve keystrokes correctly.
assert_eq!( view_1.update(cx, |_, cx| {
cx.keystrokes_for_action(view_1.id(), &Action1) view_2.update(cx, |_, cx| {
.unwrap() // Sanity check
.as_slice(), assert_eq!(
&[Keystroke::parse("a").unwrap()] cx.keystrokes_for_action(view_1.id(), &Action1)
); .unwrap()
assert_eq!( .as_slice(),
cx.keystrokes_for_action(view_2.id(), &Action2) &[Keystroke::parse("a").unwrap()]
.unwrap() );
.as_slice(), assert_eq!(
&[Keystroke::parse("b").unwrap()] cx.keystrokes_for_action(view_2.id(), &Action2)
); .unwrap()
.as_slice(),
&[Keystroke::parse("b").unwrap()]
);
// The 'a' keystroke propagates up the view tree from view_2 // The 'a' keystroke propagates up the view tree from view_2
// to view_1. The action, Action1, is handled by view_1. // to view_1. The action, Action1, is handled by view_1.
assert_eq!( assert_eq!(
cx.keystrokes_for_action(view_2.id(), &Action1) cx.keystrokes_for_action(view_2.id(), &Action1)
.unwrap() .unwrap()
.as_slice(), .as_slice(),
&[Keystroke::parse("a").unwrap()] &[Keystroke::parse("a").unwrap()]
); );
// Actions that are handled below the current view don't have bindings // Actions that are handled below the current view don't have bindings
assert_eq!(cx.keystrokes_for_action(view_1.id(), &Action2), None); assert_eq!(cx.keystrokes_for_action(view_1.id(), &Action2), None);
// Actions that are handled in other branches of the tree should not have a binding // Actions that are handled in other branches of the tree should not have a binding
assert_eq!(cx.keystrokes_for_action(view_2.id(), &GlobalAction), None); assert_eq!(cx.keystrokes_for_action(view_2.id(), &GlobalAction), None);
// Check that global actions do not have a binding, even if a binding does exist in another view // Check that global actions do not have a binding, even if a binding does exist in another view
assert_eq!( assert_eq!(
&available_actions(view_1.id(), cx), &available_actions(view_1.id(), cx),
&[ &[
("test::Action1", vec![Keystroke::parse("a").unwrap()]), ("test::Action1", vec![Keystroke::parse("a").unwrap()]),
("test::GlobalAction", vec![]) ("test::GlobalAction", vec![])
], ],
); );
// Check that view 1 actions and bindings are available even when called from view 2 // Check that view 1 actions and bindings are available even when called from view 2
assert_eq!( assert_eq!(
&available_actions(view_2.id(), cx), &available_actions(view_2.id(), cx),
&[ &[
("test::Action1", vec![Keystroke::parse("a").unwrap()]), ("test::Action1", vec![Keystroke::parse("a").unwrap()]),
("test::Action2", vec![Keystroke::parse("b").unwrap()]), ("test::Action2", vec![Keystroke::parse("b").unwrap()]),
("test::GlobalAction", vec![]), ("test::GlobalAction", vec![]),
], ],
); );
});
}); });
// Produces a list of actions and key bindings // Produces a list of actions and key bindings

View file

@ -180,7 +180,11 @@ impl TestAppContext {
} }
pub fn window_ids(&self) -> Vec<usize> { pub fn window_ids(&self) -> Vec<usize> {
self.cx.borrow().window_ids().collect() self.cx.borrow().windows.keys().copied().collect()
}
pub fn remove_all_windows(&mut self) {
self.update(|cx| cx.windows.clear());
} }
pub fn read<T, F: FnOnce(&AppContext) -> T>(&self, callback: F) -> T { pub fn read<T, F: FnOnce(&AppContext) -> T>(&self, callback: F) -> T {

View file

@ -1,8 +1,8 @@
use crate::{ use crate::{
elements::AnyRootElement, elements::AnyRootElement,
geometry::rect::RectF, geometry::rect::RectF,
json::{self, ToJson}, json::ToJson,
keymap_matcher::{Binding, Keystroke, MatchResult}, keymap_matcher::{Binding, KeymapContext, Keystroke, MatchResult},
platform::{ platform::{
self, Appearance, CursorStyle, Event, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, self, Appearance, CursorStyle, Event, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent,
MouseButton, MouseMovedEvent, PromptLevel, WindowBounds, MouseButton, MouseMovedEvent, PromptLevel, WindowBounds,
@ -34,7 +34,7 @@ use std::{
use util::ResultExt; use util::ResultExt;
use uuid::Uuid; use uuid::Uuid;
use super::Reference; use super::{Reference, ViewMetadata};
pub struct Window { pub struct Window {
pub(crate) root_view: Option<AnyViewHandle>, pub(crate) root_view: Option<AnyViewHandle>,
@ -369,13 +369,13 @@ impl<'a> WindowContext<'a> {
let mut contexts = Vec::new(); let mut contexts = Vec::new();
let mut handler_depth = None; let mut handler_depth = None;
for (i, view_id) in self.ancestors(view_id).enumerate() { for (i, view_id) in self.ancestors(view_id).enumerate() {
if let Some(view) = self.views.get(&(window_id, view_id)) { if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) {
if let Some(actions) = self.actions.get(&view.as_any().type_id()) { if let Some(actions) = self.actions.get(&view_metadata.type_id) {
if actions.contains_key(&action.as_any().type_id()) { if actions.contains_key(&action.as_any().type_id()) {
handler_depth = Some(i); handler_depth = Some(i);
} }
} }
contexts.push(view.keymap_context(self)); contexts.push(view_metadata.keymap_context.clone());
} }
} }
@ -406,10 +406,9 @@ impl<'a> WindowContext<'a> {
let mut contexts = Vec::new(); let mut contexts = Vec::new();
let mut handler_depths_by_action_type = HashMap::<TypeId, usize>::default(); let mut handler_depths_by_action_type = HashMap::<TypeId, usize>::default();
for (depth, view_id) in self.ancestors(view_id).enumerate() { for (depth, view_id) in self.ancestors(view_id).enumerate() {
if let Some(view) = self.views.get(&(window_id, view_id)) { if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) {
contexts.push(view.keymap_context(self)); contexts.push(view_metadata.keymap_context.clone());
let view_type = view.as_any().type_id(); if let Some(actions) = self.actions.get(&view_metadata.type_id) {
if let Some(actions) = self.actions.get(&view_type) {
handler_depths_by_action_type.extend( handler_depths_by_action_type.extend(
actions actions
.keys() .keys()
@ -458,9 +457,9 @@ impl<'a> WindowContext<'a> {
let dispatch_path = self let dispatch_path = self
.ancestors(focused_view_id) .ancestors(focused_view_id)
.filter_map(|view_id| { .filter_map(|view_id| {
self.views self.views_metadata
.get(&(window_id, view_id)) .get(&(window_id, view_id))
.map(|view| (view_id, view.keymap_context(self))) .map(|view| (view_id, view.keymap_context.clone()))
}) })
.collect(); .collect();
@ -975,17 +974,6 @@ impl<'a> WindowContext<'a> {
.flatten() .flatten()
} }
pub fn debug_elements(&self) -> Option<json::Value> {
let view = self.window.root_view();
Some(json!({
"root_view": view.debug_json(self),
"root_element": self.window.rendered_views.get(&view.id())
.and_then(|root_element| {
root_element.debug(self).log_err()
})
}))
}
pub fn set_window_title(&mut self, title: &str) { pub fn set_window_title(&mut self, title: &str) {
self.window.platform_window.set_title(title); self.window.platform_window.set_title(title);
} }
@ -1188,6 +1176,15 @@ impl<'a> WindowContext<'a> {
self.parents.insert((window_id, view_id), parent_id); self.parents.insert((window_id, view_id), parent_id);
let mut cx = ViewContext::mutable(self, view_id); let mut cx = ViewContext::mutable(self, view_id);
let handle = if let Some(view) = build_view(&mut cx) { let handle = if let Some(view) = build_view(&mut cx) {
let mut keymap_context = KeymapContext::default();
view.update_keymap_context(&mut keymap_context, cx.app_context());
self.views_metadata.insert(
(window_id, view_id),
ViewMetadata {
type_id: TypeId::of::<T>(),
keymap_context,
},
);
self.views.insert((window_id, view_id), Box::new(view)); self.views.insert((window_id, view_id), Box::new(view));
self.window self.window
.invalidation .invalidation
@ -1454,13 +1451,7 @@ impl<V: View> Element<V> for ChildView {
) -> serde_json::Value { ) -> serde_json::Value {
json!({ json!({
"type": "ChildView", "type": "ChildView",
"view_id": self.view_id,
"bounds": bounds.to_json(), "bounds": bounds.to_json(),
"view": if let Some(view) = cx.views.get(&(cx.window_id, self.view_id)) {
view.debug_json(cx)
} else {
json!(null)
},
"child": if let Some(element) = cx.window.rendered_views.get(&self.view_id) { "child": if let Some(element) = cx.window.rendered_views.get(&self.view_id) {
element.debug(&cx.window_context).log_err().unwrap_or_else(|| json!(null)) element.debug(&cx.window_context).log_err().unwrap_or_else(|| json!(null))
} else { } else {

View file

@ -45,7 +45,6 @@ use std::{
mem, mem,
ops::{Deref, DerefMut, Range}, ops::{Deref, DerefMut, Range},
}; };
use util::ResultExt;
pub trait Element<V: View>: 'static { pub trait Element<V: View>: 'static {
type LayoutState; type LayoutState;
@ -709,7 +708,12 @@ impl<V: View> AnyRootElement for RootElement<V> {
.ok_or_else(|| anyhow!("debug called on a root element for a dropped view"))?; .ok_or_else(|| anyhow!("debug called on a root element for a dropped view"))?;
let view = view.read(cx); let view = view.read(cx);
let view_context = ViewContext::immutable(cx, self.view.id()); let view_context = ViewContext::immutable(cx, self.view.id());
Ok(self.element.debug(view, &view_context)) Ok(serde_json::json!({
"view_id": self.view.id(),
"view_name": V::ui_name(),
"view": view.debug_json(cx),
"element": self.element.debug(view, &view_context)
}))
} }
fn name(&self) -> Option<&str> { fn name(&self) -> Option<&str> {
@ -717,63 +721,6 @@ impl<V: View> AnyRootElement for RootElement<V> {
} }
} }
impl<V: View, R: View> Element<V> for RootElement<R> {
type LayoutState = ();
type PaintState = ();
fn layout(
&mut self,
constraint: SizeConstraint,
_view: &mut V,
cx: &mut ViewContext<V>,
) -> (Vector2F, ()) {
let size = AnyRootElement::layout(self, constraint, cx)
.log_err()
.unwrap_or_else(|| Vector2F::zero());
(size, ())
}
fn paint(
&mut self,
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
_layout: &mut Self::LayoutState,
_view: &mut V,
cx: &mut ViewContext<V>,
) {
AnyRootElement::paint(self, scene, bounds.origin(), visible_bounds, cx).log_err();
}
fn rect_for_text_range(
&self,
range_utf16: Range<usize>,
_bounds: RectF,
_visible_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
_view: &V,
cx: &ViewContext<V>,
) -> Option<RectF> {
AnyRootElement::rect_for_text_range(self, range_utf16, cx)
.log_err()
.flatten()
}
fn debug(
&self,
_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
_view: &V,
cx: &ViewContext<V>,
) -> serde_json::Value {
AnyRootElement::debug(self, cx)
.log_err()
.unwrap_or_default()
}
}
pub trait ParentElement<'a, V: View>: Extend<AnyElement<V>> + Sized { pub trait ParentElement<'a, V: View>: Extend<AnyElement<V>> + Sized {
fn add_children<E: Element<V>>(&mut self, children: impl IntoIterator<Item = E>) { fn add_children<E: Element<V>>(&mut self, children: impl IntoIterator<Item = E>) {
self.extend(children.into_iter().map(|child| child.into_any())); self.extend(children.into_iter().map(|child| child.into_any()));

View file

@ -17,6 +17,11 @@ impl KeymapContext {
} }
} }
pub fn clear(&mut self) {
self.set.clear();
self.map.clear();
}
pub fn extend(&mut self, other: &Self) { pub fn extend(&mut self, other: &Self) {
for v in &other.set { for v in &other.set {
self.set.insert(v.clone()); self.set.insert(v.clone());

View file

@ -223,41 +223,41 @@ impl HandlerSet {
set.insert( set.insert(
HandlerKey::new(MouseEvent::move_disc(), None), HandlerKey::new(MouseEvent::move_disc(), None),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
set.insert( set.insert(
HandlerKey::new(MouseEvent::hover_disc(), None), HandlerKey::new(MouseEvent::hover_disc(), None),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
for button in MouseButton::all() { for button in MouseButton::all() {
set.insert( set.insert(
HandlerKey::new(MouseEvent::drag_disc(), Some(button)), HandlerKey::new(MouseEvent::drag_disc(), Some(button)),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
set.insert( set.insert(
HandlerKey::new(MouseEvent::down_disc(), Some(button)), HandlerKey::new(MouseEvent::down_disc(), Some(button)),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
set.insert( set.insert(
HandlerKey::new(MouseEvent::up_disc(), Some(button)), HandlerKey::new(MouseEvent::up_disc(), Some(button)),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
set.insert( set.insert(
HandlerKey::new(MouseEvent::click_disc(), Some(button)), HandlerKey::new(MouseEvent::click_disc(), Some(button)),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
set.insert( set.insert(
HandlerKey::new(MouseEvent::down_out_disc(), Some(button)), HandlerKey::new(MouseEvent::down_out_disc(), Some(button)),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
set.insert( set.insert(
HandlerKey::new(MouseEvent::up_out_disc(), Some(button)), HandlerKey::new(MouseEvent::up_out_disc(), Some(button)),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
} }
set.insert( set.insert(
HandlerKey::new(MouseEvent::scroll_wheel_disc(), None), HandlerKey::new(MouseEvent::scroll_wheel_disc(), None),
SmallVec::from_buf([Rc::new(|_, _, _, _| false)]), SmallVec::from_buf([Rc::new(|_, _, _, _| true)]),
); );
HandlerSet { set } HandlerSet { set }

View file

@ -100,7 +100,7 @@ pub fn run_test(
test_fn(cx, foreground_platform.clone(), deterministic.clone(), seed); test_fn(cx, foreground_platform.clone(), deterministic.clone(), seed);
}); });
cx.update(|cx| cx.remove_all_windows()); cx.remove_all_windows();
deterministic.run_until_parked(); deterministic.run_until_parked();
cx.update(|cx| cx.clear_globals()); cx.update(|cx| cx.clear_globals());

View file

@ -137,7 +137,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
); );
)); ));
cx_teardowns.extend(quote!( cx_teardowns.extend(quote!(
#cx_varname.update(|cx| cx.remove_all_windows()); #cx_varname.remove_all_windows();
deterministic.run_until_parked(); deterministic.run_until_parked();
#cx_varname.update(|cx| cx.clear_globals()); #cx_varname.update(|cx| cx.clear_globals());
)); ));
@ -212,7 +212,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
); );
)); ));
cx_teardowns.extend(quote!( cx_teardowns.extend(quote!(
#cx_varname.update(|cx| cx.remove_all_windows()); #cx_varname.remove_all_windows();
deterministic.run_until_parked(); deterministic.run_until_parked();
#cx_varname.update(|cx| cx.clear_globals()); #cx_varname.update(|cx| cx.clear_globals());
)); ));

View file

@ -187,6 +187,7 @@ impl PickerDelegate for OutlineViewDelegate {
active_editor.change_selections(Some(Autoscroll::center()), cx, |s| { active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
s.select_ranges([position..position]) s.select_ranges([position..position])
}); });
active_editor.highlight_rows(None);
} }
}); });
cx.emit(PickerEvent::Dismiss); cx.emit(PickerEvent::Dismiss);

View file

@ -126,10 +126,9 @@ impl<D: PickerDelegate> View for Picker<D> {
.into_any_named("picker") .into_any_named("picker")
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
let mut cx = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
cx.add_identifier("menu"); keymap.add_identifier("menu");
cx
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View file

@ -1352,10 +1352,9 @@ impl View for ProjectPanel {
} }
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
let mut cx = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
cx.add_identifier("menu"); keymap.add_identifier("menu");
cx
} }
} }

View file

@ -454,11 +454,11 @@ impl View for TerminalView {
}); });
} }
fn keymap_context(&self, cx: &gpui::AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, cx: &gpui::AppContext) {
let mut context = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
let mode = self.terminal.read(cx).last_content.mode; let mode = self.terminal.read(cx).last_content.mode;
context.add_key( keymap.add_key(
"screen", "screen",
if mode.contains(TermMode::ALT_SCREEN) { if mode.contains(TermMode::ALT_SCREEN) {
"alt" "alt"
@ -468,40 +468,40 @@ impl View for TerminalView {
); );
if mode.contains(TermMode::APP_CURSOR) { if mode.contains(TermMode::APP_CURSOR) {
context.add_identifier("DECCKM"); keymap.add_identifier("DECCKM");
} }
if mode.contains(TermMode::APP_KEYPAD) { if mode.contains(TermMode::APP_KEYPAD) {
context.add_identifier("DECPAM"); keymap.add_identifier("DECPAM");
} else { } else {
context.add_identifier("DECPNM"); keymap.add_identifier("DECPNM");
} }
if mode.contains(TermMode::SHOW_CURSOR) { if mode.contains(TermMode::SHOW_CURSOR) {
context.add_identifier("DECTCEM"); keymap.add_identifier("DECTCEM");
} }
if mode.contains(TermMode::LINE_WRAP) { if mode.contains(TermMode::LINE_WRAP) {
context.add_identifier("DECAWM"); keymap.add_identifier("DECAWM");
} }
if mode.contains(TermMode::ORIGIN) { if mode.contains(TermMode::ORIGIN) {
context.add_identifier("DECOM"); keymap.add_identifier("DECOM");
} }
if mode.contains(TermMode::INSERT) { if mode.contains(TermMode::INSERT) {
context.add_identifier("IRM"); keymap.add_identifier("IRM");
} }
//LNM is apparently the name for this. https://vt100.net/docs/vt510-rm/LNM.html //LNM is apparently the name for this. https://vt100.net/docs/vt510-rm/LNM.html
if mode.contains(TermMode::LINE_FEED_NEW_LINE) { if mode.contains(TermMode::LINE_FEED_NEW_LINE) {
context.add_identifier("LNM"); keymap.add_identifier("LNM");
} }
if mode.contains(TermMode::FOCUS_IN_OUT) { if mode.contains(TermMode::FOCUS_IN_OUT) {
context.add_identifier("report_focus"); keymap.add_identifier("report_focus");
} }
if mode.contains(TermMode::ALTERNATE_SCROLL) { if mode.contains(TermMode::ALTERNATE_SCROLL) {
context.add_identifier("alternate_scroll"); keymap.add_identifier("alternate_scroll");
} }
if mode.contains(TermMode::BRACKETED_PASTE) { if mode.contains(TermMode::BRACKETED_PASTE) {
context.add_identifier("bracketed_paste"); keymap.add_identifier("bracketed_paste");
} }
if mode.intersects(TermMode::MOUSE_MODE) { if mode.intersects(TermMode::MOUSE_MODE) {
context.add_identifier("any_mouse_reporting"); keymap.add_identifier("any_mouse_reporting");
} }
{ {
let mouse_reporting = if mode.contains(TermMode::MOUSE_REPORT_CLICK) { let mouse_reporting = if mode.contains(TermMode::MOUSE_REPORT_CLICK) {
@ -513,7 +513,7 @@ impl View for TerminalView {
} else { } else {
"off" "off"
}; };
context.add_key("mouse_reporting", mouse_reporting); keymap.add_key("mouse_reporting", mouse_reporting);
} }
{ {
let format = if mode.contains(TermMode::SGR_MOUSE) { let format = if mode.contains(TermMode::SGR_MOUSE) {
@ -523,9 +523,8 @@ impl View for TerminalView {
} else { } else {
"normal" "normal"
}; };
context.add_key("mouse_format", format); keymap.add_key("mouse_format", format);
} }
context
} }
} }

View file

@ -9,11 +9,18 @@ pub fn init(cx: &mut AppContext) {
} }
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) { fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
if let Some(previously_active_editor) = Vim::read(cx).active_editor.clone() {
cx.update_window(previously_active_editor.window_id(), |cx| {
Vim::update(cx, |vim, cx| {
vim.update_active_editor(cx, |previously_active_editor, cx| {
Vim::unhook_vim_settings(previously_active_editor, cx);
});
});
});
}
cx.update_window(editor.window_id(), |cx| { cx.update_window(editor.window_id(), |cx| {
Vim::update(cx, |vim, cx| { Vim::update(cx, |vim, cx| {
vim.update_active_editor(cx, |previously_active_editor, cx| {
Vim::unhook_vim_settings(previously_active_editor, cx);
});
vim.set_active_editor(editor.clone(), cx); vim.set_active_editor(editor.clone(), cx);
}); });
}); });
@ -28,9 +35,7 @@ fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
} }
} }
cx.update_window(editor.window_id(), |cx| { editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx))
editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx))
});
}); });
}); });
} }

View file

@ -84,7 +84,12 @@ pub fn init(cx: &mut AppContext) {
Vim::active_editor_input_ignored("\n".into(), cx) Vim::active_editor_input_ignored("\n".into(), cx)
}); });
// Any time settings change, update vim mode to match. // Any time settings change, update vim mode to match. The Vim struct
// will be initialized as disabled by default, so we filter its commands
// out when starting up.
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
filter.filtered_namespaces.insert("vim");
});
cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| { cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| {
vim.set_enabled(cx.global::<Settings>().vim_mode, cx) vim.set_enabled(cx.global::<Settings>().vim_mode, cx)
}); });
@ -309,7 +314,7 @@ impl Vim {
editor.set_input_enabled(!state.vim_controlled()); editor.set_input_enabled(!state.vim_controlled());
editor.selections.line_mode = matches!(state.mode, Mode::Visual { line: true }); editor.selections.line_mode = matches!(state.mode, Mode::Visual { line: true });
let context_layer = state.keymap_context_layer(); let context_layer = state.keymap_context_layer();
editor.set_keymap_context_layer::<Self>(context_layer); editor.set_keymap_context_layer::<Self>(context_layer, cx);
} else { } else {
Self::unhook_vim_settings(editor, cx); Self::unhook_vim_settings(editor, cx);
} }
@ -321,7 +326,7 @@ impl Vim {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.set_input_enabled(true); editor.set_input_enabled(true);
editor.selections.line_mode = false; editor.selections.line_mode = false;
editor.remove_keymap_context_layer::<Self>(); editor.remove_keymap_context_layer::<Self>(cx);
} }
} }

View file

@ -1854,12 +1854,11 @@ impl View for Pane {
}); });
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn update_keymap_context(&self, keymap: &mut KeymapContext, _: &AppContext) {
let mut keymap = Self::default_keymap_context(); Self::reset_to_default_keymap_context(keymap);
if self.docked.is_some() { if self.docked.is_some() {
keymap.add_identifier("docked"); keymap.add_identifier("docked");
} }
keymap
} }
} }

View file

@ -39,7 +39,6 @@ use gpui::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
impl_actions, impl_internal_actions, impl_actions, impl_internal_actions,
keymap_matcher::KeymapContext,
platform::{ platform::{
CursorStyle, MouseButton, PathPromptOptions, Platform, PromptLevel, WindowBounds, CursorStyle, MouseButton, PathPromptOptions, Platform, PromptLevel, WindowBounds,
WindowOptions, WindowOptions,
@ -1044,7 +1043,7 @@ impl Workspace {
&self.project &self.project
} }
pub fn client(&self) -> &Client { pub fn client(&self) -> &Arc<Client> {
&self.client &self.client
} }
@ -1110,12 +1109,18 @@ impl Workspace {
} }
pub fn close_global(_: &CloseWindow, cx: &mut AppContext) { pub fn close_global(_: &CloseWindow, cx: &mut AppContext) {
let id = cx.window_ids().find(|&id| cx.window_is_active(id)); cx.spawn(|mut cx| async move {
if let Some(id) = id { let id = cx
//This can only get called when the window's project connection has been lost .window_ids()
//so we don't need to prompt the user for anything and instead just close the window .into_iter()
cx.remove_window(id); .find(|&id| cx.window_is_active(id));
} if let Some(id) = id {
//This can only get called when the window's project connection has been lost
//so we don't need to prompt the user for anything and instead just close the window
cx.remove_window(id);
}
})
.detach();
} }
pub fn close( pub fn close(
@ -1140,19 +1145,14 @@ impl Workspace {
) -> Task<Result<bool>> { ) -> Task<Result<bool>> {
let active_call = self.active_call().cloned(); let active_call = self.active_call().cloned();
let window_id = cx.window_id(); let window_id = cx.window_id();
let workspace_count = cx
.window_ids()
.collect::<Vec<_>>()
.into_iter()
.filter_map(|window_id| {
cx.app_context()
.root_view(window_id)?
.clone()
.downcast::<Workspace>()
})
.count();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
let workspace_count = cx
.window_ids()
.into_iter()
.filter_map(|window_id| cx.root_view(window_id)?.clone().downcast::<Workspace>())
.count();
if let Some(active_call) = active_call { if let Some(active_call) = active_call {
if !quitting if !quitting
&& workspace_count == 1 && workspace_count == 1
@ -2925,10 +2925,6 @@ impl View for Workspace {
} }
} }
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext {
Self::default_keymap_context()
}
} }
impl ViewId { impl ViewId {
@ -2979,10 +2975,10 @@ impl std::fmt::Debug for OpenPaths {
pub struct WorkspaceCreated(WeakViewHandle<Workspace>); pub struct WorkspaceCreated(WeakViewHandle<Workspace>);
pub fn activate_workspace_for_project( pub fn activate_workspace_for_project(
cx: &mut AppContext, cx: &mut AsyncAppContext,
predicate: impl Fn(&mut Project, &mut ModelContext<Project>) -> bool, predicate: impl Fn(&mut Project, &mut ModelContext<Project>) -> bool,
) -> Option<WeakViewHandle<Workspace>> { ) -> Option<WeakViewHandle<Workspace>> {
for window_id in cx.window_ids().collect::<Vec<_>>() { for window_id in cx.window_ids() {
let handle = cx let handle = cx
.update_window(window_id, |cx| { .update_window(window_id, |cx| {
if let Some(workspace_handle) = cx.root_view().clone().downcast::<Workspace>() { if let Some(workspace_handle) = cx.root_view().clone().downcast::<Workspace>() {
@ -3021,13 +3017,14 @@ pub fn open_paths(
> { > {
log::info!("open paths {:?}", abs_paths); log::info!("open paths {:?}", abs_paths);
// Open paths in existing workspace if possible
let existing =
activate_workspace_for_project(cx, |project, cx| project.contains_paths(abs_paths, cx));
let app_state = app_state.clone(); let app_state = app_state.clone();
let abs_paths = abs_paths.to_vec(); let abs_paths = abs_paths.to_vec();
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
// Open paths in existing workspace if possible
let existing = activate_workspace_for_project(&mut cx, |project, cx| {
project.contains_paths(&abs_paths, cx)
});
if let Some(existing) = existing { if let Some(existing) = existing {
Ok(( Ok((
existing.clone(), existing.clone(),

View file

@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
description = "The fast, collaborative code editor." description = "The fast, collaborative code editor."
edition = "2021" edition = "2021"
name = "zed" name = "zed"
version = "0.84.0" version = "0.84.5"
publish = false publish = false
[lib] [lib]

View file

@ -1 +1 @@
dev stable

View file

@ -11,6 +11,7 @@ use collections::VecDeque;
pub use editor; pub use editor;
use editor::{Editor, MultiBuffer}; use editor::{Editor, MultiBuffer};
use anyhow::anyhow;
use feedback::{ use feedback::{
feedback_info_text::FeedbackInfoText, submit_feedback_button::SubmitFeedbackButton, feedback_info_text::FeedbackInfoText, submit_feedback_button::SubmitFeedbackButton,
}; };
@ -223,9 +224,14 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
move |_: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| { move |_: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| {
let app_state = app_state.clone(); let app_state = app_state.clone();
let markdown = app_state.languages.language_for_name("JSON"); let markdown = app_state.languages.language_for_name("JSON");
let content = to_string_pretty(&cx.debug_elements()).unwrap(); let window_id = cx.window_id();
cx.spawn(|workspace, mut cx| async move { cx.spawn(|workspace, mut cx| async move {
let markdown = markdown.await.log_err(); let markdown = markdown.await.log_err();
let content = to_string_pretty(
&cx.debug_elements(window_id)
.ok_or_else(|| anyhow!("could not debug elements for {window_id}"))?,
)
.unwrap();
workspace workspace
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
workspace.with_local_workspace(&app_state, cx, move |workspace, cx| { workspace.with_local_workspace(&app_state, cx, move |workspace, cx| {
@ -303,7 +309,7 @@ pub fn initialize_workspace(
cx.emit(workspace::Event::PaneAdded(workspace.dock_pane().clone())); cx.emit(workspace::Event::PaneAdded(workspace.dock_pane().clone()));
let collab_titlebar_item = let collab_titlebar_item =
cx.add_view(|cx| CollabTitlebarItem::new(&workspace_handle, &app_state.user_store, cx)); cx.add_view(|cx| CollabTitlebarItem::new(workspace, &workspace_handle, cx));
workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx); workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
let project_panel = ProjectPanel::new(workspace.project().clone(), cx); let project_panel = ProjectPanel::new(workspace.project().clone(), cx);
@ -372,24 +378,25 @@ pub fn build_window_options(
} }
fn restart(_: &Restart, cx: &mut gpui::AppContext) { fn restart(_: &Restart, cx: &mut gpui::AppContext) {
let mut workspaces = cx
.window_ids()
.filter_map(|window_id| {
Some(
cx.root_view(window_id)?
.clone()
.downcast::<Workspace>()?
.downgrade(),
)
})
.collect::<Vec<_>>();
// If multiple windows have unsaved changes, and need a save prompt,
// prompt in the active window before switching to a different window.
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
let should_confirm = cx.global::<Settings>().confirm_quit; let should_confirm = cx.global::<Settings>().confirm_quit;
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let mut workspaces = cx
.window_ids()
.into_iter()
.filter_map(|window_id| {
Some(
cx.root_view(window_id)?
.clone()
.downcast::<Workspace>()?
.downgrade(),
)
})
.collect::<Vec<_>>();
// If multiple windows have unsaved changes, and need a save prompt,
// prompt in the active window before switching to a different window.
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
if let (true, Some(workspace)) = (should_confirm, workspaces.first()) { if let (true, Some(workspace)) = (should_confirm, workspaces.first()) {
let answer = cx.prompt( let answer = cx.prompt(
workspace.window_id(), workspace.window_id(),
@ -424,24 +431,25 @@ fn restart(_: &Restart, cx: &mut gpui::AppContext) {
} }
fn quit(_: &Quit, cx: &mut gpui::AppContext) { fn quit(_: &Quit, cx: &mut gpui::AppContext) {
let mut workspaces = cx
.window_ids()
.filter_map(|window_id| {
Some(
cx.root_view(window_id)?
.clone()
.downcast::<Workspace>()?
.downgrade(),
)
})
.collect::<Vec<_>>();
// If multiple windows have unsaved changes, and need a save prompt,
// prompt in the active window before switching to a different window.
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
let should_confirm = cx.global::<Settings>().confirm_quit; let should_confirm = cx.global::<Settings>().confirm_quit;
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let mut workspaces = cx
.window_ids()
.into_iter()
.filter_map(|window_id| {
Some(
cx.root_view(window_id)?
.clone()
.downcast::<Workspace>()?
.downgrade(),
)
})
.collect::<Vec<_>>();
// If multiple windows have unsaved changes, and need a save prompt,
// prompt in the active window before switching to a different window.
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
if let (true, Some(workspace)) = (should_confirm, workspaces.first()) { if let (true, Some(workspace)) = (should_confirm, workspaces.first()) {
let answer = cx.prompt( let answer = cx.prompt(
workspace.window_id(), workspace.window_id(),