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.

Improve drop targets (#10643)

Philipp Schaffrath2f892e352312
diff --git a/assets/settings/default.json b/assets/settings/default.json
index ee50d43670c..5c950e24696 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -69,6 +69,8 @@
"confirm_quit": false,
// Whether to restore last closed project when fresh Zed instance is opened.
"restore_on_startup": "last_workspace",
+ // Size of the drop target in the editor.
+ "drop_target_size": 0.2,
// Whether the cursor blinks in the editor.
"cursor_blink": true,
// Whether to pop the completions menu while typing in an editor without
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs
index c8658699ca6..26626f5ba16 100644
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@ -1721,16 +1721,35 @@ impl Pane {
return;
}
- let edge_width = cx.rem_size() * 8;
- let cursor = event.event.position;
- let direction = if cursor.x < event.bounds.left() + edge_width {
- Some(SplitDirection::Left)
- } else if cursor.x > event.bounds.right() - edge_width {
- Some(SplitDirection::Right)
- } else if cursor.y < event.bounds.top() + edge_width {
- Some(SplitDirection::Up)
- } else if cursor.y > event.bounds.bottom() - edge_width {
- Some(SplitDirection::Down)
+ let rect = event.bounds.size;
+
+ let size = event.bounds.size.width.min(event.bounds.size.height)
+ * WorkspaceSettings::get_global(cx).drop_target_size;
+
+ let relative_cursor = Point::new(
+ event.event.position.x - event.bounds.left(),
+ event.event.position.y - event.bounds.top(),
+ );
+
+ let direction = if relative_cursor.x < size
+ || relative_cursor.x > rect.width - size
+ || relative_cursor.y < size
+ || relative_cursor.y > rect.height - size
+ {
+ [
+ SplitDirection::Up,
+ SplitDirection::Right,
+ SplitDirection::Down,
+ SplitDirection::Left,
+ ]
+ .iter()
+ .min_by_key(|side| match side {
+ SplitDirection::Up => relative_cursor.y,
+ SplitDirection::Right => rect.width - relative_cursor.x,
+ SplitDirection::Down => rect.height - relative_cursor.y,
+ SplitDirection::Left => relative_cursor.x,
+ })
+ .cloned()
} else {
None
};
@@ -2013,10 +2032,7 @@ impl Render for Pane {
div()
.invisible()
.absolute()
- .bg(theme::color_alpha(
- cx.theme().colors().drop_target_background,
- 0.75,
- ))
+ .bg(cx.theme().colors().drop_target_background)
.group_drag_over::<DraggedTab>("", |style| style.visible())
.group_drag_over::<ProjectEntryId>("", |style| style.visible())
.group_drag_over::<ExternalPaths>("", |style| style.visible())
@@ -2032,17 +2048,22 @@ impl Render for Pane {
.on_drop(cx.listener(move |this, paths, cx| {
this.handle_external_paths_drop(paths, cx)
}))
- .map(|div| match self.drag_split_direction {
- None => div.top_0().left_0().right_0().bottom_0(),
- Some(SplitDirection::Up) => div.top_0().left_0().right_0().h_32(),
- Some(SplitDirection::Down) => {
- div.left_0().bottom_0().right_0().h_32()
- }
- Some(SplitDirection::Left) => {
- div.top_0().left_0().bottom_0().w_32()
- }
- Some(SplitDirection::Right) => {
- div.top_0().bottom_0().right_0().w_32()
+ .map(|div| {
+ let size = DefiniteLength::Fraction(0.5);
+ match self.drag_split_direction {
+ None => div.top_0().right_0().bottom_0().left_0(),
+ Some(SplitDirection::Up) => {
+ div.top_0().left_0().right_0().h(size)
+ }
+ Some(SplitDirection::Down) => {
+ div.left_0().bottom_0().right_0().h(size)
+ }
+ Some(SplitDirection::Left) => {
+ div.top_0().left_0().bottom_0().w(size)
+ }
+ Some(SplitDirection::Right) => {
+ div.top_0().bottom_0().right_0().w(size)
+ }
}
}),
)
diff --git a/crates/workspace/src/workspace_settings.rs b/crates/workspace/src/workspace_settings.rs
index 0b7bc949f6b..4552cda3a38 100644
--- a/crates/workspace/src/workspace_settings.rs
+++ b/crates/workspace/src/workspace_settings.rs
@@ -12,6 +12,7 @@ pub struct WorkspaceSettings {
pub show_call_status_icon: bool,
pub autosave: AutosaveSetting,
pub restore_on_startup: RestoreOnStartupBehaviour,
+ pub drop_target_size: f32,
}
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
@@ -50,6 +51,11 @@ pub struct WorkspaceSettingsContent {
/// Values: none, last_workspace
/// Default: last_workspace
pub restore_on_startup: Option<RestoreOnStartupBehaviour>,
+ /// The size of the workspace split drop targets on the outer edges.
+ /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
+ ///
+ /// Default: `0.2` (20% of the smaller dimension of the workspace)
+ pub drop_target_size: Option<f32>,
}
#[derive(Deserialize)]