editor: Refactor EditorMode::Full (#28546)

This PR lightly refactors the `EditorMode::Full` exposing two new
methods: `is_full` and `set_mode`.

Motivation is to expose fields that modify the behavior when the editor
is in `Full` mode. By using is `mode.is_full()` instead of
`EditorMode::Full` we can introduce new fields without breaking other
places in the code.

Release Notes:

- N/A

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
This commit is contained in:
Danilo Leal 2025-04-10 20:22:27 -03:00 committed by GitHub
parent 294a1b63c0
commit a2a3d1a4bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 75 additions and 61 deletions

View file

@ -874,7 +874,7 @@ mod tests {
let editor = workspace.update_in(&mut cx, |workspace, window, cx| { let editor = workspace.update_in(&mut cx, |workspace, window, cx| {
let editor = cx.new(|cx| { let editor = cx.new(|cx| {
Editor::new( Editor::new(
editor::EditorMode::Full, editor::EditorMode::full(),
multi_buffer::MultiBuffer::build_simple("", cx), multi_buffer::MultiBuffer::build_simple("", cx),
None, None,
window, window,

View file

@ -1172,7 +1172,7 @@ async fn test_send_breakpoints_when_editor_has_been_saved(
let (editor, cx) = cx.add_window_view(|window, cx| { let (editor, cx) = cx.add_window_view(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
MultiBuffer::build_from_buffer(buffer, cx), MultiBuffer::build_from_buffer(buffer, cx),
Some(project.clone()), Some(project.clone()),
window, window,
@ -1347,7 +1347,7 @@ async fn test_unsetting_breakpoints_on_clear_breakpoint_action(
let (first_editor, cx) = cx.add_window_view(|window, cx| { let (first_editor, cx) = cx.add_window_view(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
MultiBuffer::build_from_buffer(first, cx), MultiBuffer::build_from_buffer(first, cx),
Some(project.clone()), Some(project.clone()),
window, window,
@ -1357,7 +1357,7 @@ async fn test_unsetting_breakpoints_on_clear_breakpoint_action(
let (second_editor, cx) = cx.add_window_view(|window, cx| { let (second_editor, cx) = cx.add_window_view(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
MultiBuffer::build_from_buffer(second, cx), MultiBuffer::build_from_buffer(second, cx),
Some(project.clone()), Some(project.clone()),
window, window,

View file

@ -401,6 +401,16 @@ pub enum EditorMode {
Full, Full,
} }
impl EditorMode {
pub fn full() -> Self {
Self::Full
}
pub fn is_full(&self) -> bool {
matches!(self, Self::Full { .. })
}
}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum SoftWrap { pub enum SoftWrap {
/// Prefer not to wrap at all. /// Prefer not to wrap at all.
@ -1198,7 +1208,7 @@ impl Editor {
pub fn multi_line(window: &mut Window, cx: &mut Context<Self>) -> Self { pub fn multi_line(window: &mut Window, cx: &mut Context<Self>) -> Self {
let buffer = cx.new(|cx| Buffer::local("", cx)); let buffer = cx.new(|cx| Buffer::local("", cx));
let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx)); let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));
Self::new(EditorMode::Full, buffer, None, window, cx) Self::new(EditorMode::full(), buffer, None, window, cx)
} }
pub fn auto_width(window: &mut Window, cx: &mut Context<Self>) -> Self { pub fn auto_width(window: &mut Window, cx: &mut Context<Self>) -> Self {
@ -1232,7 +1242,7 @@ impl Editor {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx)); let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));
Self::new(EditorMode::Full, buffer, project, window, cx) Self::new(EditorMode::full(), buffer, project, window, cx)
} }
pub fn for_multibuffer( pub fn for_multibuffer(
@ -1241,7 +1251,7 @@ impl Editor {
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
Self::new(EditorMode::Full, buffer, project, window, cx) Self::new(EditorMode::full(), buffer, project, window, cx)
} }
pub fn clone(&self, window: &mut Window, cx: &mut Context<Self>) -> Self { pub fn clone(&self, window: &mut Window, cx: &mut Context<Self>) -> Self {
@ -1329,7 +1339,7 @@ impl Editor {
.then(|| language_settings::SoftWrap::None); .then(|| language_settings::SoftWrap::None);
let mut project_subscriptions = Vec::new(); let mut project_subscriptions = Vec::new();
if mode == EditorMode::Full { if mode.is_full() {
if let Some(project) = project.as_ref() { if let Some(project) = project.as_ref() {
project_subscriptions.push(cx.subscribe_in( project_subscriptions.push(cx.subscribe_in(
project, project,
@ -1417,7 +1427,7 @@ impl Editor {
}; };
let breakpoint_store = match (mode, project.as_ref()) { let breakpoint_store = match (mode, project.as_ref()) {
(EditorMode::Full, Some(project)) => Some(project.read(cx).breakpoint_store()), (EditorMode::Full { .. }, Some(project)) => Some(project.read(cx).breakpoint_store()),
_ => None, _ => None,
}; };
@ -1468,7 +1478,7 @@ impl Editor {
show_scrollbars: true, show_scrollbars: true,
mode, mode,
show_breadcrumbs: EditorSettings::get_global(cx).toolbar.breadcrumbs, show_breadcrumbs: EditorSettings::get_global(cx).toolbar.breadcrumbs,
show_gutter: mode == EditorMode::Full, show_gutter: mode.is_full(),
show_line_numbers: None, show_line_numbers: None,
use_relative_line_numbers: None, use_relative_line_numbers: None,
show_git_diff_gutter: None, show_git_diff_gutter: None,
@ -1510,7 +1520,7 @@ impl Editor {
collapse_matches: false, collapse_matches: false,
workspace: None, workspace: None,
input_enabled: true, input_enabled: true,
use_modal_editing: mode == EditorMode::Full, use_modal_editing: mode.is_full(),
read_only: false, read_only: false,
use_autoclose: true, use_autoclose: true,
use_auto_surround: true, use_auto_surround: true,
@ -1527,7 +1537,7 @@ impl Editor {
edit_prediction_preview: EditPredictionPreview::Inactive { edit_prediction_preview: EditPredictionPreview::Inactive {
released_too_fast: false, released_too_fast: false,
}, },
inline_diagnostics_enabled: mode == EditorMode::Full, inline_diagnostics_enabled: mode.is_full(),
inlay_hint_cache: InlayHintCache::new(inlay_hint_settings), inlay_hint_cache: InlayHintCache::new(inlay_hint_settings),
gutter_hovered: false, gutter_hovered: false,
@ -1635,7 +1645,7 @@ impl Editor {
this.scroll_manager.show_scrollbars(window, cx); this.scroll_manager.show_scrollbars(window, cx);
jsx_tag_auto_close::refresh_enabled_in_any_buffer(&mut this, &buffer, cx); jsx_tag_auto_close::refresh_enabled_in_any_buffer(&mut this, &buffer, cx);
if mode == EditorMode::Full { if mode.is_full() {
let should_auto_hide_scrollbars = cx.should_auto_hide_scrollbars(); let should_auto_hide_scrollbars = cx.should_auto_hide_scrollbars();
cx.set_global(ScrollbarAutoHide(should_auto_hide_scrollbars)); cx.set_global(ScrollbarAutoHide(should_auto_hide_scrollbars));
@ -1697,7 +1707,7 @@ impl Editor {
let mode = match self.mode { let mode = match self.mode {
EditorMode::SingleLine { .. } => "single_line", EditorMode::SingleLine { .. } => "single_line",
EditorMode::AutoHeight { .. } => "auto_height", EditorMode::AutoHeight { .. } => "auto_height",
EditorMode::Full => "full", EditorMode::Full { .. } => "full",
}; };
if EditorSettings::jupyter_enabled(cx) { if EditorSettings::jupyter_enabled(cx) {
@ -1984,6 +1994,10 @@ impl Editor {
self.mode self.mode
} }
pub fn set_mode(&mut self, mode: EditorMode) {
self.mode = mode;
}
pub fn collaboration_hub(&self) -> Option<&dyn CollaborationHub> { pub fn collaboration_hub(&self) -> Option<&dyn CollaborationHub> {
self.collaboration_hub.as_deref() self.collaboration_hub.as_deref()
} }
@ -3006,7 +3020,7 @@ impl Editor {
return; return;
} }
if self.mode == EditorMode::Full if self.mode.is_full()
&& self.change_selections(Some(Autoscroll::fit()), window, cx, |s| s.try_cancel()) && self.change_selections(Some(Autoscroll::fit()), window, cx, |s| s.try_cancel())
{ {
return; return;
@ -3049,7 +3063,7 @@ impl Editor {
return true; return true;
} }
if self.mode == EditorMode::Full && self.active_diagnostics.is_some() { if self.mode.is_full() && self.active_diagnostics.is_some() {
self.dismiss_diagnostics(cx); self.dismiss_diagnostics(cx);
return true; return true;
} }
@ -4037,7 +4051,7 @@ impl Editor {
} }
fn refresh_inlay_hints(&mut self, reason: InlayHintRefreshReason, cx: &mut Context<Self>) { fn refresh_inlay_hints(&mut self, reason: InlayHintRefreshReason, cx: &mut Context<Self>) {
if self.semantics_provider.is_none() || self.mode != EditorMode::Full { if self.semantics_provider.is_none() || !self.mode.is_full() {
return; return;
} }
@ -5545,7 +5559,7 @@ impl Editor {
buffer_position: language::Anchor, buffer_position: language::Anchor,
cx: &App, cx: &App,
) -> EditPredictionSettings { ) -> EditPredictionSettings {
if self.mode != EditorMode::Full if !self.mode.is_full()
|| !self.show_inline_completions_override.unwrap_or(true) || !self.show_inline_completions_override.unwrap_or(true)
|| self.inline_completions_disabled_in_scope(buffer, buffer_position, cx) || self.inline_completions_disabled_in_scope(buffer, buffer_position, cx)
{ {
@ -17258,7 +17272,7 @@ impl Editor {
let project_settings = ProjectSettings::get_global(cx); let project_settings = ProjectSettings::get_global(cx);
self.serialize_dirty_buffers = project_settings.session.restore_unsaved_buffers; self.serialize_dirty_buffers = project_settings.session.restore_unsaved_buffers;
if self.mode == EditorMode::Full { if self.mode.is_full() {
let show_inline_diagnostics = project_settings.diagnostics.inline.enabled; let show_inline_diagnostics = project_settings.diagnostics.inline.enabled;
let inline_blame_enabled = project_settings.git.inline_blame_enabled(); let inline_blame_enabled = project_settings.git.inline_blame_enabled();
if self.show_inline_diagnostics != show_inline_diagnostics { if self.show_inline_diagnostics != show_inline_diagnostics {
@ -19542,7 +19556,7 @@ impl Render for Editor {
line_height: relative(settings.buffer_line_height.value()), line_height: relative(settings.buffer_line_height.value()),
..Default::default() ..Default::default()
}, },
EditorMode::Full => TextStyle { EditorMode::Full { .. } => TextStyle {
color: cx.theme().colors().editor_foreground, color: cx.theme().colors().editor_foreground,
font_family: settings.buffer_font.family.clone(), font_family: settings.buffer_font.family.clone(),
font_features: settings.buffer_font.features.clone(), font_features: settings.buffer_font.features.clone(),
@ -19560,7 +19574,7 @@ impl Render for Editor {
let background = match self.mode { let background = match self.mode {
EditorMode::SingleLine { .. } => cx.theme().system().transparent, EditorMode::SingleLine { .. } => cx.theme().system().transparent,
EditorMode::AutoHeight { max_lines: _ } => cx.theme().system().transparent, EditorMode::AutoHeight { max_lines: _ } => cx.theme().system().transparent,
EditorMode::Full => cx.theme().colors().editor_background, EditorMode::Full { .. } => cx.theme().colors().editor_background,
}; };
EditorElement::new( EditorElement::new(

View file

@ -8053,7 +8053,7 @@ async fn test_multibuffer_format_during_save(cx: &mut TestAppContext) {
}); });
let multi_buffer_editor = cx.new_window_entity(|window, cx| { let multi_buffer_editor = cx.new_window_entity(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
multi_buffer, multi_buffer,
Some(project.clone()), Some(project.clone()),
window, window,
@ -14500,7 +14500,7 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) {
let cx = &mut VisualTestContext::from_window(*workspace.deref(), cx); let cx = &mut VisualTestContext::from_window(*workspace.deref(), cx);
let multi_buffer_editor = cx.new_window_entity(|window, cx| { let multi_buffer_editor = cx.new_window_entity(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
multi_buffer, multi_buffer,
Some(project.clone()), Some(project.clone()),
window, window,
@ -14959,7 +14959,7 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut TestAppContext) {
}); });
let editor = let editor =
cx.add_window(|window, cx| Editor::new(EditorMode::Full, multi_buffer, None, window, cx)); cx.add_window(|window, cx| Editor::new(EditorMode::full(), multi_buffer, None, window, cx));
editor editor
.update(cx, |editor, _window, cx| { .update(cx, |editor, _window, cx| {
for (buffer, diff_base) in [ for (buffer, diff_base) in [
@ -15070,7 +15070,7 @@ async fn test_expand_diff_hunk_at_excerpt_boundary(cx: &mut TestAppContext) {
}); });
let editor = let editor =
cx.add_window(|window, cx| Editor::new(EditorMode::Full, multi_buffer, None, window, cx)); cx.add_window(|window, cx| Editor::new(EditorMode::full(), multi_buffer, None, window, cx));
editor editor
.update(cx, |editor, _window, cx| { .update(cx, |editor, _window, cx| {
let diff = cx.new(|cx| BufferDiff::new_with_base_text(base, &buffer, cx)); let diff = cx.new(|cx| BufferDiff::new_with_base_text(base, &buffer, cx));
@ -16626,7 +16626,7 @@ async fn test_display_diff_hunks(cx: &mut TestAppContext) {
}); });
let editor = cx.add_window(|window, cx| { let editor = cx.add_window(|window, cx| {
Editor::new(EditorMode::Full, multibuffer, Some(project), window, cx) Editor::new(EditorMode::full(), multibuffer, Some(project), window, cx)
}); });
cx.run_until_parked(); cx.run_until_parked();
@ -17143,7 +17143,7 @@ async fn test_find_enclosing_node_with_task(cx: &mut TestAppContext) {
let editor = cx.new_window_entity(|window, cx| { let editor = cx.new_window_entity(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
multi_buffer, multi_buffer,
Some(project.clone()), Some(project.clone()),
window, window,
@ -17270,7 +17270,7 @@ async fn test_folding_buffers(cx: &mut TestAppContext) {
}); });
let multi_buffer_editor = cx.new_window_entity(|window, cx| { let multi_buffer_editor = cx.new_window_entity(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
multi_buffer.clone(), multi_buffer.clone(),
Some(project.clone()), Some(project.clone()),
window, window,
@ -17427,7 +17427,7 @@ async fn test_folding_buffers_with_one_excerpt(cx: &mut TestAppContext) {
let multi_buffer_editor = cx.new_window_entity(|window, cx| { let multi_buffer_editor = cx.new_window_entity(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
multi_buffer, multi_buffer,
Some(project.clone()), Some(project.clone()),
window, window,
@ -17545,7 +17545,7 @@ async fn test_folding_buffer_when_multibuffer_has_only_one_excerpt(cx: &mut Test
}); });
let multi_buffer_editor = cx.new_window_entity(|window, cx| { let multi_buffer_editor = cx.new_window_entity(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
multi_buffer, multi_buffer,
Some(project.clone()), Some(project.clone()),
window, window,
@ -17595,7 +17595,7 @@ async fn test_multi_buffer_navigation_with_folded_buffers(cx: &mut TestAppContex
], ],
cx, cx,
); );
let mut editor = Editor::new(EditorMode::Full, multi_buffer.clone(), None, window, cx); let mut editor = Editor::new(EditorMode::full(), multi_buffer.clone(), None, window, cx);
let buffer_ids = multi_buffer.read(cx).excerpt_buffer_ids(); let buffer_ids = multi_buffer.read(cx).excerpt_buffer_ids();
// fold all but the second buffer, so that we test navigating between two // fold all but the second buffer, so that we test navigating between two
@ -17907,7 +17907,7 @@ async fn assert_highlighted_edits(
) { ) {
let window = cx.add_window(|window, cx| { let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple(text, cx); let buffer = MultiBuffer::build_simple(text, cx);
Editor::new(EditorMode::Full, buffer, None, window, cx) Editor::new(EditorMode::full(), buffer, None, window, cx)
}); });
let cx = &mut VisualTestContext::from_window(*window, cx); let cx = &mut VisualTestContext::from_window(*window, cx);
@ -18065,7 +18065,7 @@ async fn test_breakpoint_toggling(cx: &mut TestAppContext) {
let (editor, cx) = cx.add_window_view(|window, cx| { let (editor, cx) = cx.add_window_view(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
MultiBuffer::build_from_buffer(buffer, cx), MultiBuffer::build_from_buffer(buffer, cx),
Some(project.clone()), Some(project.clone()),
window, window,
@ -18182,7 +18182,7 @@ async fn test_log_breakpoint_editing(cx: &mut TestAppContext) {
let (editor, cx) = cx.add_window_view(|window, cx| { let (editor, cx) = cx.add_window_view(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
MultiBuffer::build_from_buffer(buffer, cx), MultiBuffer::build_from_buffer(buffer, cx),
Some(project.clone()), Some(project.clone()),
window, window,
@ -18357,7 +18357,7 @@ async fn test_breakpoint_enabling_and_disabling(cx: &mut TestAppContext) {
let (editor, cx) = cx.add_window_view(|window, cx| { let (editor, cx) = cx.add_window_view(|window, cx| {
Editor::new( Editor::new(
EditorMode::Full, EditorMode::full(),
MultiBuffer::build_from_buffer(buffer, cx), MultiBuffer::build_from_buffer(buffer, cx),
Some(project.clone()), Some(project.clone()),
window, window,

View file

@ -1402,7 +1402,7 @@ impl EditorElement {
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> Option<EditorScrollbars> { ) -> Option<EditorScrollbars> {
if snapshot.mode != EditorMode::Full { if !snapshot.mode.is_full() {
return None; return None;
} }
@ -2371,7 +2371,7 @@ impl EditorElement {
cx: &mut App, cx: &mut App,
) -> Arc<HashMap<MultiBufferRow, LineNumberLayout>> { ) -> Arc<HashMap<MultiBufferRow, LineNumberLayout>> {
let include_line_numbers = snapshot.show_line_numbers.unwrap_or_else(|| { let include_line_numbers = snapshot.show_line_numbers.unwrap_or_else(|| {
EditorSettings::get_global(cx).gutter.line_numbers && snapshot.mode == EditorMode::Full EditorSettings::get_global(cx).gutter.line_numbers && snapshot.mode.is_full()
}); });
if !include_line_numbers { if !include_line_numbers {
return Arc::default(); return Arc::default();
@ -2477,7 +2477,7 @@ impl EditorElement {
cx: &mut App, cx: &mut App,
) -> Vec<Option<AnyElement>> { ) -> Vec<Option<AnyElement>> {
let include_fold_statuses = EditorSettings::get_global(cx).gutter.folds let include_fold_statuses = EditorSettings::get_global(cx).gutter.folds
&& snapshot.mode == EditorMode::Full && snapshot.mode.is_full()
&& self.editor.read(cx).is_singleton(cx); && self.editor.read(cx).is_singleton(cx);
if include_fold_statuses { if include_fold_statuses {
row_infos row_infos
@ -4176,7 +4176,7 @@ impl EditorElement {
self.style.background, self.style.background,
)); ));
if let EditorMode::Full = layout.mode { if let EditorMode::Full { .. } = layout.mode {
let mut active_rows = layout.active_rows.iter().peekable(); let mut active_rows = layout.active_rows.iter().peekable();
while let Some((start_row, contains_non_empty_selection)) = active_rows.next() { while let Some((start_row, contains_non_empty_selection)) = active_rows.next() {
let mut end_row = start_row.0; let mut end_row = start_row.0;
@ -6059,7 +6059,7 @@ impl LineWithInvisibles {
strikethrough: text_style.strikethrough, strikethrough: text_style.strikethrough,
}); });
if editor_mode == EditorMode::Full { if editor_mode.is_full() {
// Line wrap pads its contents with fake whitespaces, // Line wrap pads its contents with fake whitespaces,
// avoid printing them // avoid printing them
let is_soft_wrapped = is_row_soft_wrapped(row); let is_soft_wrapped = is_row_soft_wrapped(row);
@ -6414,7 +6414,7 @@ impl EditorElement {
/// This allows UI elements to scale based on the `buffer_font_size`. /// This allows UI elements to scale based on the `buffer_font_size`.
fn rem_size(&self, cx: &mut App) -> Option<Pixels> { fn rem_size(&self, cx: &mut App) -> Option<Pixels> {
match self.editor.read(cx).mode { match self.editor.read(cx).mode {
EditorMode::Full => { EditorMode::Full { .. } => {
let buffer_font_size = self.style.text.font_size; let buffer_font_size = self.style.text.font_size;
match buffer_font_size { match buffer_font_size {
AbsoluteLength::Pixels(pixels) => { AbsoluteLength::Pixels(pixels) => {
@ -6531,7 +6531,7 @@ impl Element for EditorElement {
}, },
) )
} }
EditorMode::Full => { EditorMode::Full { .. } => {
let mut style = Style::default(); let mut style = Style::default();
style.size.width = relative(1.).into(); style.size.width = relative(1.).into();
style.size.height = relative(1.).into(); style.size.height = relative(1.).into();
@ -8507,7 +8507,7 @@ mod tests {
init_test(cx, |_| {}); init_test(cx, |_| {});
let window = cx.add_window(|window, cx| { let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx); let buffer = MultiBuffer::build_simple(&sample_text(6, 6, 'a'), cx);
Editor::new(EditorMode::Full, buffer, None, window, cx) Editor::new(EditorMode::full(), buffer, None, window, cx)
}); });
let editor = window.root(cx).unwrap(); let editor = window.root(cx).unwrap();
@ -8608,7 +8608,7 @@ mod tests {
let window = cx.add_window(|window, cx| { let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple(&(sample_text(6, 6, 'a') + "\n"), cx); let buffer = MultiBuffer::build_simple(&(sample_text(6, 6, 'a') + "\n"), cx);
Editor::new(EditorMode::Full, buffer, None, window, cx) Editor::new(EditorMode::full(), buffer, None, window, cx)
}); });
let cx = &mut VisualTestContext::from_window(*window, cx); let cx = &mut VisualTestContext::from_window(*window, cx);
let editor = window.root(cx).unwrap(); let editor = window.root(cx).unwrap();
@ -8679,7 +8679,7 @@ mod tests {
let window = cx.add_window(|window, cx| { let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple("", cx); let buffer = MultiBuffer::build_simple("", cx);
Editor::new(EditorMode::Full, buffer, None, window, cx) Editor::new(EditorMode::full(), buffer, None, window, cx)
}); });
let cx = &mut VisualTestContext::from_window(*window, cx); let cx = &mut VisualTestContext::from_window(*window, cx);
let editor = window.root(cx).unwrap(); let editor = window.root(cx).unwrap();
@ -8765,7 +8765,7 @@ mod tests {
let actual_invisibles = collect_invisibles_from_new_editor( let actual_invisibles = collect_invisibles_from_new_editor(
cx, cx,
EditorMode::Full, EditorMode::full(),
input_text, input_text,
px(500.0), px(500.0),
show_line_numbers, show_line_numbers,
@ -8859,7 +8859,7 @@ mod tests {
let actual_invisibles = collect_invisibles_from_new_editor( let actual_invisibles = collect_invisibles_from_new_editor(
cx, cx,
EditorMode::Full, EditorMode::full(),
&input_text, &input_text,
px(editor_width), px(editor_width),
show_line_numbers, show_line_numbers,

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DebuggerEvaluateSelectedText, DisplayPoint, Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DebuggerEvaluateSelectedText, DisplayPoint,
DisplaySnapshot, Editor, EditorMode, FindAllReferences, GoToDeclaration, GoToDefinition, DisplaySnapshot, Editor, FindAllReferences, GoToDeclaration, GoToDefinition,
GoToImplementation, GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode, GoToImplementation, GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode,
ToDisplayPoint, ToggleCodeActions, ToDisplayPoint, ToggleCodeActions,
actions::{Format, FormatSelections}, actions::{Format, FormatSelections},
@ -123,7 +123,7 @@ pub fn deploy_context_menu(
} }
// Don't show context menu for inline editors // Don't show context menu for inline editors
if editor.mode() != EditorMode::Full { if !editor.mode().is_full() {
return; return;
} }

View file

@ -108,7 +108,7 @@ pub(crate) fn build_editor(
window: &mut Window, window: &mut Window,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> Editor { ) -> Editor {
Editor::new(EditorMode::Full, buffer, None, window, cx) Editor::new(EditorMode::full(), buffer, None, window, cx)
} }
pub(crate) fn build_editor_with_project( pub(crate) fn build_editor_with_project(
@ -117,5 +117,5 @@ pub(crate) fn build_editor_with_project(
window: &mut Window, window: &mut Window,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> Editor { ) -> Editor {
Editor::new(EditorMode::Full, buffer, Some(project), window, cx) Editor::new(EditorMode::full(), buffer, Some(project), window, cx)
} }

View file

@ -95,7 +95,7 @@ impl CursorPosition {
cursor_position.position = None; cursor_position.position = None;
cursor_position.context = None; cursor_position.context = None;
} }
editor::EditorMode::Full => { editor::EditorMode::Full { .. } => {
let mut last_selection = None::<Selection<Point>>; let mut last_selection = None::<Selection<Point>>;
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
if snapshot.excerpts().count() > 0 { if snapshot.excerpts().count() > 0 {

View file

@ -4,7 +4,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use editor::{Anchor, AnchorRangeExt, Editor, EditorMode, scroll::Autoscroll}; use editor::{Anchor, AnchorRangeExt, Editor, scroll::Autoscroll};
use fuzzy::StringMatch; use fuzzy::StringMatch;
use gpui::{ use gpui::{
App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, HighlightStyle, App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, HighlightStyle,
@ -87,7 +87,7 @@ impl Render for OutlineView {
impl OutlineView { impl OutlineView {
fn register(editor: &mut Editor, _: Option<&mut Window>, cx: &mut Context<Editor>) { fn register(editor: &mut Editor, _: Option<&mut Window>, cx: &mut Context<Editor>) {
if editor.mode() == EditorMode::Full { if editor.mode().is_full() {
let handle = cx.entity().downgrade(); let handle = cx.entity().downgrade();
editor editor
.register_action(move |action, window, cx| { .register_action(move |action, window, cx| {

View file

@ -18,7 +18,7 @@ use anyhow::Context as _;
use collections::{BTreeSet, HashMap, HashSet, hash_map}; use collections::{BTreeSet, HashMap, HashSet, hash_map};
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use editor::{ use editor::{
AnchorRangeExt, Bias, DisplayPoint, Editor, EditorEvent, EditorMode, EditorSettings, ExcerptId, AnchorRangeExt, Bias, DisplayPoint, Editor, EditorEvent, EditorSettings, ExcerptId,
ExcerptRange, MultiBufferSnapshot, RangeToAnchorExt, ShowScrollbar, ExcerptRange, MultiBufferSnapshot, RangeToAnchorExt, ShowScrollbar,
display_map::ToDisplayPoint, display_map::ToDisplayPoint,
items::{entry_git_aware_label_color, entry_label_color}, items::{entry_git_aware_label_color, entry_label_color},
@ -4725,7 +4725,7 @@ fn workspace_active_editor(
let active_item = workspace.active_item(cx)?; let active_item = workspace.active_item(cx)?;
let active_editor = active_item let active_editor = active_item
.act_as::<Editor>(cx) .act_as::<Editor>(cx)
.filter(|editor| editor.read(cx).mode() == EditorMode::Full)?; .filter(|editor| editor.read(cx).mode().is_full())?;
Some((active_item, active_editor)) Some((active_item, active_editor))
} }

View file

@ -1729,7 +1729,7 @@ async fn test_folded_multibuffer_excerpts(cx: &mut gpui::TestAppContext) {
], ],
cx, cx,
); );
let mut editor = Editor::new(EditorMode::Full, multi_buffer.clone(), None, window, cx); let mut editor = Editor::new(EditorMode::full(), multi_buffer.clone(), None, window, cx);
let buffer_ids = multi_buffer.read(cx).excerpt_buffer_ids(); let buffer_ids = multi_buffer.read(cx).excerpt_buffer_ids();
// fold all but the second buffer, so that we test navigating between two // fold all but the second buffer, so that we test navigating between two

View file

@ -22,7 +22,7 @@ mod visual;
use anyhow::Result; use anyhow::Result;
use collections::HashMap; use collections::HashMap;
use editor::{ use editor::{
Anchor, Bias, Editor, EditorEvent, EditorMode, EditorSettings, HideMouseCursorOrigin, ToPoint, Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, ToPoint,
movement::{self, FindRange}, movement::{self, FindRange},
}; };
use gpui::{ use gpui::{
@ -1127,7 +1127,7 @@ impl Vim {
let editor = editor.read(cx); let editor = editor.read(cx);
let editor_mode = editor.mode(); let editor_mode = editor.mode();
if editor_mode == EditorMode::Full if editor_mode.is_full()
&& !newest_selection_empty && !newest_selection_empty
&& self.mode == Mode::Normal && self.mode == Mode::Normal
// When following someone, don't switch vim mode. // When following someone, don't switch vim mode.

View file

@ -1,7 +1,7 @@
use client::{Client, UserStore}; use client::{Client, UserStore};
use collections::HashMap; use collections::HashMap;
use copilot::{Copilot, CopilotCompletionProvider}; use copilot::{Copilot, CopilotCompletionProvider};
use editor::{Editor, EditorMode}; use editor::Editor;
use gpui::{AnyWindowHandle, App, AppContext as _, Context, Entity, WeakEntity}; use gpui::{AnyWindowHandle, App, AppContext as _, Context, Entity, WeakEntity};
use language::language_settings::{EditPredictionProvider, all_language_settings}; use language::language_settings::{EditPredictionProvider, all_language_settings};
use settings::SettingsStore; use settings::SettingsStore;
@ -18,7 +18,7 @@ pub fn init(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut App) {
let client = client.clone(); let client = client.clone();
let user_store = user_store.clone(); let user_store = user_store.clone();
move |editor: &mut Editor, window, cx: &mut Context<Editor>| { move |editor: &mut Editor, window, cx: &mut Context<Editor>| {
if editor.mode() != EditorMode::Full { if !editor.mode().is_full() {
return; return;
} }