mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-04 18:15:21 +00:00
WIP: Remove focus side effects from toggle dock commands
co-authored-by: max <max@zed.dev>
This commit is contained in:
parent
84f98f13c4
commit
1a23fe91b4
5 changed files with 18 additions and 70 deletions
|
@ -373,30 +373,9 @@
|
|||
"workspace::ActivatePane",
|
||||
8
|
||||
],
|
||||
"cmd-b": [
|
||||
"workspace::ToggleLeftDock",
|
||||
{ "focus": true }
|
||||
],
|
||||
"cmd-shift-b": [
|
||||
"workspace::ToggleLeftDock",
|
||||
{ "focus": false }
|
||||
],
|
||||
"cmd-r": [
|
||||
"workspace::ToggleRightDock",
|
||||
{ "focus": true }
|
||||
],
|
||||
"cmd-shift-r": [
|
||||
"workspace::ToggleRightDock",
|
||||
{ "focus": false }
|
||||
],
|
||||
"cmd-j": [
|
||||
"workspace::ToggleBottomDock",
|
||||
{ "focus": true }
|
||||
],
|
||||
"cmd-shift-j": [
|
||||
"workspace::ToggleBottomDock",
|
||||
{ "focus": false }
|
||||
],
|
||||
"cmd-b": "workspace::ToggleLeftDock",
|
||||
"cmd-r": "workspace::ToggleRightDock",
|
||||
"cmd-j": "workspace::ToggleBottomDock",
|
||||
"cmd-shift-f": "workspace::NewSearch",
|
||||
"cmd-k cmd-t": "theme_selector::Toggle",
|
||||
"cmd-k cmd-s": "zed::OpenKeymap",
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
|
||||
pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||
open_new(&app_state, cx, |workspace, cx| {
|
||||
workspace.toggle_dock(DockPosition::Left, false, cx);
|
||||
workspace.toggle_dock(DockPosition::Left, cx);
|
||||
let welcome_page = cx.add_view(|cx| WelcomePage::new(workspace, cx));
|
||||
workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
|
||||
cx.focus(&welcome_page);
|
||||
|
|
|
@ -103,24 +103,6 @@ pub trait Modal: View {
|
|||
#[derive(Clone, PartialEq)]
|
||||
pub struct RemoveWorktreeFromProject(pub WorktreeId);
|
||||
|
||||
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
||||
pub struct ToggleLeftDock {
|
||||
#[serde(default = "default_true")]
|
||||
pub focus: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
||||
pub struct ToggleBottomDock {
|
||||
#[serde(default = "default_true")]
|
||||
pub focus: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
||||
pub struct ToggleRightDock {
|
||||
#[serde(default = "default_true")]
|
||||
pub focus: bool,
|
||||
}
|
||||
|
||||
actions!(
|
||||
workspace,
|
||||
[
|
||||
|
@ -143,16 +125,14 @@ actions!(
|
|||
Restart,
|
||||
Welcome,
|
||||
ToggleZoom,
|
||||
ToggleLeftDock,
|
||||
ToggleRightDock,
|
||||
ToggleBottomDock,
|
||||
]
|
||||
);
|
||||
|
||||
actions!(zed, [OpenSettings]);
|
||||
|
||||
impl_actions!(
|
||||
workspace,
|
||||
[ToggleLeftDock, ToggleBottomDock, ToggleRightDock]
|
||||
);
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct OpenPaths {
|
||||
pub paths: Vec<PathBuf>,
|
||||
|
@ -268,14 +248,14 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
|||
cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| {
|
||||
workspace.activate_next_pane(cx)
|
||||
});
|
||||
cx.add_action(|workspace: &mut Workspace, action: &ToggleLeftDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Left, action.focus, cx);
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Left, cx);
|
||||
});
|
||||
cx.add_action(|workspace: &mut Workspace, action: &ToggleRightDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Right, action.focus, cx);
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Right, cx);
|
||||
});
|
||||
cx.add_action(|workspace: &mut Workspace, action: &ToggleBottomDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Bottom, action.focus, cx);
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Bottom, cx);
|
||||
});
|
||||
cx.add_action(Workspace::activate_pane_at_index);
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| {
|
||||
|
@ -1596,7 +1576,6 @@ impl Workspace {
|
|||
pub fn toggle_dock(
|
||||
&mut self,
|
||||
dock_side: DockPosition,
|
||||
focus: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let dock = match dock_side {
|
||||
|
@ -1608,12 +1587,6 @@ impl Workspace {
|
|||
let open = !dock.is_open();
|
||||
dock.set_open(open, cx);
|
||||
});
|
||||
|
||||
if dock.read(cx).is_open() && focus {
|
||||
cx.focus(dock);
|
||||
} else {
|
||||
cx.focus_self();
|
||||
}
|
||||
cx.notify();
|
||||
self.serialize_workspace(cx);
|
||||
}
|
||||
|
@ -3599,10 +3572,6 @@ fn parse_pixel_position_env_var(value: &str) -> Option<Vector2F> {
|
|||
Some(vec2f(width as f32, height as f32))
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -4187,7 +4156,7 @@ mod tests {
|
|||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
|
||||
let panel = workspace.update(cx, |workspace, cx| {
|
||||
let panel = cx.add_view(|_| TestPanel::new(DockPosition::Right));
|
||||
|
|
|
@ -91,15 +91,15 @@ pub fn menus() -> Vec<Menu<'static>> {
|
|||
MenuItem::separator(),
|
||||
MenuItem::action(
|
||||
"Toggle Left Dock",
|
||||
workspace::ToggleLeftDock { focus: false },
|
||||
workspace::ToggleLeftDock,
|
||||
),
|
||||
MenuItem::action(
|
||||
"Toggle Right Dock",
|
||||
workspace::ToggleRightDock { focus: false },
|
||||
workspace::ToggleRightDock,
|
||||
),
|
||||
MenuItem::action(
|
||||
"Toggle Bottom Dock",
|
||||
workspace::ToggleBottomDock { focus: false },
|
||||
workspace::ToggleBottomDock,
|
||||
),
|
||||
MenuItem::submenu(Menu {
|
||||
name: "Editor Layout",
|
||||
|
|
|
@ -354,7 +354,7 @@ pub fn initialize_workspace(
|
|||
.map_or(false, |entry| entry.is_dir())
|
||||
})
|
||||
{
|
||||
workspace.toggle_dock(project_panel_position, false, cx);
|
||||
workspace.toggle_dock(project_panel_position, cx);
|
||||
}
|
||||
|
||||
workspace.add_panel(terminal_panel, cx)
|
||||
|
|
Loading…
Reference in a new issue