diff --git a/assets/settings/default.json b/assets/settings/default.json index 8541c1fb749946de04caed2f185d4c3bd3d4c292..7824959df6e4e198d5401476096f19ac76f81a7e 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -291,6 +291,10 @@ "completion_menu_scrollbar": "never", // Whether to align detail text in code completions context menus left or right. "completion_detail_alignment": "left", + // How to display diffs in the editor. + // + // Default: stacked + "diff_view_style": "stacked", // Show method signatures in the editor, when inside parentheses. "auto_signature_help": false, // Whether to show the signature help after completion or a bracket pair inserted. diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index fc608a614c383d4cf937ee20c8bb540e6337e4fe..3ff0ee300f70f9546f6be0289d946f35c026095e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -59,8 +59,9 @@ pub use display_map::{ }; pub use edit_prediction_types::Direction; pub use editor_settings::{ - CompletionDetailAlignment, CurrentLineHighlight, DocumentColorsRenderMode, EditorSettings, - HideMouseMode, ScrollBeyondLastLine, ScrollbarAxes, SearchSettings, ShowMinimap, + CompletionDetailAlignment, CurrentLineHighlight, DiffViewStyle, DocumentColorsRenderMode, + EditorSettings, HideMouseMode, ScrollBeyondLastLine, ScrollbarAxes, SearchSettings, + ShowMinimap, }; pub use element::{ CursorLayout, EditorElement, HighlightedRange, HighlightedRangeLine, PointForPosition, @@ -77,7 +78,9 @@ pub use multi_buffer::{ MultiBufferOffset, MultiBufferOffsetUtf16, MultiBufferSnapshot, PathKey, RowInfo, ToOffset, ToPoint, }; -pub use split::{SplitDiffFeatureFlag, SplittableEditor, ToggleLockedCursors, ToggleSplitDiff}; +pub use split::{ + SplitDiff, SplitDiffFeatureFlag, SplittableEditor, ToggleLockedCursors, ToggleSplitDiff, +}; pub use split_editor_view::SplitEditorView; pub use text::Bias; diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 0b19edf0393163962d61ec815e6e5a1677732c91..47210a7561f4a3ebbddb994f00afcaff9158254d 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -4,10 +4,10 @@ use gpui::App; use language::CursorShape; use project::project_settings::DiagnosticSeverity; pub use settings::{ - CompletionDetailAlignment, CurrentLineHighlight, DelayMs, DisplayIn, DocumentColorsRenderMode, - DoubleClickInMultibuffer, GoToDefinitionFallback, HideMouseMode, MinimapThumb, - MinimapThumbBorder, MultiCursorModifier, ScrollBeyondLastLine, ScrollbarDiagnostics, - SeedQuerySetting, ShowMinimap, SnippetSortOrder, + CompletionDetailAlignment, CurrentLineHighlight, DelayMs, DiffViewStyle, DisplayIn, + DocumentColorsRenderMode, DoubleClickInMultibuffer, GoToDefinitionFallback, HideMouseMode, + MinimapThumb, MinimapThumbBorder, MultiCursorModifier, ScrollBeyondLastLine, + ScrollbarDiagnostics, SeedQuerySetting, ShowMinimap, SnippetSortOrder, }; use settings::{RegisterSetting, RelativeLineNumbers, Settings}; use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar}; @@ -59,6 +59,7 @@ pub struct EditorSettings { pub minimum_contrast_for_highlights: f32, pub completion_menu_scrollbar: ShowScrollbar, pub completion_detail_alignment: CompletionDetailAlignment, + pub diff_view_style: DiffViewStyle, } #[derive(Debug, Clone)] pub struct Jupyter { @@ -289,6 +290,7 @@ impl Settings for EditorSettings { minimum_contrast_for_highlights: editor.minimum_contrast_for_highlights.unwrap().0, completion_menu_scrollbar: editor.completion_menu_scrollbar.map(Into::into).unwrap(), completion_detail_alignment: editor.completion_detail_alignment.unwrap(), + diff_view_style: editor.diff_view_style.unwrap(), } } } diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rs index b9f601760e86fc511e7ee769ea00ab7a1a33a2ce..7d5a4ef15b8a52eadff21c56bfb0bcfdcbdc9614 100644 --- a/crates/editor/src/split.rs +++ b/crates/editor/src/split.rs @@ -15,6 +15,7 @@ use multi_buffer::{ }; use project::Project; use rope::Point; +use settings::DiffViewStyle; use text::{BufferId, OffsetRangeExt as _, Patch, ToPoint as _}; use ui::{ App, Context, InteractiveElement as _, IntoElement as _, ParentElement as _, Render, @@ -332,7 +333,7 @@ impl FeatureFlag for SplitDiffFeatureFlag { #[derive(Clone, Copy, PartialEq, Eq, Action, Default)] #[action(namespace = editor)] -struct SplitDiff; +pub struct SplitDiff; #[derive(Clone, Copy, PartialEq, Eq, Action, Default)] #[action(namespace = editor)] @@ -408,7 +409,8 @@ impl SplittableEditor { } } - pub fn new_unsplit( + pub fn new( + style: DiffViewStyle, rhs_multibuffer: Entity, project: Entity, workspace: Entity, @@ -441,17 +443,26 @@ impl SplittableEditor { }), ]; + let this = cx.weak_entity(); window.defer(cx, { let workspace = workspace.downgrade(); let rhs_editor = rhs_editor.downgrade(); move |window, cx| { workspace .update(cx, |workspace, cx| { - rhs_editor.update(cx, |editor, cx| { - editor.added_to_workspace(workspace, window, cx); - }) + rhs_editor + .update(cx, |editor, cx| { + editor.added_to_workspace(workspace, window, cx); + }) + .ok(); + }) + .ok(); + if style == DiffViewStyle::SideBySide { + this.update(cx, |this, cx| { + this.split(&Default::default(), window, cx); }) .ok(); + } } }); let split_state = cx.new(|cx| SplitEditorState::new(cx)); @@ -466,7 +477,7 @@ impl SplittableEditor { } } - fn split(&mut self, _: &SplitDiff, window: &mut Window, cx: &mut Context) { + pub fn split(&mut self, _: &SplitDiff, window: &mut Window, cx: &mut Context) { if !cx.has_flag::() { return; } @@ -2003,6 +2014,8 @@ impl LhsEditor { #[cfg(test)] mod tests { + use std::sync::Arc; + use buffer_diff::BufferDiff; use collections::HashSet; use fs::FakeFs; @@ -2014,8 +2027,7 @@ mod tests { use pretty_assertions::assert_eq; use project::Project; use rand::rngs::StdRng; - use settings::SettingsStore; - use std::sync::Arc; + use settings::{DiffViewStyle, SettingsStore}; use ui::{VisualContext as _, div, px}; use workspace::Workspace; @@ -2043,7 +2055,8 @@ mod tests { multibuffer }); let editor = cx.new_window_entity(|window, cx| { - let mut editor = SplittableEditor::new_unsplit( + let mut editor = SplittableEditor::new( + DiffViewStyle::Stacked, rhs_multibuffer.clone(), project.clone(), workspace, diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index 90eeb853f2e561bdcd7cb30402cbe80400ed74f7..ccda40c98a50c05907534e2f853f7678cb52fb9e 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -9,7 +9,7 @@ use anyhow::{Context as _, Result, anyhow}; use buffer_diff::{BufferDiff, DiffHunkSecondaryStatus}; use collections::{HashMap, HashSet}; use editor::{ - Addon, Editor, EditorEvent, SelectionEffects, SplittableEditor, + Addon, Editor, EditorEvent, EditorSettings, SelectionEffects, SplittableEditor, actions::{GoToHunk, GoToPreviousHunk, SendReviewToAgent}, multibuffer_context_lines, scroll::Autoscroll, @@ -300,7 +300,8 @@ impl ProjectDiff { }); let editor = cx.new(|cx| { - let diff_display_editor = SplittableEditor::new_unsplit( + let diff_display_editor = SplittableEditor::new( + EditorSettings::get_global(cx).diff_view_style, multibuffer.clone(), project.clone(), workspace.clone(), diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rs index b2e5be65c157e412cd5303e9ebe4cc001f97abe7..09e6bd7c6b3126c9a06bc65428ee0ac7c76633a8 100644 --- a/crates/settings/src/vscode_import.rs +++ b/crates/settings/src/vscode_import.rs @@ -307,6 +307,7 @@ impl VsCodeSettings { vertical_scroll_margin: self.read_f32("editor.cursorSurroundingLines"), completion_menu_scrollbar: None, completion_detail_alignment: None, + diff_view_style: None, } } diff --git a/crates/settings_content/src/editor.rs b/crates/settings_content/src/editor.rs index 51b80fc92d8da25384ba02e5feaeb7a983b4894d..2d3f358782e782833f5e5ff74bf2c7dc676b5455 100644 --- a/crates/settings_content/src/editor.rs +++ b/crates/settings_content/src/editor.rs @@ -221,6 +221,11 @@ pub struct EditorSettingsContent { /// /// Default: left pub completion_detail_alignment: Option, + + /// How to display diffs in the editor. + /// + /// Default: stacked + pub diff_view_style: Option, } #[derive( @@ -779,6 +784,34 @@ pub enum SnippetSortOrder { None, } +/// How to display diffs in the editor. +/// +/// Default: stacked +#[derive( + Copy, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + JsonSchema, + MergeFrom, + strum::Display, + strum::EnumIter, + strum::VariantArray, + strum::VariantNames, +)] +#[serde(rename_all = "snake_case")] +pub enum DiffViewStyle { + /// Show diffs in a single stacked view. + #[default] + Stacked, + /// Show diffs in a side-by-side split view. + SideBySide, +} + /// Default options for buffer and project search items. #[with_fallible_options] #[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]