Add preview tabs (#9125)
This PR implements the preview tabs feature from VSCode. More details and thanks for the head start of the implementation here #6782. Here is what I have observed from using the vscode implementation ([x] -> already implemented): - [x] Single click on project file opens tab as preview - [x] Double click on item in project panel opens tab as permanent - [x] Double click on the tab makes it permanent - [x] Navigating away from the tab makes the tab permanent and the new tab is shown as preview (e.g. GoToReference) - [x] Existing preview tab is reused when opening a new tab - [x] Dragging tab to the same/another panel makes the tab permanent - [x] Opening a tab from the file finder makes the tab permanent - [x] Editing a preview tab will make the tab permanent - [x] Using the space key in the project panel opens the tab as preview - [x] Handle navigation history correctly (restore a preview tab as preview as well) - [x] Restore preview tabs after restarting - [x] Support opening files from file finder in preview mode (vscode: "Enable Preview From Quick Open") I need to do some more testing of the vscode implementation, there might be other behaviors/workflows which im not aware of that open an item as preview/make them permanent. Showcase: https://github.com/zed-industries/zed/assets/53836821/9be16515-c740-4905-bea1-88871112ef86 TODOs - [x] Provide `enable_preview_tabs` setting - [x] Write some tests - [x] How should we handle this in collaboration mode (have not tested the behavior so far) - [x] Keyboard driven usage (probably need workspace commands) - [x] Register `TogglePreviewTab` only when setting enabled? - [x] Render preview tabs in tab switcher as italic - [x] Render preview tabs in image viewer as italic - [x] Should this be enabled by default (it is the default behavior in VSCode)? - [x] Docs Future improvements (out of scope for now): - Support preview mode for find all references and possibly other multibuffers (VSCode: "Enable Preview From Code Navigation") Release Notes: - Added preview tabs ([#4922](https://github.com/zed-industries/zed/issues/4922)). --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
edb1ea2433
commit
ea4419076e
29 changed files with 783 additions and 152 deletions
|
@ -246,6 +246,7 @@ impl SerializedPane {
|
|||
) -> Result<Vec<Option<Box<dyn ItemHandle>>>> {
|
||||
let mut item_tasks = Vec::new();
|
||||
let mut active_item_index = None;
|
||||
let mut preview_item_index = None;
|
||||
for (index, item) in self.children.iter().enumerate() {
|
||||
let project = project.clone();
|
||||
item_tasks.push(pane.update(cx, |_, cx| {
|
||||
|
@ -261,6 +262,9 @@ impl SerializedPane {
|
|||
if item.active {
|
||||
active_item_index = Some(index);
|
||||
}
|
||||
if item.preview {
|
||||
preview_item_index = Some(index);
|
||||
}
|
||||
}
|
||||
|
||||
let mut items = Vec::new();
|
||||
|
@ -281,6 +285,14 @@ impl SerializedPane {
|
|||
})?;
|
||||
}
|
||||
|
||||
if let Some(preview_item_index) = preview_item_index {
|
||||
pane.update(cx, |pane, cx| {
|
||||
if let Some(item) = pane.item_for_index(preview_item_index) {
|
||||
pane.set_preview_item_id(Some(item.item_id()), cx);
|
||||
}
|
||||
})?;
|
||||
}
|
||||
|
||||
anyhow::Ok(items)
|
||||
}
|
||||
}
|
||||
|
@ -294,14 +306,16 @@ pub struct SerializedItem {
|
|||
pub kind: Arc<str>,
|
||||
pub item_id: ItemId,
|
||||
pub active: bool,
|
||||
pub preview: bool,
|
||||
}
|
||||
|
||||
impl SerializedItem {
|
||||
pub fn new(kind: impl AsRef<str>, item_id: ItemId, active: bool) -> Self {
|
||||
pub fn new(kind: impl AsRef<str>, item_id: ItemId, active: bool, preview: bool) -> Self {
|
||||
Self {
|
||||
kind: Arc::from(kind.as_ref()),
|
||||
item_id,
|
||||
active,
|
||||
preview,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,20 +327,22 @@ impl Default for SerializedItem {
|
|||
kind: Arc::from("Terminal"),
|
||||
item_id: 100000,
|
||||
active: false,
|
||||
preview: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticColumnCount for SerializedItem {
|
||||
fn column_count() -> usize {
|
||||
3
|
||||
4
|
||||
}
|
||||
}
|
||||
impl Bind for &SerializedItem {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||
let next_index = statement.bind(&self.kind, start_index)?;
|
||||
let next_index = statement.bind(&self.item_id, next_index)?;
|
||||
statement.bind(&self.active, next_index)
|
||||
let next_index = statement.bind(&self.active, next_index)?;
|
||||
statement.bind(&self.preview, next_index)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,11 +351,13 @@ impl Column for SerializedItem {
|
|||
let (kind, next_index) = Arc::<str>::column(statement, start_index)?;
|
||||
let (item_id, next_index) = ItemId::column(statement, next_index)?;
|
||||
let (active, next_index) = bool::column(statement, next_index)?;
|
||||
let (preview, next_index) = bool::column(statement, next_index)?;
|
||||
Ok((
|
||||
SerializedItem {
|
||||
kind,
|
||||
item_id,
|
||||
active,
|
||||
preview,
|
||||
},
|
||||
next_index,
|
||||
))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue