workspace: Add Close Multibuffers pane context menu entry (#39199)
Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -201,7 +201,7 @@ use workspace::{
|
||||
CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, OpenInTerminal, OpenTerminal,
|
||||
RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection, TabBarSettings, Toast,
|
||||
ViewId, Workspace, WorkspaceId, WorkspaceSettings,
|
||||
item::{ItemHandle, PreviewTabsSettings, SaveOptions},
|
||||
item::{ItemBufferKind, ItemHandle, PreviewTabsSettings, SaveOptions},
|
||||
notifications::{DetachAndPromptErr, NotificationId, NotifyTaskExt},
|
||||
searchable::SearchEvent,
|
||||
};
|
||||
@@ -7286,7 +7286,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn supports_minimap(&self, cx: &App) -> bool {
|
||||
!self.minimap_visibility.disabled() && self.is_singleton(cx)
|
||||
!self.minimap_visibility.disabled() && self.buffer_kind(cx) == ItemBufferKind::Singleton
|
||||
}
|
||||
|
||||
fn edit_predictions_enabled_in_buffer(
|
||||
@@ -17952,7 +17952,7 @@ impl Editor {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.is_singleton(cx) {
|
||||
if self.buffer_kind(cx) == ItemBufferKind::Singleton {
|
||||
let selection = self.selections.newest::<Point>(cx);
|
||||
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
@@ -18018,7 +18018,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn fold(&mut self, _: &actions::Fold, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.is_singleton(cx) {
|
||||
if self.buffer_kind(cx) == ItemBufferKind::Singleton {
|
||||
let mut to_fold = Vec::new();
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let selections = self.selections.all_adjusted(cx);
|
||||
@@ -18275,7 +18275,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn unfold_lines(&mut self, _: &UnfoldLines, _window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.is_singleton(cx) {
|
||||
if self.buffer_kind(cx) == ItemBufferKind::Singleton {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = &display_map.buffer_snapshot;
|
||||
let selections = self.selections.all::<Point>(cx);
|
||||
@@ -19056,7 +19056,7 @@ impl Editor {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<Entity<Self>> {
|
||||
(minimap_settings.minimap_enabled() && self.is_singleton(cx))
|
||||
(minimap_settings.minimap_enabled() && self.buffer_kind(cx) == ItemBufferKind::Singleton)
|
||||
.then(|| self.initialize_new_minimap(minimap_settings, window, cx))
|
||||
}
|
||||
|
||||
@@ -21834,7 +21834,7 @@ impl Editor {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>,
|
||||
) {
|
||||
if self.is_singleton(cx)
|
||||
if self.buffer_kind(cx) == ItemBufferKind::Singleton
|
||||
&& !self.mode.is_minimap()
|
||||
&& WorkspaceSettings::get(None, cx).restore_on_startup != RestoreOnStartupBehavior::None
|
||||
{
|
||||
|
||||
@@ -18798,8 +18798,9 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
let active_item = workspace
|
||||
.active_item(cx)
|
||||
.expect("should have an active item after adding the multi buffer");
|
||||
assert!(
|
||||
!active_item.is_singleton(cx),
|
||||
assert_eq!(
|
||||
active_item.buffer_kind(cx),
|
||||
ItemBufferKind::Multibuffer,
|
||||
"A multi buffer was expected to active after adding"
|
||||
);
|
||||
active_item.item_id()
|
||||
@@ -18827,8 +18828,9 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
first_item_id, multibuffer_item_id,
|
||||
"Should navigate into the 1st buffer and activate it"
|
||||
);
|
||||
assert!(
|
||||
active_item.is_singleton(cx),
|
||||
assert_eq!(
|
||||
active_item.buffer_kind(cx),
|
||||
ItemBufferKind::Singleton,
|
||||
"New active item should be a singleton buffer"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -18858,7 +18860,7 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
multibuffer_item_id,
|
||||
"Should navigate back to the multi buffer"
|
||||
);
|
||||
assert!(!active_item.is_singleton(cx));
|
||||
assert_eq!(active_item.buffer_kind(cx), ItemBufferKind::Multibuffer);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -18886,8 +18888,9 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
second_item_id, first_item_id,
|
||||
"Should navigate into the 2nd buffer and activate it"
|
||||
);
|
||||
assert!(
|
||||
active_item.is_singleton(cx),
|
||||
assert_eq!(
|
||||
active_item.buffer_kind(cx),
|
||||
ItemBufferKind::Singleton,
|
||||
"New active item should be a singleton buffer"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -18917,7 +18920,7 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
multibuffer_item_id,
|
||||
"Should navigate back from the 2nd buffer to the multi buffer"
|
||||
);
|
||||
assert!(!active_item.is_singleton(cx));
|
||||
assert_eq!(active_item.buffer_kind(cx), ItemBufferKind::Multibuffer);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -18943,8 +18946,9 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
);
|
||||
assert_ne!(third_item_id, first_item_id);
|
||||
assert_ne!(third_item_id, second_item_id);
|
||||
assert!(
|
||||
active_item.is_singleton(cx),
|
||||
assert_eq!(
|
||||
active_item.buffer_kind(cx),
|
||||
ItemBufferKind::Singleton,
|
||||
"New active item should be a singleton buffer"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -18972,7 +18976,7 @@ async fn test_multibuffer_in_navigation_history(cx: &mut TestAppContext) {
|
||||
multibuffer_item_id,
|
||||
"Should navigate back from the 3rd buffer to the multi buffer"
|
||||
);
|
||||
assert!(!active_item.is_singleton(cx));
|
||||
assert_eq!(active_item.buffer_kind(cx), ItemBufferKind::Multibuffer);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@ use util::post_inc;
|
||||
use util::{RangeExt, ResultExt, debug_panic};
|
||||
use workspace::{
|
||||
CollaboratorId, ItemSettings, OpenInTerminal, OpenTerminal, RevealInProjectPanel, Workspace,
|
||||
item::Item, notifications::NotifyTaskExt,
|
||||
item::{Item, ItemBufferKind},
|
||||
notifications::NotifyTaskExt,
|
||||
};
|
||||
|
||||
/// Determines what kinds of highlights should be applied to a lines background.
|
||||
@@ -376,7 +377,7 @@ impl EditorElement {
|
||||
register_action(editor, window, Editor::move_to_enclosing_bracket);
|
||||
register_action(editor, window, Editor::undo_selection);
|
||||
register_action(editor, window, Editor::redo_selection);
|
||||
if !editor.read(cx).is_singleton(cx) {
|
||||
if editor.read(cx).buffer_kind(cx) == ItemBufferKind::Multibuffer {
|
||||
register_action(editor, window, Editor::expand_excerpts);
|
||||
register_action(editor, window, Editor::expand_excerpts_up);
|
||||
register_action(editor, window, Editor::expand_excerpts_down);
|
||||
@@ -1765,7 +1766,7 @@ impl EditorElement {
|
||||
let show_scrollbars = match scrollbar_settings.show {
|
||||
ShowScrollbar::Auto => {
|
||||
let editor = self.editor.read(cx);
|
||||
let is_singleton = editor.is_singleton(cx);
|
||||
let is_singleton = editor.buffer_kind(cx) == ItemBufferKind::Singleton;
|
||||
// Git
|
||||
(is_singleton && scrollbar_settings.git_diff && snapshot.buffer_snapshot.has_diff_hunks())
|
||||
||
|
||||
@@ -3281,7 +3282,7 @@ impl EditorElement {
|
||||
) -> Vec<Option<AnyElement>> {
|
||||
let include_fold_statuses = EditorSettings::get_global(cx).gutter.folds
|
||||
&& snapshot.mode.is_full()
|
||||
&& self.editor.read(cx).is_singleton(cx);
|
||||
&& self.editor.read(cx).buffer_kind(cx) == ItemBufferKind::Singleton;
|
||||
if include_fold_statuses {
|
||||
row_infos
|
||||
.iter()
|
||||
@@ -5810,7 +5811,7 @@ impl EditorElement {
|
||||
}
|
||||
|
||||
fn paint_line_numbers(&mut self, layout: &mut EditorLayout, window: &mut Window, cx: &mut App) {
|
||||
let is_singleton = self.editor.read(cx).is_singleton(cx);
|
||||
let is_singleton = self.editor.read(cx).buffer_kind(cx) == ItemBufferKind::Singleton;
|
||||
|
||||
let line_height = layout.position_map.line_height;
|
||||
window.set_cursor_style(CursorStyle::Arrow, &layout.gutter_hitbox);
|
||||
@@ -6622,7 +6623,7 @@ impl EditorElement {
|
||||
cx: &mut App,
|
||||
) {
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
if !editor.is_singleton(cx)
|
||||
if editor.buffer_kind(cx) != ItemBufferKind::Singleton
|
||||
|| !editor
|
||||
.scrollbar_marker_state
|
||||
.should_refresh(scrollbar_layout.hitbox.size)
|
||||
@@ -8774,25 +8775,26 @@ impl Element for EditorElement {
|
||||
.map(|editor| {
|
||||
editor.update(cx, |editor, cx| {
|
||||
let all_selections = editor.selections.all::<Point>(cx);
|
||||
let selected_buffer_ids = if editor.is_singleton(cx) {
|
||||
Vec::new()
|
||||
} else {
|
||||
let mut selected_buffer_ids =
|
||||
Vec::with_capacity(all_selections.len());
|
||||
let selected_buffer_ids =
|
||||
if editor.buffer_kind(cx) == ItemBufferKind::Singleton {
|
||||
Vec::new()
|
||||
} else {
|
||||
let mut selected_buffer_ids =
|
||||
Vec::with_capacity(all_selections.len());
|
||||
|
||||
for selection in all_selections {
|
||||
for buffer_id in snapshot
|
||||
.buffer_snapshot
|
||||
.buffer_ids_for_range(selection.range())
|
||||
{
|
||||
if selected_buffer_ids.last() != Some(&buffer_id) {
|
||||
selected_buffer_ids.push(buffer_id);
|
||||
for selection in all_selections {
|
||||
for buffer_id in snapshot
|
||||
.buffer_snapshot
|
||||
.buffer_ids_for_range(selection.range())
|
||||
{
|
||||
if selected_buffer_ids.last() != Some(&buffer_id) {
|
||||
selected_buffer_ids.push(buffer_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selected_buffer_ids
|
||||
};
|
||||
selected_buffer_ids
|
||||
};
|
||||
|
||||
let mut selections = editor
|
||||
.selections
|
||||
|
||||
@@ -43,7 +43,7 @@ use util::{ResultExt, TryFutureExt, paths::PathExt};
|
||||
use workspace::{
|
||||
CollaboratorId, ItemId, ItemNavHistory, ToolbarItemLocation, ViewId, Workspace, WorkspaceId,
|
||||
invalid_buffer_view::InvalidBufferView,
|
||||
item::{FollowableItem, Item, ItemEvent, ProjectItem, SaveOptions},
|
||||
item::{FollowableItem, Item, ItemBufferKind, ItemEvent, ProjectItem, SaveOptions},
|
||||
searchable::{
|
||||
Direction, FilteredSearchRange, SearchEvent, SearchableItem, SearchableItemHandle,
|
||||
},
|
||||
@@ -747,8 +747,11 @@ impl Item for Editor {
|
||||
.for_each_buffer(|buffer| f(buffer.entity_id(), buffer.read(cx)));
|
||||
}
|
||||
|
||||
fn is_singleton(&self, cx: &App) -> bool {
|
||||
self.buffer.read(cx).is_singleton()
|
||||
fn buffer_kind(&self, cx: &App) -> ItemBufferKind {
|
||||
match self.buffer.read(cx).is_singleton() {
|
||||
true => ItemBufferKind::Singleton,
|
||||
false => ItemBufferKind::Multibuffer,
|
||||
}
|
||||
}
|
||||
|
||||
fn can_save_as(&self, cx: &App) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user