diff --git a/assets/settings/default.json b/assets/settings/default.json index ee50d43670ccf5da538404da34adc2616581d33a..5c950e2469698ec8ff655159a1514e2d22fa7045 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 c8658699ca61d4a3fa577a9c423b558df957abd8..26626f5ba16c8697d0d09ebfa23d861e0e0ffeb8 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::("", |style| style.visible()) .group_drag_over::("", |style| style.visible()) .group_drag_over::("", |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 0b7bc949f6ba09459c4206c6410b9760e09add2e..4552cda3a384c023f24e33811d3ea6c7470e3f15 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, + /// 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, } #[derive(Deserialize)]