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
|
@ -130,6 +130,7 @@ actions!(
|
|||
Paste,
|
||||
Rename,
|
||||
Open,
|
||||
OpenPermanent,
|
||||
ToggleFocus,
|
||||
NewSearchInDirectory,
|
||||
]
|
||||
|
@ -156,6 +157,7 @@ pub enum Event {
|
|||
OpenedEntry {
|
||||
entry_id: ProjectEntryId,
|
||||
focus_opened_item: bool,
|
||||
allow_preview: bool,
|
||||
},
|
||||
SplitEntry {
|
||||
entry_id: ProjectEntryId,
|
||||
|
@ -262,6 +264,7 @@ impl ProjectPanel {
|
|||
&Event::OpenedEntry {
|
||||
entry_id,
|
||||
focus_opened_item,
|
||||
allow_preview,
|
||||
} => {
|
||||
if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) {
|
||||
if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
|
||||
|
@ -270,13 +273,14 @@ impl ProjectPanel {
|
|||
let entry_id = entry.id;
|
||||
|
||||
workspace
|
||||
.open_path(
|
||||
.open_path_preview(
|
||||
ProjectPath {
|
||||
worktree_id,
|
||||
path: file_path.clone(),
|
||||
},
|
||||
None,
|
||||
focus_opened_item,
|
||||
allow_preview,
|
||||
cx,
|
||||
)
|
||||
.detach_and_prompt_err("Failed to open file", cx, move |e, _| {
|
||||
|
@ -592,9 +596,22 @@ impl ProjectPanel {
|
|||
}
|
||||
|
||||
fn open(&mut self, _: &Open, cx: &mut ViewContext<Self>) {
|
||||
self.open_internal(true, false, cx);
|
||||
}
|
||||
|
||||
fn open_permanent(&mut self, _: &OpenPermanent, cx: &mut ViewContext<Self>) {
|
||||
self.open_internal(false, true, cx);
|
||||
}
|
||||
|
||||
fn open_internal(
|
||||
&mut self,
|
||||
allow_preview: bool,
|
||||
focus_opened_item: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
if let Some((_, entry)) = self.selected_entry(cx) {
|
||||
if entry.is_file() {
|
||||
self.open_entry(entry.id, true, cx);
|
||||
self.open_entry(entry.id, focus_opened_item, allow_preview, cx);
|
||||
} else {
|
||||
self.toggle_expanded(entry.id, cx);
|
||||
}
|
||||
|
@ -666,7 +683,7 @@ impl ProjectPanel {
|
|||
}
|
||||
this.update_visible_entries(None, cx);
|
||||
if is_new_entry && !is_dir {
|
||||
this.open_entry(new_entry.id, true, cx);
|
||||
this.open_entry(new_entry.id, true, false, cx);
|
||||
}
|
||||
cx.notify();
|
||||
})?;
|
||||
|
@ -686,11 +703,13 @@ impl ProjectPanel {
|
|||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
focus_opened_item: bool,
|
||||
allow_preview: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
cx.emit(Event::OpenedEntry {
|
||||
entry_id,
|
||||
focus_opened_item,
|
||||
allow_preview,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1461,7 +1480,13 @@ impl ProjectPanel {
|
|||
if event.down.modifiers.secondary() {
|
||||
this.split_entry(entry_id, cx);
|
||||
} else {
|
||||
this.open_entry(entry_id, event.up.click_count > 1, cx);
|
||||
let click_count = event.up.click_count;
|
||||
this.open_entry(
|
||||
entry_id,
|
||||
click_count > 1,
|
||||
click_count == 1,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1535,6 +1560,7 @@ impl Render for ProjectPanel {
|
|||
.on_action(cx.listener(Self::collapse_selected_entry))
|
||||
.on_action(cx.listener(Self::collapse_all_entries))
|
||||
.on_action(cx.listener(Self::open))
|
||||
.on_action(cx.listener(Self::open_permanent))
|
||||
.on_action(cx.listener(Self::confirm))
|
||||
.on_action(cx.listener(Self::cancel))
|
||||
.on_action(cx.listener(Self::copy_path))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue