Compare commits
9 Commits
fix-git-ht
...
v0.127.2-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a24b8f2e09 | ||
|
|
642fd36fdc | ||
|
|
743760be87 | ||
|
|
2db783ad04 | ||
|
|
597858ef99 | ||
|
|
327879e054 | ||
|
|
c1b4f3d817 | ||
|
|
5bc4c4250c | ||
|
|
ced690dc0b |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -12748,7 +12748,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zed"
|
||||
version = "0.127.0"
|
||||
version = "0.127.2"
|
||||
dependencies = [
|
||||
"activity_indicator",
|
||||
"anyhow",
|
||||
|
||||
@@ -1144,7 +1144,7 @@ impl AppContext {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dispatch_global_action(&mut self, action: &dyn Action) {
|
||||
fn dispatch_global_action(&mut self, action: &dyn Action) {
|
||||
self.propagate_event = true;
|
||||
|
||||
if let Some(mut global_listeners) = self
|
||||
|
||||
@@ -1307,6 +1307,7 @@ impl Interactivity {
|
||||
|| self.has_hover_styles()
|
||||
|| self.has_mouse_listeners()
|
||||
|| self.scroll_offset.is_some()
|
||||
|| self.tracked_focus_handle.is_some()
|
||||
{
|
||||
Some(cx.insert_hitbox(bounds, self.occlude_mouse))
|
||||
} else {
|
||||
@@ -1330,6 +1331,7 @@ impl Interactivity {
|
||||
!self.mouse_up_listeners.is_empty()
|
||||
|| !self.mouse_down_listeners.is_empty()
|
||||
|| !self.mouse_move_listeners.is_empty()
|
||||
|| !self.click_listeners.is_empty()
|
||||
|| !self.scroll_wheel_listeners.is_empty()
|
||||
|| self.drag_listener.is_some()
|
||||
|| !self.drop_listeners.is_empty()
|
||||
|
||||
@@ -29,7 +29,7 @@ use std::{
|
||||
rc::Rc,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering::SeqCst},
|
||||
Arc,
|
||||
Arc, Weak,
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
@@ -155,6 +155,14 @@ impl FocusHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts this focus handle into a weak variant, which does not prevent it from being released.
|
||||
pub fn downgrade(&self) -> WeakFocusHandle {
|
||||
WeakFocusHandle {
|
||||
id: self.id,
|
||||
handles: Arc::downgrade(&self.handles),
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves the focus to the element associated with this handle.
|
||||
pub fn focus(&self, cx: &mut WindowContext) {
|
||||
cx.focus(self)
|
||||
@@ -207,6 +215,41 @@ impl Drop for FocusHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// A weak reference to a focus handle.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WeakFocusHandle {
|
||||
pub(crate) id: FocusId,
|
||||
handles: Weak<RwLock<SlotMap<FocusId, AtomicUsize>>>,
|
||||
}
|
||||
|
||||
impl WeakFocusHandle {
|
||||
/// Attempts to upgrade the [WeakFocusHandle] to a [FocusHandle].
|
||||
pub fn upgrade(&self) -> Option<FocusHandle> {
|
||||
let handles = self.handles.upgrade()?;
|
||||
FocusHandle::for_id(self.id, &handles)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for WeakFocusHandle {
|
||||
fn eq(&self, other: &WeakFocusHandle) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for WeakFocusHandle {}
|
||||
|
||||
impl PartialEq<FocusHandle> for WeakFocusHandle {
|
||||
fn eq(&self, other: &FocusHandle) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<WeakFocusHandle> for FocusHandle {
|
||||
fn eq(&self, other: &WeakFocusHandle) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
/// FocusableView allows users of your view to easily
|
||||
/// focus it (using cx.focus_view(view))
|
||||
pub trait FocusableView: 'static + Render {
|
||||
@@ -653,7 +696,6 @@ impl<'a> WindowContext<'a> {
|
||||
|
||||
let window = self.window.handle;
|
||||
self.app.defer(move |cx| {
|
||||
cx.propagate_event = true;
|
||||
window
|
||||
.update(cx, |_, cx| {
|
||||
let node_id = focus_handle
|
||||
@@ -668,9 +710,6 @@ impl<'a> WindowContext<'a> {
|
||||
cx.dispatch_action_on_node(node_id, action.as_ref());
|
||||
})
|
||||
.log_err();
|
||||
if cx.propagate_event {
|
||||
cx.dispatch_global_action(action.as_ref());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -956,12 +995,6 @@ impl<'a> WindowContext<'a> {
|
||||
self.window.next_frame.focus = self.window.focus;
|
||||
self.window.next_frame.window_active = self.window.active.get();
|
||||
|
||||
// Set the cursor only if we're the active window.
|
||||
if self.is_window_active() {
|
||||
let cursor_style = self.compute_cursor_style().unwrap_or(CursorStyle::Arrow);
|
||||
self.platform.set_cursor_style(cursor_style);
|
||||
}
|
||||
|
||||
// Register requested input handler with the platform window.
|
||||
if let Some(input_handler) = self.window.next_frame.input_handlers.pop() {
|
||||
self.window
|
||||
@@ -1017,6 +1050,8 @@ impl<'a> WindowContext<'a> {
|
||||
.clone()
|
||||
.retain(&(), |listener| listener(&event, self));
|
||||
}
|
||||
|
||||
self.reset_cursor_style();
|
||||
self.window.refreshing = false;
|
||||
self.window.draw_phase = DrawPhase::None;
|
||||
self.window.needs_present.set(true);
|
||||
@@ -1031,16 +1066,20 @@ impl<'a> WindowContext<'a> {
|
||||
profiling::finish_frame!();
|
||||
}
|
||||
|
||||
fn compute_cursor_style(&mut self) -> Option<CursorStyle> {
|
||||
// TODO: maybe we should have a HashMap keyed by HitboxId.
|
||||
let request = self
|
||||
.window
|
||||
.next_frame
|
||||
.cursor_styles
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|request| request.hitbox_id.is_hovered(self))?;
|
||||
Some(request.style)
|
||||
fn reset_cursor_style(&self) {
|
||||
// Set the cursor only if we're the active window.
|
||||
if self.is_window_active() {
|
||||
let style = self
|
||||
.window
|
||||
.rendered_frame
|
||||
.cursor_styles
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|request| request.hitbox_id.is_hovered(self))
|
||||
.map(|request| request.style)
|
||||
.unwrap_or(CursorStyle::Arrow);
|
||||
self.platform.set_cursor_style(style);
|
||||
}
|
||||
}
|
||||
|
||||
/// Dispatch a given keystroke as though the user had typed it.
|
||||
@@ -1175,7 +1214,11 @@ impl<'a> WindowContext<'a> {
|
||||
}
|
||||
|
||||
fn dispatch_mouse_event(&mut self, event: &dyn Any) {
|
||||
self.window.mouse_hit_test = self.window.rendered_frame.hit_test(self.mouse_position());
|
||||
let hit_test = self.window.rendered_frame.hit_test(self.mouse_position());
|
||||
if hit_test != self.window.mouse_hit_test {
|
||||
self.window.mouse_hit_test = hit_test;
|
||||
self.reset_cursor_style();
|
||||
}
|
||||
|
||||
let mut mouse_listeners = mem::take(&mut self.window.rendered_frame.mouse_listeners);
|
||||
self.with_element_context(|cx| {
|
||||
@@ -1407,7 +1450,34 @@ impl<'a> WindowContext<'a> {
|
||||
.dispatch_tree
|
||||
.dispatch_path(node_id);
|
||||
|
||||
// Capture phase
|
||||
// Capture phase for global actions.
|
||||
self.propagate_event = true;
|
||||
if let Some(mut global_listeners) = self
|
||||
.global_action_listeners
|
||||
.remove(&action.as_any().type_id())
|
||||
{
|
||||
for listener in &global_listeners {
|
||||
listener(action.as_any(), DispatchPhase::Capture, self);
|
||||
if !self.propagate_event {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
global_listeners.extend(
|
||||
self.global_action_listeners
|
||||
.remove(&action.as_any().type_id())
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
|
||||
self.global_action_listeners
|
||||
.insert(action.as_any().type_id(), global_listeners);
|
||||
}
|
||||
|
||||
if !self.propagate_event {
|
||||
return;
|
||||
}
|
||||
|
||||
// Capture phase for window actions.
|
||||
for node_id in &dispatch_path {
|
||||
let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
|
||||
for DispatchActionListener {
|
||||
@@ -1427,7 +1497,8 @@ impl<'a> WindowContext<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bubble phase
|
||||
|
||||
// Bubble phase for window actions.
|
||||
for node_id in dispatch_path.iter().rev() {
|
||||
let node = self.window.rendered_frame.dispatch_tree.node(*node_id);
|
||||
for DispatchActionListener {
|
||||
@@ -1449,6 +1520,30 @@ impl<'a> WindowContext<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bubble phase for global actions.
|
||||
if let Some(mut global_listeners) = self
|
||||
.global_action_listeners
|
||||
.remove(&action.as_any().type_id())
|
||||
{
|
||||
for listener in global_listeners.iter().rev() {
|
||||
self.propagate_event = false; // Actions stop propagation by default during the bubble phase
|
||||
|
||||
listener(action.as_any(), DispatchPhase::Bubble, self);
|
||||
if !self.propagate_event {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
global_listeners.extend(
|
||||
self.global_action_listeners
|
||||
.remove(&action.as_any().type_id())
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
|
||||
self.global_action_listeners
|
||||
.insert(action.as_any().type_id(), global_listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/// Register the given handler to be invoked whenever the global of the given type
|
||||
|
||||
@@ -79,7 +79,7 @@ impl Hitbox {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Eq, PartialEq)]
|
||||
pub(crate) struct HitTest(SmallVec<[HitboxId; 8]>);
|
||||
|
||||
pub(crate) struct DeferredDraw {
|
||||
@@ -432,6 +432,7 @@ impl<'a> ElementContext<'a> {
|
||||
);
|
||||
self.window.next_frame.deferred_draws = deferred_draws;
|
||||
self.window.element_id_stack.clear();
|
||||
self.window.text_style_stack.clear();
|
||||
}
|
||||
|
||||
fn paint_deferred_draws(&mut self, deferred_draw_indices: &[usize]) {
|
||||
|
||||
@@ -12,7 +12,7 @@ use gpui::{
|
||||
AsyncWindowContext, ClickEvent, DismissEvent, Div, DragMoveEvent, EntityId, EventEmitter,
|
||||
ExternalPaths, FocusHandle, FocusableView, Model, MouseButton, NavigationDirection, Pixels,
|
||||
Point, PromptLevel, Render, ScrollHandle, Subscription, Task, View, ViewContext, VisualContext,
|
||||
WeakView, WindowContext,
|
||||
WeakFocusHandle, WeakView, WindowContext,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
@@ -166,7 +166,7 @@ pub struct Pane {
|
||||
zoomed: bool,
|
||||
was_focused: bool,
|
||||
active_item_index: usize,
|
||||
last_focused_view_by_item: HashMap<EntityId, FocusHandle>,
|
||||
last_focus_handle_by_item: HashMap<EntityId, WeakFocusHandle>,
|
||||
nav_history: NavHistory,
|
||||
toolbar: View<Toolbar>,
|
||||
new_item_menu: Option<View<ContextMenu>>,
|
||||
@@ -262,7 +262,7 @@ impl Pane {
|
||||
was_focused: false,
|
||||
zoomed: false,
|
||||
active_item_index: 0,
|
||||
last_focused_view_by_item: Default::default(),
|
||||
last_focus_handle_by_item: Default::default(),
|
||||
nav_history: NavHistory(Arc::new(Mutex::new(NavHistoryState {
|
||||
mode: NavigationMode::Normal,
|
||||
backward_stack: Default::default(),
|
||||
@@ -380,18 +380,20 @@ impl Pane {
|
||||
if self.focus_handle.is_focused(cx) {
|
||||
// Pane was focused directly. We need to either focus a view inside the active item,
|
||||
// or focus the active item itself
|
||||
if let Some(weak_last_focused_view) =
|
||||
self.last_focused_view_by_item.get(&active_item.item_id())
|
||||
if let Some(weak_last_focus_handle) =
|
||||
self.last_focus_handle_by_item.get(&active_item.item_id())
|
||||
{
|
||||
weak_last_focused_view.focus(cx);
|
||||
return;
|
||||
if let Some(focus_handle) = weak_last_focus_handle.upgrade() {
|
||||
focus_handle.focus(cx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
active_item.focus_handle(cx).focus(cx);
|
||||
} else if let Some(focused) = cx.focused() {
|
||||
if !self.context_menu_focused(cx) {
|
||||
self.last_focused_view_by_item
|
||||
.insert(active_item.item_id(), focused);
|
||||
self.last_focus_handle_by_item
|
||||
.insert(active_item.item_id(), focused.downgrade());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -941,8 +941,6 @@ mod element {
|
||||
let flexes = self.flexes.clone();
|
||||
let child_bounds = child.bounds;
|
||||
let axis = self.axis;
|
||||
let handle_hitbox = handle.hitbox.clone();
|
||||
let was_hovered = handle_hitbox.is_hovered(cx);
|
||||
move |e: &MouseMoveEvent, phase, cx| {
|
||||
let dragged_handle = dragged_handle.borrow();
|
||||
if phase.bubble() {
|
||||
@@ -957,8 +955,6 @@ mod element {
|
||||
workspace.clone(),
|
||||
cx,
|
||||
)
|
||||
} else if was_hovered != handle_hitbox.is_hovered(cx) {
|
||||
cx.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
description = "The fast, collaborative code editor."
|
||||
edition = "2021"
|
||||
name = "zed"
|
||||
version = "0.127.0"
|
||||
version = "0.127.2"
|
||||
publish = false
|
||||
license = "GPL-3.0-or-later"
|
||||
authors = ["Zed Team <hi@zed.dev>"]
|
||||
|
||||
@@ -1 +1 @@
|
||||
dev
|
||||
preview
|
||||
Reference in New Issue
Block a user