diff --git a/crates/agent_ui/src/active_thread.rs b/crates/agent_ui/src/active_thread.rs index 7ee3b7158b..5f9dfc7ab2 100644 --- a/crates/agent_ui/src/active_thread.rs +++ b/crates/agent_ui/src/active_thread.rs @@ -19,7 +19,7 @@ use audio::{Audio, Sound}; use collections::{HashMap, HashSet}; use editor::actions::{MoveUp, Paste}; use editor::scroll::Autoscroll; -use editor::{Editor, EditorElement, EditorEvent, EditorStyle, MultiBuffer, SelectionEffects}; +use editor::{Editor, EditorElement, EditorEvent, EditorStyle, MultiBuffer}; use gpui::{ AbsoluteLength, Animation, AnimationExt, AnyElement, App, ClickEvent, ClipboardEntry, ClipboardItem, DefiniteLength, EdgesRefinement, Empty, Entity, EventEmitter, Focusable, Hsla, @@ -689,12 +689,9 @@ fn open_markdown_link( }) .context("Could not find matching symbol")?; - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| s.select_anchor_ranges([symbol_range.start..symbol_range.start]), - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_anchor_ranges([symbol_range.start..symbol_range.start]) + }); anyhow::Ok(()) }) }) @@ -711,15 +708,10 @@ fn open_markdown_link( .downcast::() .context("Item is not an editor")?; active_editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| { - s.select_ranges([Point::new(line_range.start as u32, 0) - ..Point::new(line_range.start as u32, 0)]) - }, - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_ranges([Point::new(line_range.start as u32, 0) + ..Point::new(line_range.start as u32, 0)]) + }); anyhow::Ok(()) }) }) diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rs index 1a0f3ff27d..b8e67512e2 100644 --- a/crates/agent_ui/src/agent_diff.rs +++ b/crates/agent_ui/src/agent_diff.rs @@ -5,8 +5,7 @@ use anyhow::Result; use buffer_diff::DiffHunkStatus; use collections::{HashMap, HashSet}; use editor::{ - Direction, Editor, EditorEvent, EditorSettings, MultiBuffer, MultiBufferSnapshot, - SelectionEffects, ToPoint, + Direction, Editor, EditorEvent, EditorSettings, MultiBuffer, MultiBufferSnapshot, ToPoint, actions::{GoToHunk, GoToPreviousHunk}, scroll::Autoscroll, }; @@ -172,9 +171,15 @@ impl AgentDiffPane { if let Some(first_hunk) = first_hunk { let first_hunk_start = first_hunk.multi_buffer_range().start; - editor.change_selections(Default::default(), window, cx, |selections| { - selections.select_anchor_ranges([first_hunk_start..first_hunk_start]); - }) + editor.change_selections( + Some(Autoscroll::fit()), + window, + cx, + |selections| { + selections + .select_anchor_ranges([first_hunk_start..first_hunk_start]); + }, + ) } } @@ -237,7 +242,7 @@ impl AgentDiffPane { if let Some(first_hunk) = first_hunk { let first_hunk_start = first_hunk.multi_buffer_range().start; - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { selections.select_anchor_ranges([first_hunk_start..first_hunk_start]); }) } @@ -411,7 +416,7 @@ fn update_editor_selection( }; if let Some(target_hunk) = target_hunk { - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { let next_hunk_start = target_hunk.multi_buffer_range().start; selections.select_anchor_ranges([next_hunk_start..next_hunk_start]); }) @@ -1539,7 +1544,7 @@ impl AgentDiff { let first_hunk_start = first_hunk.multi_buffer_range().start; editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), + Some(Autoscroll::center()), window, cx, |selections| { @@ -1863,7 +1868,7 @@ mod tests { // Rejecting a hunk also moves the cursor to the next hunk, possibly cycling if it's at the end. editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) }); }); @@ -2119,7 +2124,7 @@ mod tests { // Rejecting a hunk also moves the cursor to the next hunk, possibly cycling if it's at the end. editor1.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) }); }); diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs index c9c173a68b..6e77e764a5 100644 --- a/crates/agent_ui/src/inline_assistant.rs +++ b/crates/agent_ui/src/inline_assistant.rs @@ -18,7 +18,6 @@ use agent_settings::AgentSettings; use anyhow::{Context as _, Result}; use client::telemetry::Telemetry; use collections::{HashMap, HashSet, VecDeque, hash_map}; -use editor::SelectionEffects; use editor::{ Anchor, AnchorRangeExt, CodeActionProvider, Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset as _, ToPoint, @@ -1160,7 +1159,7 @@ impl InlineAssistant { let position = assist.range.start; editor.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_anchor_ranges([position..position]) }); diff --git a/crates/agent_ui/src/text_thread_editor.rs b/crates/agent_ui/src/text_thread_editor.rs index dcb239a46d..645bc451fc 100644 --- a/crates/agent_ui/src/text_thread_editor.rs +++ b/crates/agent_ui/src/text_thread_editor.rs @@ -21,6 +21,7 @@ use editor::{ BlockPlacement, BlockProperties, BlockStyle, Crease, CreaseMetadata, CustomBlockId, FoldId, RenderBlock, ToDisplayPoint, }, + scroll::Autoscroll, }; use editor::{FoldPlaceholder, display_map::CreaseId}; use fs::Fs; @@ -388,7 +389,7 @@ impl TextThreadEditor { cursor..cursor }; self.editor.update(cx, |editor, cx| { - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { selections.select_ranges([new_selection]) }); }); @@ -448,7 +449,8 @@ impl TextThreadEditor { if let Some(command) = self.slash_commands.command(name, cx) { self.editor.update(cx, |editor, cx| { editor.transact(window, cx, |editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| s.try_cancel()); + editor + .change_selections(Some(Autoscroll::fit()), window, cx, |s| s.try_cancel()); let snapshot = editor.buffer().read(cx).snapshot(cx); let newest_cursor = editor.selections.newest::(cx).head(); if newest_cursor.column > 0 @@ -1581,7 +1583,7 @@ impl TextThreadEditor { self.editor.update(cx, |editor, cx| { editor.transact(window, cx, |this, window, cx| { - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(selections); }); this.insert("", window, cx); @@ -3139,7 +3141,6 @@ pub fn make_lsp_adapter_delegate( #[cfg(test)] mod tests { use super::*; - use editor::SelectionEffects; use fs::FakeFs; use gpui::{App, TestAppContext, VisualTestContext}; use indoc::indoc; @@ -3365,9 +3366,7 @@ mod tests { ) { context_editor.update_in(cx, |context_editor, window, cx| { context_editor.editor.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([range]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([range])); }); context_editor.copy(&Default::default(), window, cx); diff --git a/crates/assistant_tools/src/edit_file_tool.rs b/crates/assistant_tools/src/edit_file_tool.rs index 8c7728b4b7..fcf8285692 100644 --- a/crates/assistant_tools/src/edit_file_tool.rs +++ b/crates/assistant_tools/src/edit_file_tool.rs @@ -10,7 +10,7 @@ use assistant_tool::{ ToolUseStatus, }; use buffer_diff::{BufferDiff, BufferDiffSnapshot}; -use editor::{Editor, EditorMode, MinimapVisibility, MultiBuffer, PathKey}; +use editor::{Editor, EditorMode, MinimapVisibility, MultiBuffer, PathKey, scroll::Autoscroll}; use futures::StreamExt; use gpui::{ Animation, AnimationExt, AnyWindowHandle, App, AppContext, AsyncApp, Entity, Task, @@ -823,7 +823,7 @@ impl ToolCard for EditFileToolCard { let first_hunk_start = first_hunk.multi_buffer_range().start; editor.change_selections( - Default::default(), + Some(Autoscroll::fit()), window, cx, |selections| { diff --git a/crates/collab/src/tests/channel_buffer_tests.rs b/crates/collab/src/tests/channel_buffer_tests.rs index 0b331ff1e6..4069f61f90 100644 --- a/crates/collab/src/tests/channel_buffer_tests.rs +++ b/crates/collab/src/tests/channel_buffer_tests.rs @@ -178,7 +178,7 @@ async fn test_channel_notes_participant_indices( channel_view_a.update_in(cx_a, |notes, window, cx| { notes.editor.update(cx, |editor, cx| { editor.insert("a", window, cx); - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![0..1]); }); }); @@ -188,7 +188,7 @@ async fn test_channel_notes_participant_indices( notes.editor.update(cx, |editor, cx| { editor.move_down(&Default::default(), window, cx); editor.insert("b", window, cx); - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![1..2]); }); }); @@ -198,7 +198,7 @@ async fn test_channel_notes_participant_indices( notes.editor.update(cx, |editor, cx| { editor.move_down(&Default::default(), window, cx); editor.insert("c", window, cx); - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![2..3]); }); }); @@ -273,12 +273,12 @@ async fn test_channel_notes_participant_indices( .unwrap(); editor_a.update_in(cx_a, |editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![0..1]); }); }); editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![2..3]); }); }); diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index 2cc3ca76d1..7a51caefa1 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -4,7 +4,7 @@ use crate::{ }; use call::ActiveCall; use editor::{ - DocumentColorsRenderMode, Editor, EditorSettings, RowInfo, SelectionEffects, + DocumentColorsRenderMode, Editor, EditorSettings, RowInfo, actions::{ ConfirmCodeAction, ConfirmCompletion, ConfirmRename, ContextMenuFirst, ExpandMacroRecursively, MoveToEnd, Redo, Rename, SelectAll, ToggleCodeActions, Undo, @@ -348,9 +348,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu // Type a completion trigger character as the guest. editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input(".", window, cx); }); cx_b.focus(&editor_b); @@ -463,9 +461,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu // Now we do a second completion, this time to ensure that documentation/snippets are // resolved editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([46..46]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([46..46])); editor.handle_input("; a", window, cx); editor.handle_input(".", window, cx); }); @@ -617,7 +613,7 @@ async fn test_collaborating_with_code_actions( // Move cursor to a location that contains code actions. editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 31)..Point::new(1, 31)]) }); }); @@ -821,9 +817,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T // Move cursor to a location that can be renamed. let prepare_rename = editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([7..7]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([7..7])); editor.rename(&Rename, window, cx).unwrap() }); @@ -869,9 +863,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T editor.cancel(&editor::actions::Cancel, window, cx); }); let prepare_rename = editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([7..8]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([7..8])); editor.rename(&Rename, window, cx).unwrap() }); @@ -1372,9 +1364,7 @@ async fn test_on_input_format_from_host_to_guest( // Type a on type formatting trigger character as the guest. cx_a.focus(&editor_a); editor_a.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input(">", window, cx); }); @@ -1470,9 +1460,7 @@ async fn test_on_input_format_from_guest_to_host( // Type a on type formatting trigger character as the guest. cx_b.focus(&editor_b); editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input(":", window, cx); }); @@ -1709,9 +1697,7 @@ async fn test_mutual_editor_inlay_hint_cache_update( let after_client_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1; editor_b.update_in(cx_b, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13].clone()) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13].clone())); editor.handle_input(":", window, cx); }); cx_b.focus(&editor_b); @@ -1732,9 +1718,7 @@ async fn test_mutual_editor_inlay_hint_cache_update( let after_host_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1; editor_a.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input("a change to increment both buffers' versions", window, cx); }); cx_a.focus(&editor_a); @@ -2137,9 +2121,7 @@ async fn test_lsp_document_color(cx_a: &mut TestAppContext, cx_b: &mut TestAppCo }); editor_a.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13].clone()) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13].clone())); editor.handle_input(":", window, cx); }); color_request_handle.next().await.unwrap(); diff --git a/crates/collab/src/tests/following_tests.rs b/crates/collab/src/tests/following_tests.rs index a77112213f..99f9b33505 100644 --- a/crates/collab/src/tests/following_tests.rs +++ b/crates/collab/src/tests/following_tests.rs @@ -6,7 +6,7 @@ use collab_ui::{ channel_view::ChannelView, notifications::project_shared_notification::ProjectSharedNotification, }; -use editor::{Editor, MultiBuffer, PathKey, SelectionEffects}; +use editor::{Editor, MultiBuffer, PathKey}; use gpui::{ AppContext as _, BackgroundExecutor, BorrowAppContext, Entity, SharedString, TestAppContext, VisualContext, VisualTestContext, point, @@ -376,9 +376,7 @@ async fn test_basic_following( // Changes to client A's editor are reflected on client B. editor_a1.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([1..1, 2..2]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([1..1, 2..2])); }); executor.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); executor.run_until_parked(); @@ -395,9 +393,7 @@ async fn test_basic_following( editor_b1.update(cx_b, |editor, cx| assert_eq!(editor.text(cx), "TWO")); editor_a1.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([3..3]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([3..3])); editor.set_scroll_position(point(0., 100.), window, cx); }); executor.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); @@ -1651,9 +1647,7 @@ async fn test_following_stops_on_unshare(cx_a: &mut TestAppContext, cx_b: &mut T // b should follow a to position 1 editor_a.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([1..1]) - }) + editor.change_selections(None, window, cx, |s| s.select_ranges([1..1])) }); cx_a.executor() .advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); @@ -1673,9 +1667,7 @@ async fn test_following_stops_on_unshare(cx_a: &mut TestAppContext, cx_b: &mut T // b should not follow a to position 2 editor_a.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([2..2]) - }) + editor.change_selections(None, window, cx, |s| s.select_ranges([2..2])) }); cx_a.executor() .advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); @@ -1976,7 +1968,7 @@ async fn test_following_to_channel_notes_without_a_shared_project( assert_eq!(notes.channel(cx).unwrap().name, "channel-1"); notes.editor.update(cx, |editor, cx| { editor.insert("Hello from A.", window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![3..4]); }); }); @@ -2117,7 +2109,7 @@ async fn test_following_after_replacement(cx_a: &mut TestAppContext, cx_b: &mut workspace.add_item_to_center(Box::new(editor.clone()) as _, window, cx) }); editor.update_in(cx_a, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::row_range(4..4)]); }) }); diff --git a/crates/collab_ui/src/channel_view.rs b/crates/collab_ui/src/channel_view.rs index c872f99aa1..80cc504308 100644 --- a/crates/collab_ui/src/channel_view.rs +++ b/crates/collab_ui/src/channel_view.rs @@ -7,8 +7,8 @@ use client::{ }; use collections::HashMap; use editor::{ - CollaborationHub, DisplayPoint, Editor, EditorEvent, SelectionEffects, - display_map::ToDisplayPoint, scroll::Autoscroll, + CollaborationHub, DisplayPoint, Editor, EditorEvent, display_map::ToDisplayPoint, + scroll::Autoscroll, }; use gpui::{ AnyView, App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render, @@ -260,16 +260,9 @@ impl ChannelView { .find(|item| &Channel::slug(&item.text).to_lowercase() == &position) { self.editor.update(cx, |editor, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::focused()), - window, - cx, - |s| { - s.replace_cursors_with(|map| { - vec![item.range.start.to_display_point(map)] - }) - }, - ) + editor.change_selections(Some(Autoscroll::focused()), window, cx, |s| { + s.replace_cursors_with(|map| vec![item.range.start.to_display_point(map)]) + }) }); return; } diff --git a/crates/copilot/src/copilot_completion_provider.rs b/crates/copilot/src/copilot_completion_provider.rs index 8dc04622f9..ff63617875 100644 --- a/crates/copilot/src/copilot_completion_provider.rs +++ b/crates/copilot/src/copilot_completion_provider.rs @@ -264,8 +264,7 @@ fn common_prefix, T2: Iterator>(a: T1, b: mod tests { use super::*; use editor::{ - Editor, ExcerptRange, MultiBuffer, SelectionEffects, - test::editor_lsp_test_context::EditorLspTestContext, + Editor, ExcerptRange, MultiBuffer, test::editor_lsp_test_context::EditorLspTestContext, }; use fs::FakeFs; use futures::StreamExt; @@ -479,7 +478,7 @@ mod tests { // Reset the editor to verify how suggestions behave when tabbing on leading indentation. cx.update_editor(|editor, window, cx| { editor.set_text("fn foo() {\n \n}", window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 2)..Point::new(1, 2)]) }); }); @@ -768,7 +767,7 @@ mod tests { ); _ = editor.update(cx, |editor, window, cx| { // Ensure copilot suggestions are shown for the first excerpt. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 5)..Point::new(1, 5)]) }); editor.next_edit_prediction(&Default::default(), window, cx); @@ -794,7 +793,7 @@ mod tests { ); _ = editor.update(cx, |editor, window, cx| { // Move to another excerpt, ensuring the suggestion gets cleared. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(4, 5)..Point::new(4, 5)]) }); assert!(!editor.has_active_inline_completion()); @@ -1020,7 +1019,7 @@ mod tests { ); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges([Point::new(0, 0)..Point::new(0, 0)]) }); editor.refresh_inline_completion(true, false, window, cx); @@ -1030,7 +1029,7 @@ mod tests { assert!(copilot_requests.try_next().is_err()); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(5, 0)..Point::new(5, 0)]) }); editor.refresh_inline_completion(true, false, window, cx); diff --git a/crates/debugger_ui/src/stack_trace_view.rs b/crates/debugger_ui/src/stack_trace_view.rs index aef053df4a..675522e999 100644 --- a/crates/debugger_ui/src/stack_trace_view.rs +++ b/crates/debugger_ui/src/stack_trace_view.rs @@ -4,7 +4,7 @@ use collections::HashMap; use dap::StackFrameId; use editor::{ Anchor, Bias, DebugStackFrameLine, Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer, - RowHighlightOptions, SelectionEffects, ToPoint, scroll::Autoscroll, + RowHighlightOptions, ToPoint, scroll::Autoscroll, }; use gpui::{ AnyView, App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString, @@ -99,11 +99,10 @@ impl StackTraceView { if frame_anchor.excerpt_id != editor.selections.newest_anchor().head().excerpt_id { - let effects = SelectionEffects::scroll( - Autoscroll::center().for_anchor(frame_anchor), - ); + let auto_scroll = + Some(Autoscroll::center().for_anchor(frame_anchor)); - editor.change_selections(effects, window, cx, |selections| { + editor.change_selections(auto_scroll, window, cx, |selections| { let selection_id = selections.new_selection_id(); let selection = Selection { diff --git a/crates/diagnostics/src/diagnostic_renderer.rs b/crates/diagnostics/src/diagnostic_renderer.rs index 77bb249733..9524f97ff1 100644 --- a/crates/diagnostics/src/diagnostic_renderer.rs +++ b/crates/diagnostics/src/diagnostic_renderer.rs @@ -4,6 +4,7 @@ use editor::{ Anchor, Editor, EditorSnapshot, ToOffset, display_map::{BlockContext, BlockPlacement, BlockProperties, BlockStyle}, hover_popover::diagnostics_markdown_style, + scroll::Autoscroll, }; use gpui::{AppContext, Entity, Focusable, WeakEntity}; use language::{BufferId, Diagnostic, DiagnosticEntry}; @@ -310,7 +311,7 @@ impl DiagnosticBlock { let range = range.start.to_offset(&snapshot)..range.end.to_offset(&snapshot); editor.unfold_ranges(&[range.start..range.end], true, false, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([range.start..range.start]); }); window.focus(&editor.focus_handle(cx)); diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 8b49c53624..4f66a5a883 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -12,6 +12,7 @@ use diagnostic_renderer::DiagnosticBlock; use editor::{ DEFAULT_MULTIBUFFER_CONTEXT, Editor, EditorEvent, ExcerptRange, MultiBuffer, PathKey, display_map::{BlockPlacement, BlockProperties, BlockStyle, CustomBlockId}, + scroll::Autoscroll, }; use futures::future::join_all; use gpui::{ @@ -625,7 +626,7 @@ impl ProjectDiagnosticsEditor { if let Some(anchor_range) = anchor_ranges.first() { let range_to_select = anchor_range.start..anchor_range.start; this.editor.update(cx, |editor, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges([range_to_select]); }) }); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 48ceaec18b..376aa60ba4 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1262,19 +1262,6 @@ impl Default for SelectionHistoryMode { } #[derive(Debug)] -/// SelectionEffects controls the side-effects of updating the selection. -/// -/// The default behaviour does "what you mostly want": -/// - it pushes to the nav history if the cursor moved by >10 lines -/// - it re-triggers completion requests -/// - it scrolls to fit -/// -/// You might want to modify these behaviours. For example when doing a "jump" -/// like go to definition, we always want to add to nav history; but when scrolling -/// in vim mode we never do. -/// -/// Similarly, you might want to disable scrolling if you don't want the viewport to -/// move. pub struct SelectionEffects { nav_history: Option, completions: bool, @@ -3177,11 +3164,12 @@ impl Editor { /// effects of selection change occur at the end of the transaction. pub fn change_selections( &mut self, - effects: SelectionEffects, + effects: impl Into, window: &mut Window, cx: &mut Context, change: impl FnOnce(&mut MutableSelectionsCollection<'_>) -> R, ) -> R { + let effects = effects.into(); if let Some(state) = &mut self.deferred_selection_effects_state { state.effects.scroll = effects.scroll.or(state.effects.scroll); state.effects.completions = effects.completions; @@ -3461,13 +3449,8 @@ impl Editor { }; let selections_count = self.selections.count(); - let effects = if auto_scroll { - SelectionEffects::default() - } else { - SelectionEffects::no_scroll() - }; - self.change_selections(effects, window, cx, |s| { + self.change_selections(auto_scroll.then(Autoscroll::newest), window, cx, |s| { if let Some(point_to_delete) = point_to_delete { s.delete(point_to_delete); @@ -3505,18 +3488,13 @@ impl Editor { .buffer_snapshot .anchor_before(position.to_point(&display_map)); - self.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), - window, - cx, - |s| { - s.clear_disjoint(); - s.set_pending_anchor_range( - pointer_position..pointer_position, - SelectMode::Character, - ); - }, - ); + self.change_selections(Some(Autoscroll::newest()), window, cx, |s| { + s.clear_disjoint(); + s.set_pending_anchor_range( + pointer_position..pointer_position, + SelectMode::Character, + ); + }); }; let tail = self.selections.newest::(cx).tail(); @@ -3631,7 +3609,7 @@ impl Editor { pending.reversed = false; } - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.set_pending(pending, mode); }); } else { @@ -3647,7 +3625,7 @@ impl Editor { self.columnar_selection_state.take(); if self.selections.pending_anchor().is_some() { let selections = self.selections.all::(cx); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select(selections); s.clear_pending(); }); @@ -3721,7 +3699,7 @@ impl Editor { _ => selection_ranges, }; - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_ranges(ranges); }); cx.notify(); @@ -3761,7 +3739,7 @@ impl Editor { } if self.mode.is_full() - && self.change_selections(Default::default(), window, cx, |s| s.try_cancel()) + && self.change_selections(Some(Autoscroll::fit()), window, cx, |s| s.try_cancel()) { return; } @@ -4564,7 +4542,9 @@ impl Editor { }) .collect(); - this.change_selections(Default::default(), window, cx, |s| s.select(new_selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(new_selections) + }); this.refresh_inline_completion(true, false, window, cx); }); } @@ -4593,7 +4573,7 @@ impl Editor { self.transact(window, cx, |editor, window, cx| { editor.edit(edits, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let mut index = 0; s.move_cursors_with(|map, _, _| { let row = rows[index]; @@ -4655,7 +4635,7 @@ impl Editor { self.transact(window, cx, |editor, window, cx| { editor.edit(edits, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let mut index = 0; s.move_cursors_with(|map, _, _| { let row = rows[index]; @@ -4732,7 +4712,7 @@ impl Editor { anchors }); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchors(selection_anchors); }); @@ -4876,7 +4856,7 @@ impl Editor { .collect(); drop(buffer); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + self.change_selections(None, window, cx, |selections| { selections.select(new_selections) }); } @@ -7180,7 +7160,7 @@ impl Editor { self.unfold_ranges(&[target..target], true, false, cx); // Note that this is also done in vim's handler of the Tab action. self.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), + Some(Autoscroll::newest()), window, cx, |selections| { @@ -7225,7 +7205,7 @@ impl Editor { buffer.edit(edits.iter().cloned(), None, cx) }); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_anchor_ranges([last_edit_end..last_edit_end]); }); @@ -7272,14 +7252,9 @@ impl Editor { match &active_inline_completion.completion { InlineCompletion::Move { target, .. } => { let target = *target; - self.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), - window, - cx, - |selections| { - selections.select_anchor_ranges([target..target]); - }, - ); + self.change_selections(Some(Autoscroll::newest()), window, cx, |selections| { + selections.select_anchor_ranges([target..target]); + }); } InlineCompletion::Edit { edits, .. } => { // Find an insertion that starts at the cursor position. @@ -7880,12 +7855,9 @@ impl Editor { this.entry("Run to cursor", None, move |window, cx| { weak_editor .update(cx, |editor, cx| { - editor.change_selections( - SelectionEffects::no_scroll(), - window, - cx, - |s| s.select_ranges([Point::new(row, 0)..Point::new(row, 0)]), - ); + editor.change_selections(None, window, cx, |s| { + s.select_ranges([Point::new(row, 0)..Point::new(row, 0)]) + }); }) .ok(); @@ -9426,7 +9398,7 @@ impl Editor { .collect::>() }); if let Some(tabstop) = tabstops.first() { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { // Reverse order so that the first range is the newest created selection. // Completions will use it and autoscroll will prioritize it. s.select_ranges(tabstop.ranges.iter().rev().cloned()); @@ -9544,7 +9516,7 @@ impl Editor { } } if let Some(current_ranges) = snippet.ranges.get(snippet.active_index) { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { // Reverse order so that the first range is the newest created selection. // Completions will use it and autoscroll will prioritize it. s.select_ranges(current_ranges.iter().rev().cloned()) @@ -9634,7 +9606,9 @@ impl Editor { } } - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); this.insert("", window, cx); let empty_str: Arc = Arc::from(""); for (buffer, edits) in linked_ranges { @@ -9670,7 +9644,7 @@ impl Editor { pub fn delete(&mut self, _: &Delete, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); self.transact(window, cx, |this, window, cx| { - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if selection.is_empty() { let cursor = movement::right(map, selection.head()); @@ -9813,7 +9787,9 @@ impl Editor { self.transact(window, cx, |this, window, cx| { this.buffer.update(cx, |b, cx| b.edit(edits, None, cx)); - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); this.refresh_inline_completion(true, false, window, cx); }); } @@ -9846,7 +9822,9 @@ impl Editor { self.transact(window, cx, |this, window, cx| { this.buffer.update(cx, |b, cx| b.edit(edits, None, cx)); - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); }); } @@ -9999,7 +9977,9 @@ impl Editor { ); }); let selections = this.selections.all::(cx); - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); }); } @@ -10024,7 +10004,9 @@ impl Editor { buffer.autoindent_ranges(selections, cx); }); let selections = this.selections.all::(cx); - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); }); } @@ -10105,7 +10087,7 @@ impl Editor { }) .collect(); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(new_selections); }); }); @@ -10171,7 +10153,7 @@ impl Editor { } } - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges(cursor_positions) }); }); @@ -10758,7 +10740,7 @@ impl Editor { }) .collect(); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(new_selections); }); @@ -11109,7 +11091,7 @@ impl Editor { buffer.edit(edits, None, cx); }); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(new_selections); }); @@ -11145,7 +11127,7 @@ impl Editor { this.buffer.update(cx, |buffer, cx| { buffer.edit(edits, None, cx); }); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges([last_edit_start..last_edit_end]); }); }); @@ -11347,7 +11329,7 @@ impl Editor { } }); this.fold_creases(refold_creases, true, window, cx); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(new_selections); }) }); @@ -11448,7 +11430,9 @@ impl Editor { } }); this.fold_creases(refold_creases, true, window, cx); - this.change_selections(Default::default(), window, cx, |s| s.select(new_selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(new_selections) + }); }); } @@ -11456,7 +11440,7 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); let text_layout_details = &self.text_layout_details(window); self.transact(window, cx, |this, window, cx| { - let edits = this.change_selections(Default::default(), window, cx, |s| { + let edits = this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let mut edits: Vec<(Range, String)> = Default::default(); s.move_with(|display_map, selection| { if !selection.is_empty() { @@ -11504,7 +11488,7 @@ impl Editor { this.buffer .update(cx, |buffer, cx| buffer.edit(edits, None, cx)); let selections = this.selections.all::(cx); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(selections); }); }); @@ -11760,7 +11744,7 @@ impl Editor { } self.transact(window, cx, |this, window, cx| { - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(selections); }); this.insert("", window, cx); @@ -11776,7 +11760,7 @@ impl Editor { pub fn kill_ring_cut(&mut self, _: &KillRingCut, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.move_with(|snapshot, sel| { if sel.is_empty() { sel.end = DisplayPoint::new(sel.end.row(), snapshot.line_len(sel.end.row())) @@ -11980,7 +11964,9 @@ impl Editor { }); let selections = this.selections.all::(cx); - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); } else { this.insert(&clipboard_text, window, cx); } @@ -12019,7 +12005,7 @@ impl Editor { if let Some((selections, _)) = self.selection_history.transaction(transaction_id).cloned() { - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_anchors(selections.to_vec()); }); } else { @@ -12049,7 +12035,7 @@ impl Editor { if let Some((_, Some(selections))) = self.selection_history.transaction(transaction_id).cloned() { - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_anchors(selections.to_vec()); }); } else { @@ -12079,7 +12065,7 @@ impl Editor { pub fn move_left(&mut self, _: &MoveLeft, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let cursor = if selection.is_empty() { movement::left(map, selection.start) @@ -12093,14 +12079,14 @@ impl Editor { pub fn select_left(&mut self, _: &SelectLeft, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| (movement::left(map, head), SelectionGoal::None)); }) } pub fn move_right(&mut self, _: &MoveRight, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let cursor = if selection.is_empty() { movement::right(map, selection.end) @@ -12114,7 +12100,7 @@ impl Editor { pub fn select_right(&mut self, _: &SelectRight, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| (movement::right(map, head), SelectionGoal::None)); }) } @@ -12135,7 +12121,7 @@ impl Editor { let selection_count = self.selections.count(); let first_selection = self.selections.first_anchor(); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; @@ -12176,7 +12162,7 @@ impl Editor { let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; @@ -12213,7 +12199,7 @@ impl Editor { let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; @@ -12239,7 +12225,7 @@ impl Editor { ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, goal| { movement::down_by_rows(map, head, action.lines, goal, false, text_layout_details) }) @@ -12254,7 +12240,7 @@ impl Editor { ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, goal| { movement::up_by_rows(map, head, action.lines, goal, false, text_layout_details) }) @@ -12275,7 +12261,7 @@ impl Editor { let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, goal| { movement::up_by_rows(map, head, row_count, goal, false, text_layout_details) }) @@ -12313,15 +12299,15 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - let effects = if action.center_cursor { - SelectionEffects::scroll(Autoscroll::center()) + let autoscroll = if action.center_cursor { + Autoscroll::center() } else { - SelectionEffects::default() + Autoscroll::fit() }; let text_layout_details = &self.text_layout_details(window); - self.change_selections(effects, window, cx, |s| { + self.change_selections(Some(autoscroll), window, cx, |s| { s.move_with(|map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; @@ -12342,7 +12328,7 @@ impl Editor { pub fn select_up(&mut self, _: &SelectUp, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, goal| { movement::up(map, head, goal, false, text_layout_details) }) @@ -12363,7 +12349,7 @@ impl Editor { let selection_count = self.selections.count(); let first_selection = self.selections.first_anchor(); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; @@ -12399,7 +12385,7 @@ impl Editor { let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, goal| { movement::down_by_rows(map, head, row_count, goal, false, text_layout_details) }) @@ -12437,14 +12423,14 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - let effects = if action.center_cursor { - SelectionEffects::scroll(Autoscroll::center()) + let autoscroll = if action.center_cursor { + Autoscroll::center() } else { - SelectionEffects::default() + Autoscroll::fit() }; let text_layout_details = &self.text_layout_details(window); - self.change_selections(effects, window, cx, |s| { + self.change_selections(Some(autoscroll), window, cx, |s| { s.move_with(|map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; @@ -12465,7 +12451,7 @@ impl Editor { pub fn select_down(&mut self, _: &SelectDown, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); let text_layout_details = &self.text_layout_details(window); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, goal| { movement::down(map, head, goal, false, text_layout_details) }) @@ -12523,7 +12509,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, head, _| { ( movement::previous_word_start(map, head), @@ -12540,7 +12526,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, head, _| { ( movement::previous_subword_start(map, head), @@ -12557,7 +12543,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::previous_word_start(map, head), @@ -12574,7 +12560,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::previous_subword_start(map, head), @@ -12593,7 +12579,7 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); self.transact(window, cx, |this, window, cx| { this.select_autoclose_pair(window, cx); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if selection.is_empty() { let cursor = if action.ignore_newlines { @@ -12618,7 +12604,7 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); self.transact(window, cx, |this, window, cx| { this.select_autoclose_pair(window, cx); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if selection.is_empty() { let cursor = movement::previous_subword_start(map, selection.head()); @@ -12637,7 +12623,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); @@ -12651,7 +12637,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); @@ -12665,7 +12651,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); @@ -12679,7 +12665,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); @@ -12694,7 +12680,7 @@ impl Editor { ) { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); self.transact(window, cx, |this, window, cx| { - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if selection.is_empty() { let cursor = if action.ignore_newlines { @@ -12718,7 +12704,7 @@ impl Editor { ) { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); self.transact(window, cx, |this, window, cx| { - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if selection.is_empty() { let cursor = movement::next_subword_end(map, selection.head()); @@ -12737,7 +12723,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, head, _| { ( movement::indented_line_beginning( @@ -12759,7 +12745,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::indented_line_beginning( @@ -12782,7 +12768,7 @@ impl Editor { ) { self.hide_mouse_cursor(HideMouseCursorOrigin::TypingAction, cx); self.transact(window, cx, |this, window, cx| { - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|_, selection| { selection.reversed = true; }); @@ -12807,7 +12793,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, head, _| { ( movement::line_end(map, head, action.stop_at_soft_wraps), @@ -12824,7 +12810,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::line_end(map, head, action.stop_at_soft_wraps), @@ -12883,7 +12869,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { selection.collapse_to( movement::start_of_paragraph(map, selection.head(), 1), @@ -12904,7 +12890,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { selection.collapse_to( movement::end_of_paragraph(map, selection.head(), 1), @@ -12925,7 +12911,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::start_of_paragraph(map, head, 1), @@ -12946,7 +12932,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::end_of_paragraph(map, head, 1), @@ -12967,7 +12953,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { selection.collapse_to( movement::start_of_excerpt( @@ -12992,7 +12978,7 @@ impl Editor { return; } - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { selection.collapse_to( movement::start_of_excerpt( @@ -13017,7 +13003,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { selection.collapse_to( movement::end_of_excerpt( @@ -13042,7 +13028,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { selection.collapse_to( movement::end_of_excerpt( @@ -13067,7 +13053,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::start_of_excerpt(map, head, workspace::searchable::Direction::Prev), @@ -13088,7 +13074,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::start_of_excerpt(map, head, workspace::searchable::Direction::Next), @@ -13109,7 +13095,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::end_of_excerpt(map, head, workspace::searchable::Direction::Next), @@ -13130,7 +13116,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_heads_with(|map, head, _| { ( movement::end_of_excerpt(map, head, workspace::searchable::Direction::Prev), @@ -13151,7 +13137,7 @@ impl Editor { return; } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(vec![0..0]); }); } @@ -13165,7 +13151,7 @@ impl Editor { let mut selection = self.selections.last::(cx); selection.set_head(Point::zero(), SelectionGoal::None); self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(vec![selection]); }); } @@ -13177,7 +13163,7 @@ impl Editor { } self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); let cursor = self.buffer.read(cx).read(cx).len(); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(vec![cursor..cursor]) }); } @@ -13243,7 +13229,7 @@ impl Editor { let buffer = self.buffer.read(cx).snapshot(cx); let mut selection = self.selections.first::(cx); selection.set_head(buffer.len(), SelectionGoal::None); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(vec![selection]); }); } @@ -13251,7 +13237,7 @@ impl Editor { pub fn select_all(&mut self, _: &SelectAll, window: &mut Window, cx: &mut Context) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); let end = self.buffer.read(cx).read(cx).len(); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_ranges(vec![0..end]); }); } @@ -13267,7 +13253,7 @@ impl Editor { selection.end = cmp::min(max_point, Point::new(rows.end.0, 0)); selection.reversed = false; } - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(selections); }); } @@ -13304,7 +13290,7 @@ impl Editor { } } } - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(new_selection_ranges); }); } @@ -13452,7 +13438,7 @@ impl Editor { } } - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(final_selections); }); @@ -13490,12 +13476,7 @@ impl Editor { auto_scroll.is_some(), cx, ); - let effects = if let Some(scroll) = auto_scroll { - SelectionEffects::scroll(scroll) - } else { - SelectionEffects::no_scroll() - }; - self.change_selections(effects, window, cx, |s| { + self.change_selections(auto_scroll, window, cx, |s| { if replace_newest { s.delete(s.newest_anchor().id); } @@ -13707,7 +13688,7 @@ impl Editor { } self.unfold_ranges(&new_selections.clone(), false, false, cx); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + self.change_selections(None, window, cx, |selections| { selections.select_ranges(new_selections) }); @@ -13878,7 +13859,7 @@ impl Editor { let selections = self.selections.disjoint_anchors(); match selections.first() { Some(first) if selections.len() >= 2 => { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([first.range()]); }); } @@ -13902,7 +13883,7 @@ impl Editor { let selections = self.selections.disjoint_anchors(); match selections.last() { Some(last) if selections.len() >= 2 => { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([last.range()]); }); } @@ -14181,7 +14162,9 @@ impl Editor { } drop(snapshot); - this.change_selections(Default::default(), window, cx, |s| s.select(selections)); + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.select(selections) + }); let selections = this.selections.all::(cx); let selections_on_single_row = selections.windows(2).all(|selections| { @@ -14200,7 +14183,7 @@ impl Editor { if advance_downwards { let snapshot = this.buffer.read(cx).snapshot(cx); - this.change_selections(Default::default(), window, cx, |s| { + this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|display_snapshot, display_point, _| { let mut point = display_point.to_point(display_snapshot); point.row += 1; @@ -14267,7 +14250,7 @@ impl Editor { .collect::>(); if selected_larger_symbol { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select(new_selections); }); } @@ -14367,7 +14350,7 @@ impl Editor { if selected_larger_node { self.select_syntax_node_history.disable_clearing = true; - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select(new_selections.clone()); }); self.select_syntax_node_history.disable_clearing = false; @@ -14413,7 +14396,7 @@ impl Editor { } self.select_syntax_node_history.disable_clearing = true; - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select(selections.to_vec()); }); self.select_syntax_node_history.disable_clearing = false; @@ -14678,7 +14661,7 @@ impl Editor { cx: &mut Context, ) { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_offsets_with(|snapshot, selection| { let Some(enclosing_bracket_ranges) = snapshot.enclosing_bracket_ranges(selection.start..selection.end) @@ -14739,12 +14722,9 @@ impl Editor { self.selection_history.mode = SelectionHistoryMode::Undoing; self.with_selection_effects_deferred(window, cx, |this, window, cx| { this.end_selection(window, cx); - this.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), - window, - cx, - |s| s.select_anchors(entry.selections.to_vec()), - ); + this.change_selections(Some(Autoscroll::newest()), window, cx, |s| { + s.select_anchors(entry.selections.to_vec()) + }); }); self.selection_history.mode = SelectionHistoryMode::Normal; @@ -14765,12 +14745,9 @@ impl Editor { self.selection_history.mode = SelectionHistoryMode::Redoing; self.with_selection_effects_deferred(window, cx, |this, window, cx| { this.end_selection(window, cx); - this.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), - window, - cx, - |s| s.select_anchors(entry.selections.to_vec()), - ); + this.change_selections(Some(Autoscroll::newest()), window, cx, |s| { + s.select_anchors(entry.selections.to_vec()) + }); }); self.selection_history.mode = SelectionHistoryMode::Normal; @@ -15003,7 +14980,7 @@ impl Editor { let Some(buffer_id) = buffer.anchor_after(next_diagnostic.range.start).buffer_id else { return; }; - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(vec![ next_diagnostic.range.start..next_diagnostic.range.start, ]) @@ -15045,7 +15022,7 @@ impl Editor { let autoscroll = Autoscroll::center(); self.unfold_ranges(&[destination..destination], false, false, cx); - self.change_selections(SelectionEffects::scroll(autoscroll), window, cx, |s| { + self.change_selections(Some(autoscroll), window, cx, |s| { s.select_ranges([destination..destination]); }); } @@ -15108,7 +15085,7 @@ impl Editor { .next_change(1, Direction::Next) .map(|s| s.to_vec()) { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let map = s.display_map(); s.select_display_ranges(selections.iter().map(|a| { let point = a.to_display_point(&map); @@ -15129,7 +15106,7 @@ impl Editor { .next_change(1, Direction::Prev) .map(|s| s.to_vec()) { - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let map = s.display_map(); s.select_display_ranges(selections.iter().map(|a| { let point = a.to_display_point(&map); @@ -15749,16 +15726,10 @@ impl Editor { match multibuffer_selection_mode { MultibufferSelectionMode::First => { if let Some(first_range) = ranges.first() { - editor.change_selections( - SelectionEffects::no_scroll(), - window, - cx, - |selections| { - selections.clear_disjoint(); - selections - .select_anchor_ranges(std::iter::once(first_range.clone())); - }, - ); + editor.change_selections(None, window, cx, |selections| { + selections.clear_disjoint(); + selections.select_anchor_ranges(std::iter::once(first_range.clone())); + }); } editor.highlight_background::( &ranges, @@ -15767,15 +15738,10 @@ impl Editor { ); } MultibufferSelectionMode::All => { - editor.change_selections( - SelectionEffects::no_scroll(), - window, - cx, - |selections| { - selections.clear_disjoint(); - selections.select_anchor_ranges(ranges); - }, - ); + editor.change_selections(None, window, cx, |selections| { + selections.clear_disjoint(); + selections.select_anchor_ranges(ranges); + }); } } editor.register_buffers_with_language_servers(cx); @@ -15909,7 +15875,7 @@ impl Editor { if rename_selection_range.end > old_name.len() { editor.select_all(&SelectAll, window, cx); } else { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([rename_selection_range]); }); } @@ -16082,7 +16048,7 @@ impl Editor { .min(rename_range.end); drop(snapshot); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_ranges(vec![cursor_in_editor..cursor_in_editor]) }); } else { @@ -16765,7 +16731,7 @@ impl Editor { pub fn set_mark(&mut self, _: &actions::SetMark, window: &mut Window, cx: &mut Context) { if self.selection_mark_mode { - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.move_with(|_, sel| { sel.collapse_to(sel.head(), SelectionGoal::None); }); @@ -16781,7 +16747,7 @@ impl Editor { window: &mut Window, cx: &mut Context, ) { - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.move_with(|_, sel| { if sel.start != sel.end { sel.reversed = !sel.reversed @@ -17520,7 +17486,7 @@ impl Editor { let autoscroll = Autoscroll::center(); self.unfold_ranges(&[destination..destination], false, false, cx); - self.change_selections(SelectionEffects::scroll(autoscroll), window, cx, |s| { + self.change_selections(Some(autoscroll), window, cx, |s| { s.select_ranges([destination..destination]); }); } @@ -20055,14 +20021,9 @@ impl Editor { None => Autoscroll::newest(), }; let nav_history = editor.nav_history.take(); - editor.change_selections( - SelectionEffects::scroll(autoscroll), - window, - cx, - |s| { - s.select_ranges(ranges); - }, - ); + editor.change_selections(Some(autoscroll), window, cx, |s| { + s.select_ranges(ranges); + }); editor.nav_history = nav_history; }); } @@ -20263,7 +20224,7 @@ impl Editor { } if let Some(relative_utf16_range) = relative_utf16_range { let selections = self.selections.all::(cx); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { let new_ranges = selections.into_iter().map(|range| { let start = OffsetUtf16( range @@ -20406,7 +20367,7 @@ impl Editor { .iter() .map(|selection| (selection.end..selection.end, pending.clone())); this.edit(edits, cx); - this.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + this.change_selections(None, window, cx, |s| { s.select_ranges(selections.into_iter().enumerate().map(|(ix, sel)| { sel.start + ix * pending.len()..sel.end + ix * pending.len() })); @@ -20562,9 +20523,7 @@ impl Editor { } }) .detach(); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { - selections.refresh() - }); + self.change_selections(None, window, cx, |selections| selections.refresh()); } pub fn to_pixel_point( @@ -20689,7 +20648,7 @@ impl Editor { buffer_snapshot.get_or_init(|| self.buffer.read(cx).snapshot(cx)); // skip adding the initial selection to selection history self.selection_history.mode = SelectionHistoryMode::Skipping; - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_ranges(selections.into_iter().map(|(start, end)| { snapshot.clip_offset(start, Bias::Left) ..snapshot.clip_offset(end, Bias::Right) @@ -22503,7 +22462,7 @@ impl EntityInputHandler for Editor { }); if let Some(new_selected_ranges) = new_selected_ranges { - this.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + this.change_selections(None, window, cx, |selections| { selections.select_ranges(new_selected_ranges) }); this.backspace(&Default::default(), window, cx); @@ -22578,9 +22537,7 @@ impl EntityInputHandler for Editor { }); if let Some(ranges) = ranges_to_replace { - this.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges(ranges) - }); + this.change_selections(None, window, cx, |s| s.select_ranges(ranges)); } let marked_ranges = { @@ -22634,7 +22591,7 @@ impl EntityInputHandler for Editor { .collect::>(); drop(snapshot); - this.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + this.change_selections(None, window, cx, |selections| { selections.select_ranges(new_selected_ranges) }); } diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 376effa91d..1ef2294d41 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -179,9 +179,7 @@ fn test_edit_events(cx: &mut TestAppContext) { // No event is emitted when the mutation is a no-op. _ = editor2.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([0..0]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([0..0])); editor.backspace(&Backspace, window, cx); }); @@ -204,9 +202,7 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) { _ = editor.update(cx, |editor, window, cx| { editor.start_transaction_at(now, window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([2..4]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([2..4])); editor.insert("cd", window, cx); editor.end_transaction_at(now, cx); @@ -214,18 +210,14 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) { assert_eq!(editor.selections.ranges(cx), vec![4..4]); editor.start_transaction_at(now, window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([4..5]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([4..5])); editor.insert("e", window, cx); editor.end_transaction_at(now, cx); assert_eq!(editor.text(cx), "12cde6"); assert_eq!(editor.selections.ranges(cx), vec![5..5]); now += group_interval + Duration::from_millis(1); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([2..2]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([2..2])); // Simulate an edit in another editor buffer.update(cx, |buffer, cx| { @@ -333,7 +325,7 @@ fn test_ime_composition(cx: &mut TestAppContext) { assert_eq!(editor.marked_text_ranges(cx), None); // Start a new IME composition with multiple cursors. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ OffsetUtf16(1)..OffsetUtf16(1), OffsetUtf16(3)..OffsetUtf16(3), @@ -631,7 +623,7 @@ fn test_clone(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(selection_ranges.clone()) }); editor.fold_creases( @@ -717,12 +709,12 @@ async fn test_navigation_history(cx: &mut TestAppContext) { // Move the cursor a small distance. // Nothing is added to the navigation history. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0) ]) }); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 0)..DisplayPoint::new(DisplayRow(3), 0) ]) @@ -731,7 +723,7 @@ async fn test_navigation_history(cx: &mut TestAppContext) { // Move the cursor a large distance. // The history can jump back to the previous position. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(13), 0)..DisplayPoint::new(DisplayRow(13), 3) ]) @@ -901,7 +893,7 @@ fn test_fold_action(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(7), 0)..DisplayPoint::new(DisplayRow(12), 0) ]); @@ -992,7 +984,7 @@ fn test_fold_action_whitespace_sensitive_language(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(10), 0) ]); @@ -1077,7 +1069,7 @@ fn test_fold_action_multiple_line_breaks(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(11), 0) ]); @@ -1309,7 +1301,7 @@ fn test_move_cursor(cx: &mut TestAppContext) { &[DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)] ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 2) ]); @@ -1454,7 +1446,7 @@ fn test_move_cursor_different_line_lengths(cx: &mut TestAppContext) { build_editor(buffer.clone(), window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([empty_range(0, "ⓐⓑⓒⓓⓔ".len())]); }); @@ -1544,7 +1536,7 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(1), 4)..DisplayPoint::new(DisplayRow(1), 4), @@ -1739,7 +1731,7 @@ fn test_beginning_end_of_line_ignore_soft_wrap(cx: &mut TestAppContext) { // First, let's assert behavior on the first line, that was not soft-wrapped. // Start the cursor at the `k` on the first line - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 7)..DisplayPoint::new(DisplayRow(0), 7) ]); @@ -1761,7 +1753,7 @@ fn test_beginning_end_of_line_ignore_soft_wrap(cx: &mut TestAppContext) { // Now, let's assert behavior on the second line, that ended up being soft-wrapped. // Start the cursor at the last line (`y` that was wrapped to a new line) - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 0) ]); @@ -1827,7 +1819,7 @@ fn test_beginning_of_line_stop_at_indent(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(1), 4)..DisplayPoint::new(DisplayRow(1), 4), @@ -1909,7 +1901,7 @@ fn test_prev_next_word_boundary(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 11)..DisplayPoint::new(DisplayRow(0), 11), DisplayPoint::new(DisplayRow(2), 4)..DisplayPoint::new(DisplayRow(2), 4), @@ -1979,7 +1971,7 @@ fn test_prev_next_word_bounds_with_soft_wrap(cx: &mut TestAppContext) { "use one::{\n two::three::\n four::five\n};" ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(1), 7)..DisplayPoint::new(DisplayRow(1), 7) ]); @@ -2242,7 +2234,7 @@ async fn test_autoscroll(cx: &mut TestAppContext) { // on screen, the editor autoscrolls to reveal the newest cursor, and // allows the vertical scroll margin below that cursor. cx.update_editor(|editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { selections.select_ranges([ Point::new(0, 0)..Point::new(0, 0), Point::new(6, 0)..Point::new(6, 0), @@ -2270,7 +2262,7 @@ async fn test_autoscroll(cx: &mut TestAppContext) { // Add a cursor above the visible area. Since both cursors fit on screen, // the editor scrolls to show both. cx.update_editor(|editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |selections| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { selections.select_ranges([ Point::new(1, 0)..Point::new(1, 0), Point::new(6, 0)..Point::new(6, 0), @@ -2437,7 +2429,7 @@ fn test_delete_to_word_boundary(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ // an empty selection - the preceding word fragment is deleted DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), @@ -2456,7 +2448,7 @@ fn test_delete_to_word_boundary(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ // an empty selection - the following word fragment is deleted DisplayPoint::new(DisplayRow(0), 3)..DisplayPoint::new(DisplayRow(0), 3), @@ -2491,7 +2483,7 @@ fn test_delete_to_previous_word_start_or_newline(cx: &mut TestAppContext) { }; _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 1)..DisplayPoint::new(DisplayRow(3), 1) ]) @@ -2527,7 +2519,7 @@ fn test_delete_to_next_word_end_or_newline(cx: &mut TestAppContext) { }; _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0) ]) @@ -2566,7 +2558,7 @@ fn test_newline(cx: &mut TestAppContext) { }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(1), 2), @@ -2599,7 +2591,7 @@ fn test_newline_with_old_selections(cx: &mut TestAppContext) { cx, ); let mut editor = build_editor(buffer.clone(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ Point::new(2, 4)..Point::new(2, 5), Point::new(5, 4)..Point::new(5, 5), @@ -3086,7 +3078,7 @@ fn test_insert_with_old_selections(cx: &mut TestAppContext) { let editor = cx.add_window(|window, cx| { let buffer = MultiBuffer::build_simple("a( X ), b( Y ), c( Z )", cx); let mut editor = build_editor(buffer.clone(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([3..4, 11..12, 19..20]) }); editor @@ -3735,7 +3727,7 @@ fn test_delete_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 1), @@ -3758,7 +3750,7 @@ fn test_delete_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(0), 1) ]) @@ -3795,7 +3787,7 @@ fn test_join_lines_with_single_selection(cx: &mut TestAppContext) { ); // When multiple lines are selected, remove newlines that are spanned by the selection - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(0, 5)..Point::new(2, 2)]) }); editor.join_lines(&JoinLines, window, cx); @@ -3814,7 +3806,7 @@ fn test_join_lines_with_single_selection(cx: &mut TestAppContext) { ); // When joining an empty line don't insert a space - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(2, 1)..Point::new(2, 2)]) }); editor.join_lines(&JoinLines, window, cx); @@ -3854,7 +3846,7 @@ fn test_join_lines_with_single_selection(cx: &mut TestAppContext) { // We remove any leading spaces assert_eq!(buffer.read(cx).text(), "aaa bbb\n c\n \n\td"); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(0, 1)..Point::new(0, 1)]) }); editor.join_lines(&JoinLines, window, cx); @@ -3881,7 +3873,7 @@ fn test_join_lines_with_multi_selection(cx: &mut TestAppContext) { let mut editor = build_editor(buffer.clone(), window, cx); let buffer = buffer.read(cx).as_singleton().unwrap(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ Point::new(0, 2)..Point::new(1, 1), Point::new(1, 2)..Point::new(1, 2), @@ -4721,7 +4713,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), @@ -4747,7 +4739,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1), @@ -4771,7 +4763,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), @@ -4797,7 +4789,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1), @@ -4819,7 +4811,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1), @@ -4856,7 +4848,7 @@ fn test_move_line_up_down(cx: &mut TestAppContext) { window, cx, ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(3), 1)..DisplayPoint::new(DisplayRow(3), 1), @@ -4959,7 +4951,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) { Some(Autoscroll::fit()), cx, ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) }); editor.move_line_down(&MoveLineDown, window, cx); @@ -5044,9 +5036,7 @@ fn test_transpose(cx: &mut TestAppContext) { _ = cx.add_window(|window, cx| { let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), window, cx); editor.set_style(EditorStyle::default(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([1..1]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([1..1])); editor.transpose(&Default::default(), window, cx); assert_eq!(editor.text(cx), "bac"); assert_eq!(editor.selections.ranges(cx), [2..2]); @@ -5065,16 +5055,12 @@ fn test_transpose(cx: &mut TestAppContext) { _ = cx.add_window(|window, cx| { let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), window, cx); editor.set_style(EditorStyle::default(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([3..3]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([3..3])); editor.transpose(&Default::default(), window, cx); assert_eq!(editor.text(cx), "acb\nde"); assert_eq!(editor.selections.ranges(cx), [3..3]); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([4..4]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([4..4])); editor.transpose(&Default::default(), window, cx); assert_eq!(editor.text(cx), "acbd\ne"); assert_eq!(editor.selections.ranges(cx), [5..5]); @@ -5093,9 +5079,7 @@ fn test_transpose(cx: &mut TestAppContext) { _ = cx.add_window(|window, cx| { let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), window, cx); editor.set_style(EditorStyle::default(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([1..1, 2..2, 4..4]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([1..1, 2..2, 4..4])); editor.transpose(&Default::default(), window, cx); assert_eq!(editor.text(cx), "bacd\ne"); assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]); @@ -5122,9 +5106,7 @@ fn test_transpose(cx: &mut TestAppContext) { _ = cx.add_window(|window, cx| { let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), window, cx); editor.set_style(EditorStyle::default(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([4..4]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([4..4])); editor.transpose(&Default::default(), window, cx); assert_eq!(editor.text(cx), "🏀🍐✋"); assert_eq!(editor.selections.ranges(cx), [8..8]); @@ -6103,7 +6085,7 @@ fn test_select_line(cx: &mut TestAppContext) { build_editor(buffer, window, cx) }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), @@ -6230,7 +6212,7 @@ async fn test_split_selection_into_lines_interacting_with_creases(cx: &mut TestA }); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), @@ -6249,7 +6231,7 @@ async fn test_split_selection_into_lines_interacting_with_creases(cx: &mut TestA .assert_editor_state("aˇaˇaaa\nbbbbb\nˇccccc\nddddd\neeeee\nfffff\nggggg\nhhhhh\niiiiiˇ"); _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(5), 0)..DisplayPoint::new(DisplayRow(0), 1) ]) @@ -6995,7 +6977,7 @@ async fn test_undo_format_scrolls_to_last_edit_pos(cx: &mut TestAppContext) { // Move cursor to a different position cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(4, 2)..Point::new(4, 2)]); }); }); @@ -7100,7 +7082,7 @@ async fn test_undo_inline_completion_scrolls_to_edit_pos(cx: &mut TestAppContext "}); cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(9, 2)..Point::new(9, 2)]); }); }); @@ -7360,7 +7342,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut TestAppContext) { .await; editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 25)..DisplayPoint::new(DisplayRow(0), 25), DisplayPoint::new(DisplayRow(2), 24)..DisplayPoint::new(DisplayRow(2), 12), @@ -7542,7 +7524,7 @@ async fn test_select_larger_syntax_node_for_cursor_at_end(cx: &mut TestAppContex // Test case 1: Cursor at end of word editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 5)..DisplayPoint::new(DisplayRow(0), 5) ]); @@ -7566,7 +7548,7 @@ async fn test_select_larger_syntax_node_for_cursor_at_end(cx: &mut TestAppContex // Test case 2: Cursor at end of statement editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 11)..DisplayPoint::new(DisplayRow(0), 11) ]); @@ -7611,7 +7593,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte // Test 1: Cursor on a letter of a string word editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 17)..DisplayPoint::new(DisplayRow(3), 17) ]); @@ -7645,7 +7627,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte // Test 2: Partial selection within a word editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 17)..DisplayPoint::new(DisplayRow(3), 19) ]); @@ -7679,7 +7661,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte // Test 3: Complete word already selected editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 16)..DisplayPoint::new(DisplayRow(3), 21) ]); @@ -7713,7 +7695,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte // Test 4: Selection spanning across words editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 19)..DisplayPoint::new(DisplayRow(3), 24) ]); @@ -7915,9 +7897,7 @@ async fn test_autoindent(cx: &mut TestAppContext) { .await; editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([5..5, 8..8, 9..9]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([5..5, 8..8, 9..9])); editor.newline(&Newline, window, cx); assert_eq!(editor.text(cx), "fn a(\n \n) {\n \n}\n"); assert_eq!( @@ -8699,7 +8679,7 @@ async fn test_surround_with_pair(cx: &mut TestAppContext) { .await; editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 1), @@ -8849,7 +8829,7 @@ async fn test_delete_autoclose_pair(cx: &mut TestAppContext) { .await; editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ Point::new(0, 1)..Point::new(0, 1), Point::new(1, 1)..Point::new(1, 1), @@ -9531,22 +9511,16 @@ async fn test_multibuffer_format_during_save(cx: &mut TestAppContext) { }); multi_buffer_editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(1..2)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(1..2)) + }); editor.insert("|one|two|three|", window, cx); }); assert!(cx.read(|cx| multi_buffer_editor.is_dirty(cx))); multi_buffer_editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(60..70)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(60..70)) + }); editor.insert("|four|five|six|", window, cx); }); assert!(cx.read(|cx| multi_buffer_editor.is_dirty(cx))); @@ -9709,12 +9683,9 @@ async fn test_autosave_with_dirty_buffers(cx: &mut TestAppContext) { // Edit only the first buffer editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(10..10)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(10..10)) + }); editor.insert("// edited", window, cx); }); @@ -11126,9 +11097,7 @@ async fn test_signature_help(cx: &mut TestAppContext) { "}); cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([0..0]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([0..0])); }); let mocked_response = lsp::SignatureHelp { @@ -11215,7 +11184,7 @@ async fn test_signature_help(cx: &mut TestAppContext) { // When selecting a range, the popover is gone. // Avoid using `cx.set_state` to not actually edit the document, just change its selections. cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(1, 25)..Point::new(1, 19))); }) }); @@ -11232,7 +11201,7 @@ async fn test_signature_help(cx: &mut TestAppContext) { // When unselecting again, the popover is back if within the brackets. cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19))); }) }); @@ -11252,7 +11221,7 @@ async fn test_signature_help(cx: &mut TestAppContext) { // Test to confirm that SignatureHelp does not appear after deselecting multiple ranges when it was hidden by pressing Escape. cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(0, 0)..Point::new(0, 0))); s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19))); }) @@ -11293,7 +11262,7 @@ async fn test_signature_help(cx: &mut TestAppContext) { cx.condition(|editor, _| !editor.signature_help_state.is_shown()) .await; cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(1, 25)..Point::new(1, 19))); }) }); @@ -11305,7 +11274,7 @@ async fn test_signature_help(cx: &mut TestAppContext) { fn sample(param1: u8, param2: u8) {} "}); cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19))); }) }); @@ -11961,7 +11930,7 @@ async fn test_completion_in_multibuffer_with_replace_range(cx: &mut TestAppConte let fake_server = fake_servers.next().await.unwrap(); editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ Point::new(1, 11)..Point::new(1, 11), Point::new(7, 11)..Point::new(7, 11), @@ -13602,7 +13571,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) { let (editor, cx) = cx.add_window_view(|window, cx| build_editor(multibuffer, window, cx)); editor.update_in(cx, |editor, window, cx| { assert_eq!(editor.text(cx), "aaaa\nbbbb"); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ Point::new(0, 0)..Point::new(0, 0), Point::new(1, 0)..Point::new(1, 0), @@ -13620,7 +13589,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) { ); // Ensure the cursor's head is respected when deleting across an excerpt boundary. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(0, 2)..Point::new(1, 2)]) }); editor.backspace(&Default::default(), window, cx); @@ -13630,7 +13599,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) { [Point::new(1, 0)..Point::new(1, 0)] ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 1)..Point::new(0, 1)]) }); editor.backspace(&Default::default(), window, cx); @@ -13678,9 +13647,7 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) { true, ); assert_eq!(editor.text(cx), expected_text); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges(selection_ranges) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges(selection_ranges)); editor.handle_input("X", window, cx); @@ -13741,7 +13708,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) { let editor = cx.add_window(|window, cx| { let mut editor = build_editor(multibuffer.clone(), window, cx); let snapshot = editor.snapshot(window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 3)..Point::new(1, 3)]) }); editor.begin_selection( @@ -13763,7 +13730,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) { // Refreshing selections is a no-op when excerpts haven't changed. _ = editor.update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| s.refresh()); + editor.change_selections(None, window, cx, |s| s.refresh()); assert_eq!( editor.selections.ranges(cx), [ @@ -13788,7 +13755,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) { // Refreshing selections will relocate the first selection to the original buffer // location. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| s.refresh()); + editor.change_selections(None, window, cx, |s| s.refresh()); assert_eq!( editor.selections.ranges(cx), [ @@ -13850,7 +13817,7 @@ fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) { ); // Ensure we don't panic when selections are refreshed and that the pending selection is finalized. - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| s.refresh()); + editor.change_selections(None, window, cx, |s| s.refresh()); assert_eq!( editor.selections.ranges(cx), [Point::new(0, 3)..Point::new(0, 3)] @@ -13909,7 +13876,7 @@ async fn test_extra_newline_insertion(cx: &mut TestAppContext) { .await; editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 3), DisplayPoint::new(DisplayRow(2), 5)..DisplayPoint::new(DisplayRow(2), 5), @@ -14088,9 +14055,7 @@ async fn test_following(cx: &mut TestAppContext) { // Update the selections only _ = leader.update(cx, |leader, window, cx| { - leader.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([1..1]) - }); + leader.change_selections(None, window, cx, |s| s.select_ranges([1..1])); }); follower .update(cx, |follower, window, cx| { @@ -14138,9 +14103,7 @@ async fn test_following(cx: &mut TestAppContext) { // Update the selections and scroll position. The follower's scroll position is updated // via autoscroll, not via the leader's exact scroll position. _ = leader.update(cx, |leader, window, cx| { - leader.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([0..0]) - }); + leader.change_selections(None, window, cx, |s| s.select_ranges([0..0])); leader.request_autoscroll(Autoscroll::newest(), cx); leader.set_scroll_position(gpui::Point::new(1.5, 3.5), window, cx); }); @@ -14164,9 +14127,7 @@ async fn test_following(cx: &mut TestAppContext) { // Creating a pending selection that precedes another selection _ = leader.update(cx, |leader, window, cx| { - leader.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([1..1]) - }); + leader.change_selections(None, window, cx, |s| s.select_ranges([1..1])); leader.begin_selection(DisplayPoint::new(DisplayRow(0), 0), true, 1, window, cx); }); follower @@ -14822,7 +14783,7 @@ async fn test_on_type_formatting_not_triggered(cx: &mut TestAppContext) { editor_handle.update_in(cx, |editor, window, cx| { window.focus(&editor.focus_handle(cx)); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(0, 21)..Point::new(0, 20)]) }); editor.handle_input("{", window, cx); @@ -16437,7 +16398,7 @@ async fn test_multibuffer_reverts(cx: &mut TestAppContext) { }); editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(0, 0)..Point::new(6, 0))); }); editor.git_restore(&Default::default(), window, cx); @@ -16581,12 +16542,9 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) { cx.executor().run_until_parked(); multi_buffer_editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(1..2)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(1..2)) + }); editor.open_excerpts(&OpenExcerpts, window, cx); }); cx.executor().run_until_parked(); @@ -16636,12 +16594,9 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) { .unwrap(); multi_buffer_editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(39..40)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(39..40)) + }); editor.open_excerpts(&OpenExcerpts, window, cx); }); cx.executor().run_until_parked(); @@ -16695,12 +16650,9 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) { .unwrap(); multi_buffer_editor.update_in(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(70..70)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(70..70)) + }); editor.open_excerpts(&OpenExcerpts, window, cx); }); cx.executor().run_until_parked(); @@ -18302,7 +18254,7 @@ async fn test_active_indent_guide_single_line(cx: &mut TestAppContext) { .await; cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 0)..Point::new(1, 0)]) }); }); @@ -18330,7 +18282,7 @@ async fn test_active_indent_guide_respect_indented_range(cx: &mut TestAppContext .await; cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 0)..Point::new(1, 0)]) }); }); @@ -18346,7 +18298,7 @@ async fn test_active_indent_guide_respect_indented_range(cx: &mut TestAppContext ); cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) }); }); @@ -18362,7 +18314,7 @@ async fn test_active_indent_guide_respect_indented_range(cx: &mut TestAppContext ); cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(3, 0)..Point::new(3, 0)]) }); }); @@ -18393,7 +18345,7 @@ async fn test_active_indent_guide_empty_line(cx: &mut TestAppContext) { .await; cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) }); }); @@ -18419,7 +18371,7 @@ async fn test_active_indent_guide_non_matching_indent(cx: &mut TestAppContext) { .await; cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(1, 0)..Point::new(1, 0)]) }); }); @@ -19357,14 +19309,14 @@ async fn test_find_enclosing_node_with_task(cx: &mut TestAppContext) { ); // Test finding task when cursor is inside function body - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(4, 5)..Point::new(4, 5)]) }); let (_, row, _) = editor.find_enclosing_node_task(cx).unwrap(); assert_eq!(row, 3, "Should find task for cursor inside runnable_1"); // Test finding task when cursor is on function name - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(8, 4)..Point::new(8, 4)]) }); let (_, row, _) = editor.find_enclosing_node_task(cx).unwrap(); @@ -19518,7 +19470,7 @@ async fn test_folding_buffers(cx: &mut TestAppContext) { .collect::(), "bbbb" ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![Point::new(1, 0)..Point::new(1, 0)]); }); editor.handle_input("B", window, cx); @@ -19745,9 +19697,7 @@ async fn test_folding_buffer_when_multibuffer_has_only_one_excerpt(cx: &mut Test HighlightStyle::color(Hsla::green()), cx, ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges(Some(highlight_range)) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges(Some(highlight_range))); }); let full_text = format!("\n\n{sample_text}"); @@ -21117,7 +21067,7 @@ println!("5"); }) }); editor_1.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(expected_ranges.clone()); }); }); @@ -21563,7 +21513,7 @@ async fn test_html_linked_edits_on_completion(cx: &mut TestAppContext) { let fake_server = fake_servers.next().await.unwrap(); editor.update_in(cx, |editor, window, cx| { editor.set_text("", window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges([Point::new(0, 3)..Point::new(0, 3)]); }); let Some((buffer, _)) = editor @@ -22569,7 +22519,7 @@ async fn test_pulling_diagnostics(cx: &mut TestAppContext) { // Moving cursor should not trigger diagnostic request editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(0, 0)..Point::new(0, 0)]) }); }); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 4260537076..6fee347c17 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -5238,8 +5238,8 @@ impl EditorElement { paint_highlight(range.start, range.end, color, edges); } - let scroll_left = - layout.position_map.snapshot.scroll_position().x * layout.position_map.em_width; + let scroll_left = layout.position_map.snapshot.scroll_position().x + * layout.position_map.em_advance; for (wrap_position, active) in layout.wrap_guides.iter() { let x = (layout.position_map.text_hitbox.origin.x @@ -6676,7 +6676,7 @@ impl EditorElement { let position_map: &PositionMap = &position_map; let line_height = position_map.line_height; - let max_glyph_width = position_map.em_width; + let max_glyph_advance = position_map.em_advance; let (delta, axis) = match delta { gpui::ScrollDelta::Pixels(mut pixels) => { //Trackpad @@ -6687,15 +6687,15 @@ impl EditorElement { gpui::ScrollDelta::Lines(lines) => { //Not trackpad let pixels = - point(lines.x * max_glyph_width, lines.y * line_height); + point(lines.x * max_glyph_advance, lines.y * line_height); (pixels, None) } }; let current_scroll_position = position_map.snapshot.scroll_position(); - let x = (current_scroll_position.x * max_glyph_width + let x = (current_scroll_position.x * max_glyph_advance - (delta.x * scroll_sensitivity)) - / max_glyph_width; + / max_glyph_advance; let y = (current_scroll_position.y * line_height - (delta.y * scroll_sensitivity)) / line_height; @@ -8591,7 +8591,7 @@ impl Element for EditorElement { start_row, editor_content_width, scroll_width, - em_width, + em_advance, &line_layouts, cx, ) @@ -10051,7 +10051,7 @@ fn compute_auto_height_layout( mod tests { use super::*; use crate::{ - Editor, MultiBuffer, SelectionEffects, + Editor, MultiBuffer, display_map::{BlockPlacement, BlockProperties}, editor_tests::{init_test, update_test_language_settings}, }; @@ -10176,7 +10176,7 @@ mod tests { window .update(cx, |editor, window, cx| { editor.cursor_shape = CursorShape::Block; - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ Point::new(0, 0)..Point::new(1, 0), Point::new(3, 2)..Point::new(3, 3), diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index 02f93e6829..a716b2e031 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -1257,7 +1257,7 @@ mod tests { let snapshot = editor.buffer().read(cx).snapshot(cx); let anchor_range = snapshot.anchor_before(selection_range.start) ..snapshot.anchor_after(selection_range.end); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(crate::Autoscroll::fit()), window, cx, |s| { s.set_pending_anchor_range(anchor_range, crate::SelectMode::Character) }); }); diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index cae4789535..9e6fc356ea 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -3,7 +3,7 @@ use crate::{ EditorSnapshot, GlobalDiagnosticRenderer, Hover, display_map::{InlayOffset, ToDisplayPoint, invisibles::is_invisible}, hover_links::{InlayHighlight, RangeInEditor}, - scroll::ScrollAmount, + scroll::{Autoscroll, ScrollAmount}, }; use anyhow::Context as _; use gpui::{ @@ -746,7 +746,7 @@ pub fn open_markdown_url(link: SharedString, window: &mut Window, cx: &mut App) }; editor.update_in(cx, |editor, window, cx| { editor.change_selections( - Default::default(), + Some(Autoscroll::fit()), window, cx, |selections| { diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index 647f34487f..dcfa8429a0 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -1302,7 +1302,6 @@ fn apply_hint_update( #[cfg(test)] pub mod tests { - use crate::SelectionEffects; use crate::editor_tests::update_test_language_settings; use crate::scroll::ScrollAmount; use crate::{ExcerptRange, scroll::Autoscroll, test::editor_lsp_test_context::rust_lang}; @@ -1385,9 +1384,7 @@ pub mod tests { editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input("some change", window, cx); }) .unwrap(); @@ -1701,9 +1698,7 @@ pub mod tests { rs_editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input("some rs change", window, cx); }) .unwrap(); @@ -1738,9 +1733,7 @@ pub mod tests { md_editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input("some md change", window, cx); }) .unwrap(); @@ -2162,9 +2155,7 @@ pub mod tests { ] { editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input(change_after_opening, window, cx); }) .unwrap(); @@ -2208,9 +2199,7 @@ pub mod tests { edits.push(cx.spawn(|mut cx| async move { task_editor .update(&mut cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([13..13]) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.handle_input(async_later_change, window, cx); }) .unwrap(); @@ -2458,12 +2447,9 @@ pub mod tests { editor .update(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| s.select_ranges([selection_in_cached_range..selection_in_cached_range]), - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_ranges([selection_in_cached_range..selection_in_cached_range]) + }); }) .unwrap(); cx.executor().advance_clock(Duration::from_millis( @@ -2726,24 +2712,15 @@ pub mod tests { editor .update(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]), - ); - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges([Point::new(22, 0)..Point::new(22, 0)]), - ); - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges([Point::new(50, 0)..Point::new(50, 0)]), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]) + }); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges([Point::new(22, 0)..Point::new(22, 0)]) + }); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges([Point::new(50, 0)..Point::new(50, 0)]) + }); }) .unwrap(); cx.executor().run_until_parked(); @@ -2768,12 +2745,9 @@ pub mod tests { editor .update(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges([Point::new(100, 0)..Point::new(100, 0)]), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges([Point::new(100, 0)..Point::new(100, 0)]) + }); }) .unwrap(); cx.executor().advance_clock(Duration::from_millis( @@ -2804,12 +2778,9 @@ pub mod tests { editor .update(cx, |editor, window, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]) + }); }) .unwrap(); cx.executor().advance_clock(Duration::from_millis( @@ -2841,7 +2812,7 @@ pub mod tests { editor_edited.store(true, Ordering::Release); editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(57, 0)..Point::new(57, 0)]) }); editor.handle_input("++++more text++++", window, cx); @@ -3159,7 +3130,7 @@ pub mod tests { cx.executor().run_until_parked(); editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) }) }) @@ -3441,7 +3412,7 @@ pub mod tests { cx.executor().run_until_parked(); editor .update(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) }) }) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index fa6bd93ab8..ec3590dba2 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -1352,7 +1352,7 @@ impl ProjectItem for Editor { cx, ); if !restoration_data.selections.is_empty() { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(clip_ranges(&restoration_data.selections, &snapshot)); }); } @@ -1558,7 +1558,7 @@ impl SearchableItem for Editor { ) { self.unfold_ranges(&[matches[index].clone()], false, true, cx); let range = self.range_for_match(&matches[index]); - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([range]); }) } @@ -1570,7 +1570,7 @@ impl SearchableItem for Editor { cx: &mut Context, ) { self.unfold_ranges(matches, false, false, cx); - self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + self.change_selections(None, window, cx, |s| { s.select_ranges(matches.iter().cloned()) }); } diff --git a/crates/editor/src/jsx_tag_auto_close.rs b/crates/editor/src/jsx_tag_auto_close.rs index 95a7925839..f24fe46100 100644 --- a/crates/editor/src/jsx_tag_auto_close.rs +++ b/crates/editor/src/jsx_tag_auto_close.rs @@ -843,7 +843,7 @@ mod jsx_tag_autoclose_tests { let mut cx = EditorTestContext::for_editor(editor, cx).await; cx.update_editor(|editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select(vec![ Selection::from_offset(4), Selection::from_offset(9), diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index 4780f1f565..b9b8cbe997 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -1,8 +1,8 @@ use crate::{ Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DisplayPoint, DisplaySnapshot, Editor, EvaluateSelectedText, FindAllReferences, GoToDeclaration, GoToDefinition, GoToImplementation, - GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode, SelectionEffects, - SelectionExt, ToDisplayPoint, ToggleCodeActions, + GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode, SelectionExt, + ToDisplayPoint, ToggleCodeActions, actions::{Format, FormatSelections}, selections_collection::SelectionsCollection, }; @@ -177,7 +177,7 @@ pub fn deploy_context_menu( let anchor = buffer.anchor_before(point.to_point(&display_map)); if !display_ranges(&display_map, &editor.selections).any(|r| r.contains(&point)) { // Move the cursor to the clicked location so that dispatched actions make sense - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.clear_disjoint(); s.set_pending_anchor_range(anchor..anchor, SelectMode::Character); }); diff --git a/crates/editor/src/proposed_changes_editor.rs b/crates/editor/src/proposed_changes_editor.rs index 1ead45b3de..c5f937f20c 100644 --- a/crates/editor/src/proposed_changes_editor.rs +++ b/crates/editor/src/proposed_changes_editor.rs @@ -1,4 +1,4 @@ -use crate::{ApplyAllDiffHunks, Editor, EditorEvent, SelectionEffects, SemanticsProvider}; +use crate::{ApplyAllDiffHunks, Editor, EditorEvent, SemanticsProvider}; use buffer_diff::BufferDiff; use collections::HashSet; use futures::{channel::mpsc, future::join_all}; @@ -213,9 +213,7 @@ impl ProposedChangesEditor { self.buffer_entries = buffer_entries; self.editor.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { - selections.refresh() - }); + editor.change_selections(None, window, cx, |selections| selections.refresh()); editor.buffer.update(cx, |buffer, cx| { for diff in new_diffs { buffer.add_diff(diff, cx) diff --git a/crates/editor/src/test.rs b/crates/editor/src/test.rs index 0a9d5e9535..9e20d14b61 100644 --- a/crates/editor/src/test.rs +++ b/crates/editor/src/test.rs @@ -5,7 +5,7 @@ use std::{rc::Rc, sync::LazyLock}; pub use crate::rust_analyzer_ext::expand_macro_recursively; use crate::{ - DisplayPoint, Editor, EditorMode, FoldPlaceholder, MultiBuffer, SelectionEffects, + DisplayPoint, Editor, EditorMode, FoldPlaceholder, MultiBuffer, display_map::{ Block, BlockPlacement, CustomBlockId, DisplayMap, DisplayRow, DisplaySnapshot, ToDisplayPoint, @@ -93,9 +93,7 @@ pub fn select_ranges( ) { let (unmarked_text, text_ranges) = marked_text_ranges(marked_text, true); assert_eq!(editor.text(cx), unmarked_text); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges(text_ranges) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges(text_ranges)); } #[track_caller] diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rs index bdf73da5fb..195abbe6d9 100644 --- a/crates/editor/src/test/editor_test_context.rs +++ b/crates/editor/src/test/editor_test_context.rs @@ -1,5 +1,5 @@ use crate::{ - AnchorRangeExt, DisplayPoint, Editor, MultiBuffer, RowExt, + AnchorRangeExt, Autoscroll, DisplayPoint, Editor, MultiBuffer, RowExt, display_map::{HighlightKey, ToDisplayPoint}, }; use buffer_diff::DiffHunkStatusKind; @@ -362,7 +362,7 @@ impl EditorTestContext { let (unmarked_text, selection_ranges) = marked_text_ranges(marked_text, true); self.editor.update_in(&mut self.cx, |editor, window, cx| { editor.set_text(unmarked_text, window, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(selection_ranges) }) }); @@ -379,7 +379,7 @@ impl EditorTestContext { let (unmarked_text, selection_ranges) = marked_text_ranges(marked_text, true); self.editor.update_in(&mut self.cx, |editor, window, cx| { assert_eq!(editor.text(cx), unmarked_text); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(selection_ranges) }) }); diff --git a/crates/git_ui/src/commit_view.rs b/crates/git_ui/src/commit_view.rs index c8c237fe90..e07f84ba02 100644 --- a/crates/git_ui/src/commit_view.rs +++ b/crates/git_ui/src/commit_view.rs @@ -1,6 +1,6 @@ use anyhow::{Context as _, Result}; use buffer_diff::{BufferDiff, BufferDiffSnapshot}; -use editor::{Editor, EditorEvent, MultiBuffer, SelectionEffects}; +use editor::{Editor, EditorEvent, MultiBuffer}; use git::repository::{CommitDetails, CommitDiff, CommitSummary, RepoPath}; use gpui::{ AnyElement, AnyView, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, @@ -154,7 +154,7 @@ impl CommitView { }); editor.update(cx, |editor, cx| { editor.disable_header_for_buffer(metadata_buffer_id.unwrap(), cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges(vec![0..0]); }); }); diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index f858bea94c..371759bd24 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -8,7 +8,7 @@ use anyhow::Result; use buffer_diff::{BufferDiff, DiffHunkSecondaryStatus}; use collections::HashSet; use editor::{ - Editor, EditorEvent, SelectionEffects, + Editor, EditorEvent, actions::{GoToHunk, GoToPreviousHunk}, scroll::Autoscroll, }; @@ -255,14 +255,9 @@ impl ProjectDiff { fn move_to_path(&mut self, path_key: PathKey, window: &mut Window, cx: &mut Context) { if let Some(position) = self.multibuffer.read(cx).location_for_path(&path_key, cx) { self.editor.update(cx, |editor, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::focused()), - window, - cx, - |s| { - s.select_ranges([position..position]); - }, - ) + editor.change_selections(Some(Autoscroll::focused()), window, cx, |s| { + s.select_ranges([position..position]); + }) }); } else { self.pending_scroll = Some(path_key); @@ -468,7 +463,7 @@ impl ProjectDiff { self.editor.update(cx, |editor, cx| { if was_empty { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { // TODO select the very beginning (possibly inside a deletion) selections.select_ranges([0..0]) }); diff --git a/crates/go_to_line/src/go_to_line.rs b/crates/go_to_line/src/go_to_line.rs index 1ac933e316..bba9617975 100644 --- a/crates/go_to_line/src/go_to_line.rs +++ b/crates/go_to_line/src/go_to_line.rs @@ -2,8 +2,8 @@ pub mod cursor_position; use cursor_position::{LineIndicatorFormat, UserCaretPosition}; use editor::{ - Anchor, Editor, MultiBufferSnapshot, RowHighlightOptions, SelectionEffects, ToOffset, ToPoint, - actions::Tab, scroll::Autoscroll, + Anchor, Editor, MultiBufferSnapshot, RowHighlightOptions, ToOffset, ToPoint, actions::Tab, + scroll::Autoscroll, }; use gpui::{ App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Render, SharedString, Styled, @@ -249,12 +249,9 @@ impl GoToLine { let Some(start) = self.anchor_from_query(&snapshot, cx) else { return; }; - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| s.select_anchor_ranges([start..start]), - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_anchor_ranges([start..start]) + }); editor.focus_handle(cx).focus(window); cx.notify() }); diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rs index 4e9c887124..4ff793cbaf 100644 --- a/crates/inline_completion_button/src/inline_completion_button.rs +++ b/crates/inline_completion_button/src/inline_completion_button.rs @@ -2,7 +2,7 @@ use anyhow::Result; use client::{UserStore, zed_urls}; use copilot::{Copilot, Status}; use editor::{ - Editor, SelectionEffects, + Editor, actions::{ShowEditPrediction, ToggleEditPrediction}, scroll::Autoscroll, }; @@ -929,14 +929,9 @@ async fn open_disabled_globs_setting_in_editor( .map(|inner_match| inner_match.start()..inner_match.end()) }); if let Some(range) = range { - item.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), - window, - cx, - |selections| { - selections.select_ranges(vec![range]); - }, - ); + item.change_selections(Some(Autoscroll::newest()), window, cx, |selections| { + selections.select_ranges(vec![range]); + }); } })?; diff --git a/crates/journal/src/journal.rs b/crates/journal/src/journal.rs index 08bdb8e04f..0aed317a0b 100644 --- a/crates/journal/src/journal.rs +++ b/crates/journal/src/journal.rs @@ -1,7 +1,7 @@ use anyhow::Result; use chrono::{Datelike, Local, NaiveTime, Timelike}; +use editor::Editor; use editor::scroll::Autoscroll; -use editor::{Editor, SelectionEffects}; use gpui::{App, AppContext as _, Context, Window, actions}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -168,12 +168,9 @@ pub fn new_journal_entry(workspace: &Workspace, window: &mut Window, cx: &mut Ap if let Some(editor) = item.downcast::().map(|editor| editor.downgrade()) { editor.update_in(cx, |editor, window, cx| { let len = editor.buffer().read(cx).len(cx); - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| s.select_ranges([len..len]), - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_ranges([len..len]) + }); if len > 0 { editor.insert("\n\n", window, cx); } diff --git a/crates/language_tools/src/syntax_tree_view.rs b/crates/language_tools/src/syntax_tree_view.rs index 6f74e76e26..99132ce452 100644 --- a/crates/language_tools/src/syntax_tree_view.rs +++ b/crates/language_tools/src/syntax_tree_view.rs @@ -1,4 +1,4 @@ -use editor::{Anchor, Editor, ExcerptId, SelectionEffects, scroll::Autoscroll}; +use editor::{Anchor, Editor, ExcerptId, scroll::Autoscroll}; use gpui::{ App, AppContext as _, Context, Div, Entity, EventEmitter, FocusHandle, Focusable, Hsla, InteractiveElement, IntoElement, MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement, @@ -340,7 +340,7 @@ impl Render for SyntaxTreeView { mem::swap(&mut range.start, &mut range.end); editor.change_selections( - SelectionEffects::scroll(Autoscroll::newest()), + Some(Autoscroll::newest()), window, cx, |selections| { selections.select_ranges(vec![range]); diff --git a/crates/markdown_preview/src/markdown_preview_view.rs b/crates/markdown_preview/src/markdown_preview_view.rs index f22671d5df..bf1a1da572 100644 --- a/crates/markdown_preview/src/markdown_preview_view.rs +++ b/crates/markdown_preview/src/markdown_preview_view.rs @@ -4,7 +4,7 @@ use std::{ops::Range, path::PathBuf}; use anyhow::Result; use editor::scroll::Autoscroll; -use editor::{Editor, EditorEvent, SelectionEffects}; +use editor::{Editor, EditorEvent}; use gpui::{ App, ClickEvent, Context, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement, IntoElement, ListState, ParentElement, Render, RetainAllImageCache, Styled, Subscription, Task, @@ -468,12 +468,9 @@ impl MarkdownPreviewView { ) { if let Some(state) = &self.active_editor { state.editor.update(cx, |editor, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |selections| selections.select_ranges(vec![selection]), - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |selections| { + selections.select_ranges(vec![selection]) + }); window.focus(&editor.focus_handle(cx)); }); } diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rs index 8c5e78d77b..3fec1d616a 100644 --- a/crates/outline/src/outline.rs +++ b/crates/outline/src/outline.rs @@ -4,8 +4,8 @@ use std::{ sync::Arc, }; +use editor::RowHighlightOptions; use editor::{Anchor, AnchorRangeExt, Editor, scroll::Autoscroll}; -use editor::{RowHighlightOptions, SelectionEffects}; use fuzzy::StringMatch; use gpui::{ App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, HighlightStyle, @@ -288,12 +288,9 @@ impl PickerDelegate for OutlineViewDelegate { .highlighted_rows::() .next(); if let Some((rows, _)) = highlight { - active_editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| s.select_ranges([rows.start..rows.start]), - ); + active_editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_ranges([rows.start..rows.start]) + }); active_editor.clear_row_highlights::(); window.focus(&active_editor.focus_handle(cx)); } diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 0be05d4589..5bb771c1e9 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -19,10 +19,10 @@ use collections::{BTreeSet, HashMap, HashSet, hash_map}; use db::kvp::KEY_VALUE_STORE; use editor::{ AnchorRangeExt, Bias, DisplayPoint, Editor, EditorEvent, EditorSettings, ExcerptId, - ExcerptRange, MultiBufferSnapshot, RangeToAnchorExt, SelectionEffects, ShowScrollbar, + ExcerptRange, MultiBufferSnapshot, RangeToAnchorExt, ShowScrollbar, display_map::ToDisplayPoint, items::{entry_git_aware_label_color, entry_label_color}, - scroll::{Autoscroll, ScrollAnchor, ScrollbarAutoHide}, + scroll::{Autoscroll, AutoscrollStrategy, ScrollAnchor, ScrollbarAutoHide}, }; use file_icons::FileIcons; use fuzzy::{StringMatch, StringMatchCandidate, match_strings}; @@ -1099,7 +1099,7 @@ impl OutlinePanel { if change_selection { active_editor.update(cx, |editor, cx| { editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), + Some(Autoscroll::Strategy(AutoscrollStrategy::Center, None)), window, cx, |s| s.select_ranges(Some(anchor..anchor)), diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 4a122ac731..c1ebe25538 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -4,7 +4,7 @@ pub mod popover_menu; use anyhow::Result; use editor::{ - Editor, SelectionEffects, + Editor, actions::{MoveDown, MoveUp}, scroll::Autoscroll, }; @@ -695,12 +695,9 @@ impl Picker { editor.update(cx, |editor, cx| { editor.set_text(query, window, cx); let editor_offset = editor.buffer().read(cx).len(cx); - editor.change_selections( - SelectionEffects::scroll(Autoscroll::Next), - window, - cx, - |s| s.select_ranges(Some(editor_offset..editor_offset)), - ); + editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { + s.select_ranges(Some(editor_offset..editor_offset)) + }); }); } } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 4db83bcf4c..3bcc881f9d 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -12,7 +12,7 @@ use editor::{ entry_diagnostic_aware_icon_decoration_and_color, entry_diagnostic_aware_icon_name_and_color, entry_git_aware_label_color, }, - scroll::ScrollbarAutoHide, + scroll::{Autoscroll, ScrollbarAutoHide}, }; use file_icons::FileIcons; use git::status::GitSummary; @@ -1589,7 +1589,7 @@ impl ProjectPanel { }); self.filename_editor.update(cx, |editor, cx| { editor.set_text(file_name, window, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([selection]) }); window.focus(&editor.focus_handle(cx)); diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index 47aed8f470..a9ba14264f 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -1,4 +1,4 @@ -use editor::{Bias, Editor, SelectionEffects, scroll::Autoscroll, styled_runs_for_code_label}; +use editor::{Bias, Editor, scroll::Autoscroll, styled_runs_for_code_label}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ App, Context, DismissEvent, Entity, FontWeight, ParentElement, StyledText, Task, WeakEntity, @@ -136,12 +136,9 @@ impl PickerDelegate for ProjectSymbolsDelegate { workspace.open_project_item::(pane, buffer, true, true, window, cx); editor.update(cx, |editor, cx| { - editor.change_selections( - SelectionEffects::scroll(Autoscroll::center()), - window, - cx, - |s| s.select_ranges([position..position]), - ); + editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { + s.select_ranges([position..position]) + }); }); })?; anyhow::Ok(()) diff --git a/crates/repl/src/session.rs b/crates/repl/src/session.rs index 18d41f3eae..20518fb12c 100644 --- a/crates/repl/src/session.rs +++ b/crates/repl/src/session.rs @@ -8,7 +8,6 @@ use crate::{ }; use anyhow::Context as _; use collections::{HashMap, HashSet}; -use editor::SelectionEffects; use editor::{ Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToPoint, display_map::{ @@ -478,7 +477,7 @@ impl Session { if move_down { editor.update(cx, move |editor, cx| { editor.change_selections( - SelectionEffects::scroll(Autoscroll::top_relative(8)), + Some(Autoscroll::top_relative(8)), window, cx, |selections| { diff --git a/crates/rules_library/src/rules_library.rs b/crates/rules_library/src/rules_library.rs index 5e249162d3..231647ef5a 100644 --- a/crates/rules_library/src/rules_library.rs +++ b/crates/rules_library/src/rules_library.rs @@ -1,6 +1,6 @@ use anyhow::Result; use collections::{HashMap, HashSet}; -use editor::{CompletionProvider, SelectionEffects}; +use editor::CompletionProvider; use editor::{CurrentLineHighlight, Editor, EditorElement, EditorEvent, EditorStyle, actions::Tab}; use gpui::{ Action, App, Bounds, Entity, EventEmitter, Focusable, PromptLevel, Subscription, Task, @@ -895,15 +895,10 @@ impl RulesLibrary { } EditorEvent::Blurred => { title_editor.update(cx, |title_editor, cx| { - title_editor.change_selections( - SelectionEffects::no_scroll(), - window, - cx, - |selections| { - let cursor = selections.oldest_anchor().head(); - selections.select_anchor_ranges([cursor..cursor]); - }, - ); + title_editor.change_selections(None, window, cx, |selections| { + let cursor = selections.oldest_anchor().head(); + selections.select_anchor_ranges([cursor..cursor]); + }); }); } _ => {} @@ -925,15 +920,10 @@ impl RulesLibrary { } EditorEvent::Blurred => { body_editor.update(cx, |body_editor, cx| { - body_editor.change_selections( - SelectionEffects::no_scroll(), - window, - cx, - |selections| { - let cursor = selections.oldest_anchor().head(); - selections.select_anchor_ranges([cursor..cursor]); - }, - ); + body_editor.change_selections(None, window, cx, |selections| { + let cursor = selections.oldest_anchor().head(); + selections.select_anchor_ranges([cursor..cursor]); + }); }); } _ => {} diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 715cb451dd..fa7a3ba915 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1540,10 +1540,7 @@ mod tests { use std::ops::Range; use super::*; - use editor::{ - DisplayPoint, Editor, MultiBuffer, SearchSettings, SelectionEffects, - display_map::DisplayRow, - }; + use editor::{DisplayPoint, Editor, MultiBuffer, SearchSettings, display_map::DisplayRow}; use gpui::{Hsla, TestAppContext, UpdateGlobal, VisualTestContext}; use language::{Buffer, Point}; use project::Project; @@ -1680,7 +1677,7 @@ mod tests { }); editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0) ]) @@ -1767,7 +1764,7 @@ mod tests { // Park the cursor in between matches and ensure that going to the previous match selects // the closest match to the left. editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0) ]) @@ -1788,7 +1785,7 @@ mod tests { // Park the cursor in between matches and ensure that going to the next match selects the // closest match to the right. editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0) ]) @@ -1809,7 +1806,7 @@ mod tests { // Park the cursor after the last match and ensure that going to the previous match selects // the last match. editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 60) ]) @@ -1830,7 +1827,7 @@ mod tests { // Park the cursor after the last match and ensure that going to the next match selects the // first match. editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 60) ]) @@ -1851,7 +1848,7 @@ mod tests { // Park the cursor before the first match and ensure that going to the previous match // selects the last match. editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([ DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0) ]) @@ -2628,7 +2625,7 @@ mod tests { }); editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(vec![Point::new(1, 0)..Point::new(2, 4)]) }) }); @@ -2711,7 +2708,7 @@ mod tests { }); editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(vec![ Point::new(1, 0)..Point::new(1, 4), Point::new(5, 3)..Point::new(6, 4), diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index fd2cc3a1ce..8e1ea3d773 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -7,7 +7,7 @@ use anyhow::Context as _; use collections::{HashMap, HashSet}; use editor::{ Anchor, Editor, EditorElement, EditorEvent, EditorSettings, EditorStyle, MAX_TAB_TITLE_LEN, - MultiBuffer, SelectionEffects, actions::SelectAll, items::active_match_index, + MultiBuffer, actions::SelectAll, items::active_match_index, scroll::Autoscroll, }; use futures::{StreamExt, stream::FuturesOrdered}; use gpui::{ @@ -1303,7 +1303,7 @@ impl ProjectSearchView { self.results_editor.update(cx, |editor, cx| { let range_to_select = editor.range_for_match(&range_to_select); editor.unfold_ranges(std::slice::from_ref(&range_to_select), false, true, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([range_to_select]) }); }); @@ -1350,9 +1350,7 @@ impl ProjectSearchView { fn focus_results_editor(&mut self, window: &mut Window, cx: &mut Context) { self.query_editor.update(cx, |query_editor, cx| { let cursor = query_editor.selections.newest_anchor().head(); - query_editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges([cursor..cursor]) - }); + query_editor.change_selections(None, window, cx, |s| s.select_ranges([cursor..cursor])); }); let results_handle = self.results_editor.focus_handle(cx); window.focus(&results_handle); @@ -1372,7 +1370,7 @@ impl ProjectSearchView { let range_to_select = match_ranges .first() .map(|range| editor.range_for_match(range)); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(range_to_select) }); editor.scroll(Point::default(), Some(Axis::Vertical), window, cx); diff --git a/crates/tasks_ui/src/modal.rs b/crates/tasks_ui/src/modal.rs index 1510f613e3..d3b8d927b3 100644 --- a/crates/tasks_ui/src/modal.rs +++ b/crates/tasks_ui/src/modal.rs @@ -751,7 +751,7 @@ fn string_match_candidates<'a>( mod tests { use std::{path::PathBuf, sync::Arc}; - use editor::{Editor, SelectionEffects}; + use editor::Editor; use gpui::{TestAppContext, VisualTestContext}; use language::{Language, LanguageConfig, LanguageMatcher, Point}; use project::{ContextProviderWithTasks, FakeFs, Project}; @@ -1028,7 +1028,7 @@ mod tests { .update(|_window, cx| second_item.act_as::(cx)) .unwrap(); editor.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(Some(Point::new(1, 2)..Point::new(1, 5))) }) }); diff --git a/crates/tasks_ui/src/tasks_ui.rs b/crates/tasks_ui/src/tasks_ui.rs index 0b3f70e6bc..acdc7d0298 100644 --- a/crates/tasks_ui/src/tasks_ui.rs +++ b/crates/tasks_ui/src/tasks_ui.rs @@ -393,7 +393,7 @@ fn worktree_context(worktree_abs_path: &Path) -> TaskContext { mod tests { use std::{collections::HashMap, sync::Arc}; - use editor::{Editor, SelectionEffects}; + use editor::Editor; use gpui::TestAppContext; use language::{Language, LanguageConfig}; use project::{BasicContextProvider, FakeFs, Project, task_store::TaskStore}; @@ -538,7 +538,7 @@ mod tests { // And now, let's select an identifier. editor2.update_in(cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| { + editor.change_selections(None, window, cx, |selections| { selections.select_ranges([14..18]) }) }); diff --git a/crates/vim/src/change_list.rs b/crates/vim/src/change_list.rs index 25da3e09b8..3332239631 100644 --- a/crates/vim/src/change_list.rs +++ b/crates/vim/src/change_list.rs @@ -1,4 +1,4 @@ -use editor::{Bias, Direction, Editor, display_map::ToDisplayPoint, movement}; +use editor::{Bias, Direction, Editor, display_map::ToDisplayPoint, movement, scroll::Autoscroll}; use gpui::{Context, Window, actions}; use crate::{Vim, state::Mode}; @@ -29,7 +29,7 @@ impl Vim { .next_change(count, direction) .map(|s| s.to_vec()) { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let map = s.display_map(); s.select_display_ranges(selections.iter().map(|a| { let point = a.to_display_point(&map); diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index 839a0392d4..40e8fcffa3 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -2,9 +2,10 @@ use anyhow::Result; use collections::{HashMap, HashSet}; use command_palette_hooks::CommandInterceptResult; use editor::{ - Bias, Editor, SelectionEffects, ToPoint, + Bias, Editor, ToPoint, actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive}, display_map::ToDisplayPoint, + scroll::Autoscroll, }; use gpui::{Action, App, AppContext as _, Context, Global, Window, actions}; use itertools::Itertools; @@ -421,7 +422,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context) { let target = snapshot .buffer_snapshot .clip_point(Point::new(buffer_row.0, current.head().column), Bias::Left); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([target..target]); }); @@ -492,7 +493,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context) { .disjoint_anchor_ranges() .collect::>() }); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { let end = Point::new(range.end.0, s.buffer().line_len(range.end)); s.select_ranges([end..Point::new(range.start.0, 0)]); }); @@ -502,7 +503,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context) { window.dispatch_action(action.action.boxed_clone(), cx); cx.defer_in(window, move |vim, window, cx| { vim.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { if let Some(previous_selections) = previous_selections { s.select_ranges(previous_selections); } else { @@ -1454,20 +1455,15 @@ impl OnMatchingLines { editor .update_in(cx, |editor, window, cx| { editor.start_transaction_at(Instant::now(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.replace_cursors_with(|_| new_selections); }); window.dispatch_action(action, cx); cx.defer_in(window, move |editor, window, cx| { let newest = editor.selections.newest::(cx).clone(); - editor.change_selections( - SelectionEffects::no_scroll(), - window, - cx, - |s| { - s.select(vec![newest]); - }, - ); + editor.change_selections(None, window, cx, |s| { + s.select(vec![newest]); + }); editor.end_transaction_at(Instant::now(), cx); }) }) @@ -1570,7 +1566,7 @@ impl Vim { ) .unwrap_or((start.range(), MotionKind::Exclusive)); if range.start != start.start { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ range.start.to_point(&snapshot)..range.start.to_point(&snapshot) ]); @@ -1610,7 +1606,7 @@ impl Vim { .range(&snapshot, start.clone(), around) .unwrap_or(start.range()); if range.start != start.start { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges([ range.start.to_point(&snapshot)..range.start.to_point(&snapshot) ]); @@ -1803,7 +1799,7 @@ impl ShellExec { editor.transact(window, cx, |editor, window, cx| { editor.edit([(range.clone(), text)], cx); let snapshot = editor.buffer().read(cx).snapshot(cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let point = if is_read { let point = range.end.to_point(&snapshot); Point::new(point.row.saturating_sub(1), 0) diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs index d0bbf5f17f..d5312934e4 100644 --- a/crates/vim/src/helix.rs +++ b/crates/vim/src/helix.rs @@ -1,4 +1,4 @@ -use editor::{DisplayPoint, Editor, movement}; +use editor::{DisplayPoint, Editor, movement, scroll::Autoscroll}; use gpui::{Action, actions}; use gpui::{Context, Window}; use language::{CharClassifier, CharKind}; @@ -47,7 +47,7 @@ impl Vim { mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool, ) { self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let times = times.unwrap_or(1); let new_goal = SelectionGoal::None; @@ -100,7 +100,7 @@ impl Vim { mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool, ) { self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let times = times.unwrap_or(1); let new_goal = SelectionGoal::None; @@ -161,7 +161,7 @@ impl Vim { ) { self.update_editor(window, cx, |_, editor, window, cx| { let text_layout_details = editor.text_layout_details(window); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let goal = selection.goal; let cursor = if selection.is_empty() || selection.reversed { @@ -239,7 +239,7 @@ impl Vim { Motion::FindForward { .. } => { self.update_editor(window, cx, |_, editor, window, cx| { let text_layout_details = editor.text_layout_details(window); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let goal = selection.goal; let cursor = if selection.is_empty() || selection.reversed { @@ -266,7 +266,7 @@ impl Vim { Motion::FindBackward { .. } => { self.update_editor(window, cx, |_, editor, window, cx| { let text_layout_details = editor.text_layout_details(window); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let goal = selection.goal; let cursor = if selection.is_empty() || selection.reversed { diff --git a/crates/vim/src/indent.rs b/crates/vim/src/indent.rs index c8762c563a..ac708a7e89 100644 --- a/crates/vim/src/indent.rs +++ b/crates/vim/src/indent.rs @@ -1,6 +1,5 @@ use crate::{Vim, motion::Motion, object::Object, state::Mode}; use collections::HashMap; -use editor::SelectionEffects; use editor::{Bias, Editor, display_map::ToDisplayPoint}; use gpui::actions; use gpui::{Context, Window}; @@ -89,7 +88,7 @@ impl Vim { let text_layout_details = editor.text_layout_details(window); editor.transact(window, cx, |editor, window, cx| { let mut selection_starts: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); selection_starts.insert(selection.id, anchor); @@ -107,7 +106,7 @@ impl Vim { IndentDirection::Out => editor.outdent(&Default::default(), window, cx), IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx), } - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = selection_starts.remove(&selection.id).unwrap(); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); @@ -129,7 +128,7 @@ impl Vim { self.update_editor(window, cx, |_, editor, window, cx| { editor.transact(window, cx, |editor, window, cx| { let mut original_positions: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); original_positions.insert(selection.id, anchor); @@ -141,7 +140,7 @@ impl Vim { IndentDirection::Out => editor.outdent(&Default::default(), window, cx), IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx), } - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = original_positions.remove(&selection.id).unwrap(); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); diff --git a/crates/vim/src/insert.rs b/crates/vim/src/insert.rs index 7b38bed2be..a30af8769f 100644 --- a/crates/vim/src/insert.rs +++ b/crates/vim/src/insert.rs @@ -1,5 +1,5 @@ use crate::{Vim, state::Mode}; -use editor::{Bias, Editor}; +use editor::{Bias, Editor, scroll::Autoscroll}; use gpui::{Action, Context, Window, actions}; use language::SelectionGoal; use settings::Settings; @@ -34,7 +34,7 @@ impl Vim { editor.dismiss_menus_and_popups(false, window, cx); if !HelixModeSetting::get_global(cx).0 { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, mut cursor, _| { *cursor.column_mut() = cursor.column().saturating_sub(1); (map.clip_point(cursor, Bias::Left), SelectionGoal::None) diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 2a6e5196bc..e9b01f5a67 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -4,6 +4,7 @@ use editor::{ movement::{ self, FindRange, TextLayoutDetails, find_boundary, find_preceding_boundary_display_point, }, + scroll::Autoscroll, }; use gpui::{Action, Context, Window, actions, px}; use language::{CharKind, Point, Selection, SelectionGoal}; @@ -625,7 +626,7 @@ impl Vim { Mode::Visual | Mode::VisualLine | Mode::VisualBlock => { if !prior_selections.is_empty() { self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(prior_selections.iter().cloned()) }) }); diff --git a/crates/vim/src/normal.rs b/crates/vim/src/normal.rs index 2003c8b754..1d70227e0b 100644 --- a/crates/vim/src/normal.rs +++ b/crates/vim/src/normal.rs @@ -26,6 +26,7 @@ use collections::BTreeSet; use convert::ConvertTarget; use editor::Bias; use editor::Editor; +use editor::scroll::Autoscroll; use editor::{Anchor, SelectionEffects}; use editor::{display_map::ToDisplayPoint, movement}; use gpui::{Context, Window, actions}; @@ -102,7 +103,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context) { Vim::action(editor, cx, |vim, _: &HelixDelete, window, cx| { vim.record_current_action(cx); vim.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { if selection.is_empty() { selection.end = movement::right(map, selection.end) @@ -376,7 +377,7 @@ impl Vim { self.start_recording(cx); self.switch_mode(Mode::Insert, false, window, cx); self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, cursor, _| (right(map, cursor, 1), SelectionGoal::None)); }); }); @@ -387,7 +388,7 @@ impl Vim { if self.mode.is_visual() { let current_mode = self.mode; self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if current_mode == Mode::VisualLine { let start_of_line = motion::start_of_line(map, false, selection.start); @@ -411,7 +412,7 @@ impl Vim { self.start_recording(cx); self.switch_mode(Mode::Insert, false, window, cx); self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, cursor, _| { ( first_non_whitespace(map, false, cursor), @@ -431,7 +432,7 @@ impl Vim { self.start_recording(cx); self.switch_mode(Mode::Insert, false, window, cx); self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, cursor, _| { (next_line_end(map, cursor, 1), SelectionGoal::None) }); @@ -452,7 +453,7 @@ impl Vim { return; }; - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges(marks.iter().map(|mark| *mark..*mark)) }); }); @@ -488,7 +489,7 @@ impl Vim { }) .collect::>(); editor.edit_with_autoindent(edits, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, cursor, _| { let previous_line = motion::start_of_relative_buffer_row(map, cursor, -1); let insert_point = motion::end_of_line(map, false, previous_line, 1); @@ -529,7 +530,7 @@ impl Vim { (end_of_line..end_of_line, "\n".to_string() + &indent) }) .collect::>(); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.maybe_move_cursors_with(|map, cursor, goal| { Motion::CurrentLine.move_point( map, @@ -606,7 +607,7 @@ impl Vim { .collect::>(); editor.edit(edits, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|_, selection| { if let Some(position) = original_positions.get(&selection.id) { selection.collapse_to(*position, SelectionGoal::None); @@ -754,7 +755,7 @@ impl Vim { editor.newline(&editor::actions::Newline, window, cx); } editor.set_clip_at_line_ends(true, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let point = movement::saturating_left(map, selection.head()); selection.collapse_to(point, SelectionGoal::None) @@ -790,7 +791,7 @@ impl Vim { cx: &mut Context, mut positions: HashMap, ) { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if let Some(anchor) = positions.remove(&selection.id) { selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); diff --git a/crates/vim/src/normal/change.rs b/crates/vim/src/normal/change.rs index da8d38ea13..e6ecf309f1 100644 --- a/crates/vim/src/normal/change.rs +++ b/crates/vim/src/normal/change.rs @@ -8,6 +8,7 @@ use editor::{ Bias, DisplayPoint, display_map::{DisplaySnapshot, ToDisplayPoint}, movement::TextLayoutDetails, + scroll::Autoscroll, }; use gpui::{Context, Window}; use language::Selection; @@ -39,7 +40,7 @@ impl Vim { editor.transact(window, cx, |editor, window, cx| { // We are swapping to insert mode anyway. Just set the line end clipping behavior now editor.set_clip_at_line_ends(false, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let kind = match motion { Motion::NextWordStart { ignore_punctuation } @@ -113,7 +114,7 @@ impl Vim { // We are swapping to insert mode anyway. Just set the line end clipping behavior now editor.set_clip_at_line_ends(false, cx); editor.transact(window, cx, |editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { objects_found |= object.expand_selection(map, selection, around); }); diff --git a/crates/vim/src/normal/convert.rs b/crates/vim/src/normal/convert.rs index 4621e3ab89..5295e79edb 100644 --- a/crates/vim/src/normal/convert.rs +++ b/crates/vim/src/normal/convert.rs @@ -1,5 +1,5 @@ use collections::HashMap; -use editor::{SelectionEffects, display_map::ToDisplayPoint}; +use editor::{display_map::ToDisplayPoint, scroll::Autoscroll}; use gpui::{Context, Window}; use language::{Bias, Point, SelectionGoal}; use multi_buffer::MultiBufferRow; @@ -36,7 +36,7 @@ impl Vim { let text_layout_details = editor.text_layout_details(window); editor.transact(window, cx, |editor, window, cx| { let mut selection_starts: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Left); selection_starts.insert(selection.id, anchor); @@ -66,7 +66,7 @@ impl Vim { editor.convert_to_rot47(&Default::default(), window, cx) } } - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = selection_starts.remove(&selection.id).unwrap(); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); @@ -90,7 +90,7 @@ impl Vim { editor.transact(window, cx, |editor, window, cx| { editor.set_clip_at_line_ends(false, cx); let mut original_positions: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { object.expand_selection(map, selection, around); original_positions.insert( @@ -116,7 +116,7 @@ impl Vim { editor.convert_to_rot47(&Default::default(), window, cx) } } - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = original_positions.remove(&selection.id).unwrap(); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); @@ -239,7 +239,7 @@ impl Vim { .collect::(); editor.edit([(range, text)], cx) } - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(cursor_positions) }) }); diff --git a/crates/vim/src/normal/delete.rs b/crates/vim/src/normal/delete.rs index 141346c99f..f52d9bebe0 100644 --- a/crates/vim/src/normal/delete.rs +++ b/crates/vim/src/normal/delete.rs @@ -7,6 +7,7 @@ use collections::{HashMap, HashSet}; use editor::{ Bias, DisplayPoint, display_map::{DisplaySnapshot, ToDisplayPoint}, + scroll::Autoscroll, }; use gpui::{Context, Window}; use language::{Point, Selection}; @@ -29,7 +30,7 @@ impl Vim { let mut original_columns: HashMap<_, _> = Default::default(); let mut motion_kind = None; let mut ranges_to_copy = Vec::new(); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let original_head = selection.head(); original_columns.insert(selection.id, original_head.column()); @@ -70,7 +71,7 @@ impl Vim { // Fixup cursor position after the deletion editor.set_clip_at_line_ends(true, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let mut cursor = selection.head(); if kind.linewise() { @@ -101,7 +102,7 @@ impl Vim { // Emulates behavior in vim where if we expanded backwards to include a newline // the cursor gets set back to the start of the line let mut should_move_to_start: HashSet<_> = Default::default(); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { object.expand_selection(map, selection, around); let offset_range = selection.map(|p| p.to_offset(map, Bias::Left)).range(); @@ -158,7 +159,7 @@ impl Vim { // Fixup cursor position after the deletion editor.set_clip_at_line_ends(true, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let mut cursor = selection.head(); if should_move_to_start.contains(&selection.id) { diff --git a/crates/vim/src/normal/increment.rs b/crates/vim/src/normal/increment.rs index 09e6e85a5c..e2a0d28267 100644 --- a/crates/vim/src/normal/increment.rs +++ b/crates/vim/src/normal/increment.rs @@ -1,4 +1,4 @@ -use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint}; +use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint, scroll::Autoscroll}; use gpui::{Action, Context, Window}; use language::{Bias, Point}; use schemars::JsonSchema; @@ -97,7 +97,7 @@ impl Vim { editor.edit(edits, cx); let snapshot = editor.buffer().read(cx).snapshot(cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let mut new_ranges = Vec::new(); for (visual, anchor) in new_anchors.iter() { let mut point = anchor.to_point(&snapshot); diff --git a/crates/vim/src/normal/mark.rs b/crates/vim/src/normal/mark.rs index 57a6108841..af4b71f427 100644 --- a/crates/vim/src/normal/mark.rs +++ b/crates/vim/src/normal/mark.rs @@ -4,6 +4,7 @@ use editor::{ Anchor, Bias, DisplayPoint, Editor, MultiBuffer, display_map::{DisplaySnapshot, ToDisplayPoint}, movement, + scroll::Autoscroll, }; use gpui::{Context, Entity, EntityId, UpdateGlobal, Window}; use language::SelectionGoal; @@ -115,7 +116,7 @@ impl Vim { } } - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges(ranges) }); }) @@ -168,7 +169,7 @@ impl Vim { } }) .collect(); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(points.into_iter().map(|p| p..p)) }) }) @@ -250,7 +251,7 @@ impl Vim { } if !should_jump && !ranges.is_empty() { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges(ranges) }); } diff --git a/crates/vim/src/normal/paste.rs b/crates/vim/src/normal/paste.rs index 0dade838f5..41337f0707 100644 --- a/crates/vim/src/normal/paste.rs +++ b/crates/vim/src/normal/paste.rs @@ -1,4 +1,4 @@ -use editor::{DisplayPoint, RowExt, SelectionEffects, display_map::ToDisplayPoint, movement}; +use editor::{DisplayPoint, RowExt, display_map::ToDisplayPoint, movement, scroll::Autoscroll}; use gpui::{Action, Context, Window}; use language::{Bias, SelectionGoal}; use schemars::JsonSchema; @@ -187,7 +187,7 @@ impl Vim { // and put the cursor on the first non-blank character of the first inserted line (or at the end if the first line is blank). // otherwise vim will insert the next text at (or before) the current cursor position, // the cursor will go to the last (or first, if is_multiline) inserted character. - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.replace_cursors_with(|map| { let mut cursors = Vec::new(); for (anchor, line_mode, is_multiline) in &new_selections { @@ -238,7 +238,7 @@ impl Vim { self.update_editor(window, cx, |_, editor, window, cx| { editor.transact(window, cx, |editor, window, cx| { editor.set_clip_at_line_ends(false, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { object.expand_selection(map, selection, around); }); @@ -252,7 +252,7 @@ impl Vim { }; editor.insert(&text, window, cx); editor.set_clip_at_line_ends(true, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { selection.start = map.clip_point(selection.start, Bias::Left); selection.end = selection.start @@ -276,7 +276,7 @@ impl Vim { let text_layout_details = editor.text_layout_details(window); editor.transact(window, cx, |editor, window, cx| { editor.set_clip_at_line_ends(false, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { motion.expand_selection( map, @@ -296,7 +296,7 @@ impl Vim { }; editor.insert(&text, window, cx); editor.set_clip_at_line_ends(true, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { selection.start = map.clip_point(selection.start, Bias::Left); selection.end = selection.start diff --git a/crates/vim/src/normal/substitute.rs b/crates/vim/src/normal/substitute.rs index 96df61e528..1199356995 100644 --- a/crates/vim/src/normal/substitute.rs +++ b/crates/vim/src/normal/substitute.rs @@ -1,4 +1,4 @@ -use editor::{Editor, SelectionEffects, movement}; +use editor::{Editor, movement}; use gpui::{Context, Window, actions}; use language::Point; @@ -41,7 +41,7 @@ impl Vim { editor.set_clip_at_line_ends(false, cx); editor.transact(window, cx, |editor, window, cx| { let text_layout_details = editor.text_layout_details(window); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { if selection.start == selection.end { Motion::Right.expand_selection( diff --git a/crates/vim/src/normal/toggle_comments.rs b/crates/vim/src/normal/toggle_comments.rs index 3b578c44cb..1df381acbe 100644 --- a/crates/vim/src/normal/toggle_comments.rs +++ b/crates/vim/src/normal/toggle_comments.rs @@ -1,6 +1,6 @@ use crate::{Vim, motion::Motion, object::Object}; use collections::HashMap; -use editor::{Bias, SelectionEffects, display_map::ToDisplayPoint}; +use editor::{Bias, display_map::ToDisplayPoint}; use gpui::{Context, Window}; use language::SelectionGoal; @@ -18,7 +18,7 @@ impl Vim { let text_layout_details = editor.text_layout_details(window); editor.transact(window, cx, |editor, window, cx| { let mut selection_starts: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); selection_starts.insert(selection.id, anchor); @@ -32,7 +32,7 @@ impl Vim { }); }); editor.toggle_comments(&Default::default(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = selection_starts.remove(&selection.id).unwrap(); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); @@ -53,7 +53,7 @@ impl Vim { self.update_editor(window, cx, |_, editor, window, cx| { editor.transact(window, cx, |editor, window, cx| { let mut original_positions: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); original_positions.insert(selection.id, anchor); @@ -61,7 +61,7 @@ impl Vim { }); }); editor.toggle_comments(&Default::default(), window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = original_positions.remove(&selection.id).unwrap(); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); diff --git a/crates/vim/src/normal/yank.rs b/crates/vim/src/normal/yank.rs index 6beb81b2b6..3525b0d43f 100644 --- a/crates/vim/src/normal/yank.rs +++ b/crates/vim/src/normal/yank.rs @@ -7,7 +7,7 @@ use crate::{ state::{Mode, Register}, }; use collections::HashMap; -use editor::{ClipboardSelection, Editor, SelectionEffects}; +use editor::{ClipboardSelection, Editor}; use gpui::Context; use gpui::Window; use language::Point; @@ -31,7 +31,7 @@ impl Vim { editor.set_clip_at_line_ends(false, cx); let mut original_positions: HashMap<_, _> = Default::default(); let mut kind = None; - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let original_position = (selection.head(), selection.goal); kind = motion.expand_selection( @@ -51,7 +51,7 @@ impl Vim { }); let Some(kind) = kind else { return }; vim.yank_selections_content(editor, kind, window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|_, selection| { let (head, goal) = original_positions.remove(&selection.id).unwrap(); selection.collapse_to(head, goal); @@ -73,7 +73,7 @@ impl Vim { editor.transact(window, cx, |editor, window, cx| { editor.set_clip_at_line_ends(false, cx); let mut start_positions: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { object.expand_selection(map, selection, around); let start_position = (selection.start, selection.goal); @@ -81,7 +81,7 @@ impl Vim { }); }); vim.yank_selections_content(editor, MotionKind::Exclusive, window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|_, selection| { let (head, goal) = start_positions.remove(&selection.id).unwrap(); selection.collapse_to(head, goal); diff --git a/crates/vim/src/replace.rs b/crates/vim/src/replace.rs index bf0d977531..5f407db5cb 100644 --- a/crates/vim/src/replace.rs +++ b/crates/vim/src/replace.rs @@ -5,8 +5,8 @@ use crate::{ state::Mode, }; use editor::{ - Anchor, Bias, Editor, EditorSnapshot, SelectionEffects, ToOffset, ToPoint, - display_map::ToDisplayPoint, + Anchor, Bias, Editor, EditorSnapshot, ToOffset, ToPoint, display_map::ToDisplayPoint, + scroll::Autoscroll, }; use gpui::{Context, Window, actions}; use language::{Point, SelectionGoal}; @@ -72,7 +72,7 @@ impl Vim { editor.edit_with_block_indent(edits.clone(), Vec::new(), cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_anchor_ranges(edits.iter().map(|(range, _)| range.end..range.end)); }); editor.set_clip_at_line_ends(true, cx); @@ -124,7 +124,7 @@ impl Vim { editor.edit(edits, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_ranges(new_selections); }); editor.set_clip_at_line_ends(true, cx); @@ -251,7 +251,7 @@ impl Vim { } if let Some(position) = final_cursor_position { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|_map, selection| { selection.collapse_to(position, SelectionGoal::None); }); diff --git a/crates/vim/src/rewrap.rs b/crates/vim/src/rewrap.rs index e03a3308fc..b5d69ef0ae 100644 --- a/crates/vim/src/rewrap.rs +++ b/crates/vim/src/rewrap.rs @@ -1,6 +1,6 @@ use crate::{Vim, motion::Motion, object::Object, state::Mode}; use collections::HashMap; -use editor::{Bias, Editor, RewrapOptions, SelectionEffects, display_map::ToDisplayPoint}; +use editor::{Bias, Editor, RewrapOptions, display_map::ToDisplayPoint, scroll::Autoscroll}; use gpui::{Context, Window, actions}; use language::SelectionGoal; @@ -22,7 +22,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context) { }, cx, ); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if let Some(anchor) = positions.remove(&selection.id) { let mut point = anchor.to_display_point(map); @@ -53,7 +53,7 @@ impl Vim { let text_layout_details = editor.text_layout_details(window); editor.transact(window, cx, |editor, window, cx| { let mut selection_starts: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); selection_starts.insert(selection.id, anchor); @@ -73,7 +73,7 @@ impl Vim { }, cx, ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = selection_starts.remove(&selection.id).unwrap(); let mut point = anchor.to_display_point(map); @@ -96,7 +96,7 @@ impl Vim { self.update_editor(window, cx, |_, editor, window, cx| { editor.transact(window, cx, |editor, window, cx| { let mut original_positions: HashMap<_, _> = Default::default(); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); original_positions.insert(selection.id, anchor); @@ -110,7 +110,7 @@ impl Vim { }, cx, ); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let anchor = original_positions.remove(&selection.id).unwrap(); let mut point = anchor.to_display_point(map); diff --git a/crates/vim/src/surrounds.rs b/crates/vim/src/surrounds.rs index 852433bc8e..6697742e4d 100644 --- a/crates/vim/src/surrounds.rs +++ b/crates/vim/src/surrounds.rs @@ -4,7 +4,7 @@ use crate::{ object::Object, state::Mode, }; -use editor::{Bias, movement}; +use editor::{Bias, movement, scroll::Autoscroll}; use gpui::{Context, Window}; use language::BracketPair; @@ -109,7 +109,7 @@ impl Vim { editor.edit(edits, cx); editor.set_clip_at_line_ends(true, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { if mode == Mode::VisualBlock { s.select_anchor_ranges(anchors.into_iter().take(1)) } else { @@ -207,7 +207,7 @@ impl Vim { } } - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(anchors); }); edits.sort_by_key(|(range, _)| range.start); @@ -317,7 +317,7 @@ impl Vim { edits.sort_by_key(|(range, _)| range.start); editor.edit(edits, cx); editor.set_clip_at_line_ends(true, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_anchor_ranges(stable_anchors); }); }); @@ -375,7 +375,7 @@ impl Vim { anchors.push(start..start) } } - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(anchors); }); editor.set_clip_at_line_ends(true, cx); diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 2c2d60004e..6b5d41f12e 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -22,8 +22,7 @@ mod visual; use anyhow::Result; use collections::HashMap; use editor::{ - Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, SelectionEffects, - ToPoint, + Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, ToPoint, movement::{self, FindRange}, }; use gpui::{ @@ -964,7 +963,7 @@ impl Vim { } } - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { // we cheat with visual block mode and use multiple cursors. // the cost of this cheat is we need to convert back to a single // cursor whenever vim would. @@ -1164,7 +1163,7 @@ impl Vim { } else { self.update_editor(window, cx, |_, editor, window, cx| { editor.set_clip_at_line_ends(false, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|_, selection| { selection.collapse_to(selection.start, selection.goal) }) @@ -1439,29 +1438,27 @@ impl Vim { Mode::VisualLine | Mode::VisualBlock | Mode::Visual => { self.update_editor(window, cx, |vim, editor, window, cx| { let original_mode = vim.undo_modes.get(transaction_id); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - match original_mode { - Some(Mode::VisualLine) => { - s.move_with(|map, selection| { - selection.collapse_to( - map.prev_line_boundary(selection.start.to_point(map)).1, - SelectionGoal::None, - ) - }); - } - Some(Mode::VisualBlock) => { - let mut first = s.first_anchor(); - first.collapse_to(first.start, first.goal); - s.select_anchors(vec![first]); - } - _ => { - s.move_with(|map, selection| { - selection.collapse_to( - map.clip_at_line_end(selection.start), - selection.goal, - ); - }); - } + editor.change_selections(None, window, cx, |s| match original_mode { + Some(Mode::VisualLine) => { + s.move_with(|map, selection| { + selection.collapse_to( + map.prev_line_boundary(selection.start.to_point(map)).1, + SelectionGoal::None, + ) + }); + } + Some(Mode::VisualBlock) => { + let mut first = s.first_anchor(); + first.collapse_to(first.start, first.goal); + s.select_anchors(vec![first]); + } + _ => { + s.move_with(|map, selection| { + selection.collapse_to( + map.clip_at_line_end(selection.start), + selection.goal, + ); + }); } }); }); @@ -1469,7 +1466,7 @@ impl Vim { } Mode::Normal => { self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { selection .collapse_to(map.clip_at_line_end(selection.end), selection.goal) diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs index 2d72881b7a..29ef3943b5 100644 --- a/crates/vim/src/visual.rs +++ b/crates/vim/src/visual.rs @@ -2,9 +2,10 @@ use std::sync::Arc; use collections::HashMap; use editor::{ - Bias, DisplayPoint, Editor, SelectionEffects, + Bias, DisplayPoint, Editor, display_map::{DisplaySnapshot, ToDisplayPoint}, movement, + scroll::Autoscroll, }; use gpui::{Context, Window, actions}; use language::{Point, Selection, SelectionGoal}; @@ -132,7 +133,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context) { vim.update_editor(window, cx, |_, editor, window, cx| { editor.set_clip_at_line_ends(false, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let map = s.display_map(); let ranges = ranges .into_iter() @@ -186,7 +187,7 @@ impl Vim { motion.move_point(map, point, goal, times, &text_layout_details) }) } else { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let was_reversed = selection.reversed; let mut current_head = selection.head(); @@ -258,7 +259,7 @@ impl Vim { ) -> Option<(DisplayPoint, SelectionGoal)>, ) { let text_layout_details = editor.text_layout_details(window); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { let map = &s.display_map(); let mut head = s.newest_anchor().head().to_display_point(map); let mut tail = s.oldest_anchor().tail().to_display_point(map); @@ -374,7 +375,7 @@ impl Vim { } self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let mut mut_selection = selection.clone(); @@ -453,7 +454,7 @@ impl Vim { ) { self.update_editor(window, cx, |_, editor, window, cx| { editor.split_selection_into_lines(&Default::default(), window, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, cursor, _| { (next_line_end(map, cursor, 1), SelectionGoal::None) }); @@ -471,7 +472,7 @@ impl Vim { ) { self.update_editor(window, cx, |_, editor, window, cx| { editor.split_selection_into_lines(&Default::default(), window, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_cursors_with(|map, cursor, _| { ( first_non_whitespace(map, false, cursor), @@ -494,7 +495,7 @@ impl Vim { pub fn other_end(&mut self, _: &OtherEnd, window: &mut Window, cx: &mut Context) { self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|_, selection| { selection.reversed = !selection.reversed; }); @@ -510,7 +511,7 @@ impl Vim { ) { let mode = self.mode; self.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|_, selection| { selection.reversed = !selection.reversed; }); @@ -529,7 +530,7 @@ impl Vim { editor.selections.line_mode = false; editor.transact(window, cx, |editor, window, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { if line_mode { let mut position = selection.head(); @@ -566,7 +567,7 @@ impl Vim { vim.copy_selections_content(editor, kind, window, cx); if line_mode && vim.mode != Mode::VisualBlock { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let end = selection.end.to_point(map); let start = selection.start.to_point(map); @@ -586,7 +587,7 @@ impl Vim { // Fixup cursor position after the deletion editor.set_clip_at_line_ends(true, cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.move_with(|map, selection| { let mut cursor = selection.head().to_point(map); @@ -612,7 +613,7 @@ impl Vim { // For visual line mode, adjust selections to avoid yanking the next line when on \n if line_mode && vim.mode != Mode::VisualBlock { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { let start = selection.start.to_point(map); let end = selection.end.to_point(map); @@ -633,7 +634,7 @@ impl Vim { MotionKind::Exclusive }; vim.yank_selections_content(editor, kind, window, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.move_with(|map, selection| { if line_mode { selection.start = start_of_line(map, false, selection.start); @@ -686,9 +687,7 @@ impl Vim { } editor.edit(edits, cx); - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { - s.select_ranges(stable_anchors) - }); + editor.change_selections(None, window, cx, |s| s.select_ranges(stable_anchors)); }); }); self.switch_mode(Mode::Normal, false, window, cx); @@ -800,7 +799,7 @@ impl Vim { if direction == Direction::Prev { std::mem::swap(&mut start_selection, &mut end_selection); } - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges([start_selection..end_selection]); }); editor.set_collapse_matches(true); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index ea3f327ff0..2bbe3d0bcb 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -18,7 +18,7 @@ use client::zed_urls; use collections::VecDeque; use debugger_ui::debugger_panel::DebugPanel; use editor::ProposedChangesEditorToolbar; -use editor::{Editor, MultiBuffer}; +use editor::{Editor, MultiBuffer, scroll::Autoscroll}; use futures::future::Either; use futures::{StreamExt, channel::mpsc, select_biased}; use git_ui::git_panel::GitPanel; @@ -1125,7 +1125,7 @@ fn open_log_file(workspace: &mut Workspace, window: &mut Window, cx: &mut Contex editor.update(cx, |editor, cx| { let last_multi_buffer_offset = editor.buffer().read(cx).len(cx); - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_ranges(Some( last_multi_buffer_offset..last_multi_buffer_offset, )); @@ -1774,7 +1774,7 @@ mod tests { use super::*; use assets::Assets; use collections::HashSet; - use editor::{DisplayPoint, Editor, SelectionEffects, display_map::DisplayRow}; + use editor::{DisplayPoint, Editor, display_map::DisplayRow, scroll::Autoscroll}; use gpui::{ Action, AnyWindowHandle, App, AssetSource, BorrowAppContext, SemanticVersion, TestAppContext, UpdateGlobal, VisualTestContext, WindowHandle, actions, @@ -3348,7 +3348,7 @@ mod tests { workspace .update(cx, |_, window, cx| { editor1.update(cx, |editor, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(10), 0) ..DisplayPoint::new(DisplayRow(10), 0)]) }); @@ -3378,7 +3378,7 @@ mod tests { workspace .update(cx, |_, window, cx| { editor3.update(cx, |editor, cx| { - editor.change_selections(Default::default(), window, cx, |s| { + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(12), 0) ..DisplayPoint::new(DisplayRow(12), 0)]) }); @@ -3593,7 +3593,7 @@ mod tests { workspace .update(cx, |_, window, cx| { editor1.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(15), 0) ..DisplayPoint::new(DisplayRow(15), 0)]) }) @@ -3604,7 +3604,7 @@ mod tests { workspace .update(cx, |_, window, cx| { editor1.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(3), 0) ..DisplayPoint::new(DisplayRow(3), 0)]) }); @@ -3615,7 +3615,7 @@ mod tests { workspace .update(cx, |_, window, cx| { editor1.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(13), 0) ..DisplayPoint::new(DisplayRow(13), 0)]) }) @@ -3627,7 +3627,7 @@ mod tests { .update(cx, |_, window, cx| { editor1.update(cx, |editor, cx| { editor.transact(window, cx, |editor, window, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(2), 0) ..DisplayPoint::new(DisplayRow(14), 0)]) }); @@ -3640,7 +3640,7 @@ mod tests { workspace .update(cx, |_, window, cx| { editor1.update(cx, |editor, cx| { - editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + editor.change_selections(None, window, cx, |s| { s.select_display_ranges([DisplayPoint::new(DisplayRow(1), 0) ..DisplayPoint::new(DisplayRow(1), 0)]) })