Add centered layout support (#9754)

This PR implements the Centered Layout feature (#4685):
- Added the `toggle centered layout` action.
- The centered layout mode only takes effect when there's a single
central pane.
- The state of the centered layout toggle is saved / restored between
Zed restarts.
- The paddings are controlled by the `centered_layout` setting:

```json
"centered_layout": {
  "left_padding": 0.2,
  "right_padding": 0.2
}
```

This allows us to support both the VSCode-style (equal paddings) and
IntelliJ-style (only left padding in Zen mode).

Release Notes:

- Added support for Centered Layout
([#4685](https://github.com/zed-industries/zed/pull/9754)).


https://github.com/zed-industries/zed/assets/2101250/2d5b2a16-c248-48b5-9e8c-6f1219619398

Related Issues:

- Part of #4382
This commit is contained in:
Andrew Lygin 2024-04-16 22:12:41 +03:00 committed by GitHub
parent 52591905fb
commit 4eb1e65fbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 146 additions and 17 deletions

View file

@ -138,6 +138,7 @@ define_connection! {
// window_height: Option<f32>, // WindowBounds::Fixed RectF height
// display: Option<Uuid>, // Display id
// fullscreen: Option<bool>, // Is the window fullscreen?
// centered_layout: Option<bool>, // Is the Centered Layout mode activated?
// )
//
// pane_groups(
@ -280,6 +281,10 @@ define_connection! {
sql!(
ALTER TABLE workspaces ADD COLUMN fullscreen INTEGER; //bool
),
// Add centered_layout field to workspace
sql!(
ALTER TABLE workspaces ADD COLUMN centered_layout INTEGER; //bool
),
// Add preview field to items
sql!(
ALTER TABLE items ADD COLUMN preview INTEGER; //bool
@ -299,12 +304,13 @@ impl WorkspaceDb {
// Note that we re-assign the workspace_id here in case it's empty
// and we've grabbed the most recent workspace
let (workspace_id, workspace_location, bounds, display, fullscreen, docks): (
let (workspace_id, workspace_location, bounds, display, fullscreen, centered_layout, docks): (
WorkspaceId,
WorkspaceLocation,
Option<SerializedWindowsBounds>,
Option<Uuid>,
Option<bool>,
Option<bool>,
DockStructure,
) = self
.select_row_bound(sql! {
@ -318,6 +324,7 @@ impl WorkspaceDb {
window_height,
display,
fullscreen,
centered_layout,
left_dock_visible,
left_dock_active_panel,
left_dock_zoom,
@ -344,6 +351,7 @@ impl WorkspaceDb {
.log_err()?,
bounds: bounds.map(|bounds| bounds.0),
fullscreen: fullscreen.unwrap_or(false),
centered_layout: centered_layout.unwrap_or(false),
display,
docks,
})
@ -678,6 +686,14 @@ impl WorkspaceDb {
WHERE workspace_id = ?1
}
}
query! {
pub(crate) async fn set_centered_layout(workspace_id: WorkspaceId, centered_layout: bool) -> Result<()> {
UPDATE workspaces
SET centered_layout = ?2
WHERE workspace_id = ?1
}
}
}
#[cfg(test)]
@ -764,6 +780,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
};
let workspace_2 = SerializedWorkspace {
@ -774,6 +791,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
};
db.save_workspace(workspace_1.clone()).await;
@ -873,6 +891,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
};
db.save_workspace(workspace.clone()).await;
@ -902,6 +921,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
};
let mut workspace_2 = SerializedWorkspace {
@ -912,6 +932,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
};
db.save_workspace(workspace_1.clone()).await;
@ -949,6 +970,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
};
db.save_workspace(workspace_3.clone()).await;
@ -983,6 +1005,7 @@ mod tests {
display: Default::default(),
docks: Default::default(),
fullscreen: false,
centered_layout: false,
}
}