Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/agent_ui/src/agent_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,6 @@ impl Item for AgentDiffPane {
self.editor.for_each_project_item(cx, f)
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn set_nav_history(
&mut self,
nav_history: ItemNavHistory,
Expand Down
4 changes: 0 additions & 4 deletions crates/collab_ui/src/channel_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,6 @@ impl Item for ChannelView {
}))
}

fn is_singleton(&self, _cx: &App) -> bool {
false
}

fn navigate(
&mut self,
data: Box<dyn Any>,
Expand Down
4 changes: 0 additions & 4 deletions crates/debugger_ui/src/stack_trace_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,6 @@ impl Item for StackTraceView {
self.editor.for_each_project_item(cx, f)
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn set_nav_history(
&mut self,
nav_history: ItemNavHistory,
Expand Down
4 changes: 0 additions & 4 deletions crates/diagnostics/src/buffer_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@ impl Item for BufferDiagnosticsEditor {
self.multibuffer.read(cx).is_dirty(cx)
}

fn is_singleton(&self, _cx: &App) -> bool {
false
}

fn navigate(
&mut self,
data: Box<dyn Any>,
Expand Down
4 changes: 0 additions & 4 deletions crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,6 @@ impl Item for ProjectDiagnosticsEditor {
self.editor.for_each_project_item(cx, f)
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn set_nav_history(
&mut self,
nav_history: ItemNavHistory,
Expand Down
14 changes: 7 additions & 7 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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
{
Expand Down
26 changes: 15 additions & 11 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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();

Expand All @@ -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!(
Expand Down Expand Up @@ -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();
}
Expand Down
46 changes: 24 additions & 22 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
||
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());

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);
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);
}
}
}
}

selected_buffer_ids
};
selected_buffer_ids
};

let mut selections = editor
.selections
Expand Down
9 changes: 6 additions & 3 deletions crates/editor/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions crates/git_ui/src/commit_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,6 @@ impl Item for CommitView {
.update(cx, |editor, cx| editor.deactivated(window, cx));
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn act_as_type<'a>(
&'a self,
type_id: TypeId,
Expand Down
4 changes: 0 additions & 4 deletions crates/git_ui/src/file_diff_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ impl Item for FileDiffView {
.update(cx, |editor, cx| editor.deactivated(window, cx));
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn act_as_type<'a>(
&'a self,
type_id: TypeId,
Expand Down
4 changes: 0 additions & 4 deletions crates/git_ui/src/project_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,6 @@ impl Item for ProjectDiff {
self.editor.for_each_project_item(cx, f)
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn set_nav_history(
&mut self,
nav_history: ItemNavHistory,
Expand Down
4 changes: 0 additions & 4 deletions crates/git_ui/src/text_diff_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,6 @@ impl Item for TextDiffView {
.update(cx, |editor, cx| editor.deactivated(window, cx));
}

fn is_singleton(&self, _: &App) -> bool {
false
}

fn act_as_type<'a>(
&'a self,
type_id: TypeId,
Expand Down
4 changes: 0 additions & 4 deletions crates/image_viewer/src/image_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ impl Item for ImageView {
f(self.image_item.entity_id(), self.image_item.read(cx))
}

fn is_singleton(&self, _cx: &App) -> bool {
true
}

fn tab_tooltip_text(&self, cx: &App) -> Option<SharedString> {
let abs_path = self.image_item.read(cx).abs_path(cx)?;
let file_path = abs_path.compact().to_string_lossy().into_owned();
Expand Down
4 changes: 2 additions & 2 deletions crates/onboarding/src/multibuffer_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use db::kvp::KEY_VALUE_STORE;
use gpui::{App, EntityId, EventEmitter, Subscription};
use ui::{IconButtonShape, Tooltip, prelude::*};
use workspace::item::{ItemEvent, ItemHandle};
use workspace::item::{ItemBufferKind, ItemEvent, ItemHandle};
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};

pub struct MultibufferHint {
Expand Down Expand Up @@ -79,7 +79,7 @@ impl MultibufferHint {
return ToolbarItemLocation::Hidden;
};

if active_pane_item.is_singleton(cx)
if active_pane_item.buffer_kind(cx) == ItemBufferKind::Singleton
|| active_pane_item.breadcrumbs(cx.theme(), cx).is_none()
|| !active_pane_item.can_save(cx)
{
Expand Down
4 changes: 0 additions & 4 deletions crates/repl/src/notebook/notebook_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,6 @@ impl Item for NotebookEditor {
f(self.notebook_item.entity_id(), self.notebook_item.read(cx))
}

fn is_singleton(&self, _cx: &App) -> bool {
true
}

fn tab_content(&self, params: TabContentParams, window: &Window, cx: &App) -> AnyElement {
Label::new(self.tab_content_text(params.detail.unwrap_or(0), cx))
.single_line()
Expand Down
Loading
Loading