mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 08:54:04 +00:00
Fix panel resize (#3707)
* [x] Reposition right dock handle * [x] Handle mouse events correctly for drag and drop * [x] Prevent drag events from passing through the resize handle to the draggable items in the panels (channels, files) * [x] Stop the editor gutter from stealing mouse move events
This commit is contained in:
commit
b797cd3e71
5 changed files with 568 additions and 553 deletions
|
@ -564,8 +564,6 @@ impl EditorElement {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
cx.stop_propagation();
|
||||
} else {
|
||||
update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx);
|
||||
hover_at(editor, None, cx);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -200,58 +200,56 @@ impl Element for UniformList {
|
|||
bounds.lower_right() - point(border.right + padding.right, border.bottom),
|
||||
);
|
||||
|
||||
cx.with_z_index(style.z_index.unwrap_or(0), |cx| {
|
||||
style.paint(bounds, cx, |cx| {
|
||||
if self.item_count > 0 {
|
||||
let content_height =
|
||||
item_height * self.item_count + padding.top + padding.bottom;
|
||||
let min_scroll_offset = padded_bounds.size.height - content_height;
|
||||
let is_scrolled = scroll_offset.y != px(0.);
|
||||
style.paint(bounds, cx, |cx| {
|
||||
if self.item_count > 0 {
|
||||
let content_height =
|
||||
item_height * self.item_count + padding.top + padding.bottom;
|
||||
let min_scroll_offset = padded_bounds.size.height - content_height;
|
||||
let is_scrolled = scroll_offset.y != px(0.);
|
||||
|
||||
if is_scrolled && scroll_offset.y < min_scroll_offset {
|
||||
shared_scroll_offset.borrow_mut().y = min_scroll_offset;
|
||||
scroll_offset.y = min_scroll_offset;
|
||||
}
|
||||
if is_scrolled && scroll_offset.y < min_scroll_offset {
|
||||
shared_scroll_offset.borrow_mut().y = min_scroll_offset;
|
||||
scroll_offset.y = min_scroll_offset;
|
||||
}
|
||||
|
||||
if let Some(scroll_handle) = self.scroll_handle.clone() {
|
||||
scroll_handle.0.borrow_mut().replace(ScrollHandleState {
|
||||
item_height,
|
||||
list_height: padded_bounds.size.height,
|
||||
scroll_offset: shared_scroll_offset,
|
||||
});
|
||||
}
|
||||
|
||||
let first_visible_element_ix =
|
||||
(-(scroll_offset.y + padding.top) / item_height).floor() as usize;
|
||||
let last_visible_element_ix =
|
||||
((-scroll_offset.y + padded_bounds.size.height) / item_height)
|
||||
.ceil() as usize;
|
||||
let visible_range = first_visible_element_ix
|
||||
..cmp::min(last_visible_element_ix, self.item_count);
|
||||
|
||||
let mut items = (self.render_items)(visible_range.clone(), cx);
|
||||
cx.with_z_index(1, |cx| {
|
||||
let content_mask = ContentMask { bounds };
|
||||
cx.with_content_mask(Some(content_mask), |cx| {
|
||||
for (item, ix) in items.iter_mut().zip(visible_range) {
|
||||
let item_origin = padded_bounds.origin
|
||||
+ point(
|
||||
px(0.),
|
||||
item_height * ix + scroll_offset.y + padding.top,
|
||||
);
|
||||
let available_space = size(
|
||||
AvailableSpace::Definite(padded_bounds.size.width),
|
||||
AvailableSpace::Definite(item_height),
|
||||
);
|
||||
item.draw(item_origin, available_space, cx);
|
||||
}
|
||||
});
|
||||
if let Some(scroll_handle) = self.scroll_handle.clone() {
|
||||
scroll_handle.0.borrow_mut().replace(ScrollHandleState {
|
||||
item_height,
|
||||
list_height: padded_bounds.size.height,
|
||||
scroll_offset: shared_scroll_offset,
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
let first_visible_element_ix =
|
||||
(-(scroll_offset.y + padding.top) / item_height).floor() as usize;
|
||||
let last_visible_element_ix =
|
||||
((-scroll_offset.y + padded_bounds.size.height) / item_height).ceil()
|
||||
as usize;
|
||||
let visible_range = first_visible_element_ix
|
||||
..cmp::min(last_visible_element_ix, self.item_count);
|
||||
|
||||
let mut items = (self.render_items)(visible_range.clone(), cx);
|
||||
cx.with_z_index(1, |cx| {
|
||||
let content_mask = ContentMask { bounds };
|
||||
cx.with_content_mask(Some(content_mask), |cx| {
|
||||
for (item, ix) in items.iter_mut().zip(visible_range) {
|
||||
let item_origin = padded_bounds.origin
|
||||
+ point(
|
||||
px(0.),
|
||||
item_height * ix + scroll_offset.y + padding.top,
|
||||
);
|
||||
let available_space = size(
|
||||
AvailableSpace::Definite(padded_bounds.size.width),
|
||||
AvailableSpace::Definite(item_height),
|
||||
);
|
||||
item.draw(item_origin, available_space, cx);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -946,16 +946,20 @@ impl<'a> WindowContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns true if the top-most opaque layer painted over this point was part of the
|
||||
/// same layer as the given stacking order.
|
||||
/// Returns true if there is no opaque layer containing the given point
|
||||
/// on top of the given level. Layers whose level is an extension of the
|
||||
/// level are not considered to be on top of the level.
|
||||
pub fn was_top_layer(&self, point: &Point<Pixels>, level: &StackingOrder) -> bool {
|
||||
for (stack, bounds) in self.window.rendered_frame.depth_map.iter() {
|
||||
if bounds.contains(point) {
|
||||
return level.starts_with(stack) || stack.starts_with(level);
|
||||
for (opaque_level, bounds) in self.window.rendered_frame.depth_map.iter() {
|
||||
if level >= opaque_level {
|
||||
break;
|
||||
}
|
||||
|
||||
if bounds.contains(point) && !opaque_level.starts_with(level) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
true
|
||||
}
|
||||
|
||||
pub fn was_top_layer_under_active_drag(
|
||||
|
@ -963,16 +967,19 @@ impl<'a> WindowContext<'a> {
|
|||
point: &Point<Pixels>,
|
||||
level: &StackingOrder,
|
||||
) -> bool {
|
||||
for (stack, bounds) in self.window.rendered_frame.depth_map.iter() {
|
||||
if stack.starts_with(&[ACTIVE_DRAG_Z_INDEX]) {
|
||||
for (opaque_level, bounds) in self.window.rendered_frame.depth_map.iter() {
|
||||
if level >= opaque_level {
|
||||
break;
|
||||
}
|
||||
if opaque_level.starts_with(&[ACTIVE_DRAG_Z_INDEX]) {
|
||||
continue;
|
||||
}
|
||||
if bounds.contains(point) {
|
||||
return level.starts_with(stack) || stack.starts_with(level);
|
||||
|
||||
if bounds.contains(point) && !opaque_level.starts_with(level) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
true
|
||||
}
|
||||
|
||||
/// Called during painting to get the current stacking order.
|
||||
|
|
|
@ -490,11 +490,13 @@ impl Render for Dock {
|
|||
let mut handle = div()
|
||||
.id("resize-handle")
|
||||
.on_drag(DraggedDock(position), |dock, cx| {
|
||||
cx.stop_propagation();
|
||||
cx.build_view(|_| dock.clone())
|
||||
})
|
||||
.on_click(cx.listener(|v, e: &ClickEvent, cx| {
|
||||
if e.down.button == MouseButton::Left && e.down.click_count == 2 {
|
||||
v.resize_active_panel(None, cx)
|
||||
v.resize_active_panel(None, cx);
|
||||
cx.stop_propagation();
|
||||
}
|
||||
}))
|
||||
.z_index(1);
|
||||
|
@ -525,8 +527,8 @@ impl Render for Dock {
|
|||
.absolute()
|
||||
.top(px(0.))
|
||||
.left(px(0.))
|
||||
.w_full()
|
||||
.h(HANDLE_SIZE)
|
||||
.h_full()
|
||||
.w(HANDLE_SIZE)
|
||||
.cursor_col_resize();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue