Remove into SelectionEffects from .change_selections (#33554)

In #32656 I generalized the argument to change selections to allow
controling both the scroll and the nav history (and the completion
trigger).

To avoid conflicting with ongoing debugger cherry-picks I left the
argument as an `impl Into<>`, but I think it's clearer to make callers
specify what they want here.

I converted a lot of `None` arguments to `SelectionEffects::no_scroll()`
to be exactly compatible; but I think many people used none as an "i
don't care" value in which case Default::default() might be more
appropraite

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2025-06-27 14:31:31 -06:00 committed by GitHub
parent 6e762d9c05
commit a675ca7a1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
65 changed files with 837 additions and 625 deletions

View file

@ -19,7 +19,7 @@ use audio::{Audio, Sound};
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::actions::{MoveUp, Paste}; use editor::actions::{MoveUp, Paste};
use editor::scroll::Autoscroll; use editor::scroll::Autoscroll;
use editor::{Editor, EditorElement, EditorEvent, EditorStyle, MultiBuffer}; use editor::{Editor, EditorElement, EditorEvent, EditorStyle, MultiBuffer, SelectionEffects};
use gpui::{ use gpui::{
AbsoluteLength, Animation, AnimationExt, AnyElement, App, ClickEvent, ClipboardEntry, AbsoluteLength, Animation, AnimationExt, AnyElement, App, ClickEvent, ClipboardEntry,
ClipboardItem, DefiniteLength, EdgesRefinement, Empty, Entity, EventEmitter, Focusable, Hsla, ClipboardItem, DefiniteLength, EdgesRefinement, Empty, Entity, EventEmitter, Focusable, Hsla,
@ -689,9 +689,12 @@ fn open_markdown_link(
}) })
.context("Could not find matching symbol")?; .context("Could not find matching symbol")?;
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { editor.change_selections(
s.select_anchor_ranges([symbol_range.start..symbol_range.start]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|s| s.select_anchor_ranges([symbol_range.start..symbol_range.start]),
);
anyhow::Ok(()) anyhow::Ok(())
}) })
}) })
@ -708,10 +711,15 @@ fn open_markdown_link(
.downcast::<Editor>() .downcast::<Editor>()
.context("Item is not an editor")?; .context("Item is not an editor")?;
active_editor.update_in(cx, |editor, window, cx| { active_editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { editor.change_selections(
SelectionEffects::scroll(Autoscroll::center()),
window,
cx,
|s| {
s.select_ranges([Point::new(line_range.start as u32, 0) s.select_ranges([Point::new(line_range.start as u32, 0)
..Point::new(line_range.start as u32, 0)]) ..Point::new(line_range.start as u32, 0)])
}); },
);
anyhow::Ok(()) anyhow::Ok(())
}) })
}) })

View file

@ -5,7 +5,8 @@ use anyhow::Result;
use buffer_diff::DiffHunkStatus; use buffer_diff::DiffHunkStatus;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::{ use editor::{
Direction, Editor, EditorEvent, EditorSettings, MultiBuffer, MultiBufferSnapshot, ToPoint, Direction, Editor, EditorEvent, EditorSettings, MultiBuffer, MultiBufferSnapshot,
SelectionEffects, ToPoint,
actions::{GoToHunk, GoToPreviousHunk}, actions::{GoToHunk, GoToPreviousHunk},
scroll::Autoscroll, scroll::Autoscroll,
}; };
@ -171,15 +172,9 @@ impl AgentDiffPane {
if let Some(first_hunk) = first_hunk { if let Some(first_hunk) = first_hunk {
let first_hunk_start = first_hunk.multi_buffer_range().start; let first_hunk_start = first_hunk.multi_buffer_range().start;
editor.change_selections( editor.change_selections(Default::default(), window, cx, |selections| {
Some(Autoscroll::fit()), selections.select_anchor_ranges([first_hunk_start..first_hunk_start]);
window, })
cx,
|selections| {
selections
.select_anchor_ranges([first_hunk_start..first_hunk_start]);
},
)
} }
} }
@ -242,7 +237,7 @@ impl AgentDiffPane {
if let Some(first_hunk) = first_hunk { if let Some(first_hunk) = first_hunk {
let first_hunk_start = first_hunk.multi_buffer_range().start; let first_hunk_start = first_hunk.multi_buffer_range().start;
editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_anchor_ranges([first_hunk_start..first_hunk_start]); selections.select_anchor_ranges([first_hunk_start..first_hunk_start]);
}) })
} }
@ -416,7 +411,7 @@ fn update_editor_selection(
}; };
if let Some(target_hunk) = target_hunk { if let Some(target_hunk) = target_hunk {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
let next_hunk_start = target_hunk.multi_buffer_range().start; let next_hunk_start = target_hunk.multi_buffer_range().start;
selections.select_anchor_ranges([next_hunk_start..next_hunk_start]); selections.select_anchor_ranges([next_hunk_start..next_hunk_start]);
}) })
@ -1544,7 +1539,7 @@ impl AgentDiff {
let first_hunk_start = first_hunk.multi_buffer_range().start; let first_hunk_start = first_hunk.multi_buffer_range().start;
editor.change_selections( editor.change_selections(
Some(Autoscroll::center()), SelectionEffects::scroll(Autoscroll::center()),
window, window,
cx, cx,
|selections| { |selections| {
@ -1868,7 +1863,7 @@ mod tests {
// Rejecting a hunk also moves the cursor to the next hunk, possibly cycling if it's at the end. // 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.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)])
}); });
}); });
@ -2124,7 +2119,7 @@ mod tests {
// Rejecting a hunk also moves the cursor to the next hunk, possibly cycling if it's at the end. // 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| { editor1.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)])
}); });
}); });

View file

@ -18,6 +18,7 @@ use agent_settings::AgentSettings;
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};
use client::telemetry::Telemetry; use client::telemetry::Telemetry;
use collections::{HashMap, HashSet, VecDeque, hash_map}; use collections::{HashMap, HashSet, VecDeque, hash_map};
use editor::SelectionEffects;
use editor::{ use editor::{
Anchor, AnchorRangeExt, CodeActionProvider, Editor, EditorEvent, ExcerptId, ExcerptRange, Anchor, AnchorRangeExt, CodeActionProvider, Editor, EditorEvent, ExcerptId, ExcerptRange,
MultiBuffer, MultiBufferSnapshot, ToOffset as _, ToPoint, MultiBuffer, MultiBufferSnapshot, ToOffset as _, ToPoint,
@ -1159,7 +1160,7 @@ impl InlineAssistant {
let position = assist.range.start; let position = assist.range.start;
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_anchor_ranges([position..position]) selections.select_anchor_ranges([position..position])
}); });

View file

@ -21,7 +21,6 @@ use editor::{
BlockPlacement, BlockProperties, BlockStyle, Crease, CreaseMetadata, CustomBlockId, FoldId, BlockPlacement, BlockProperties, BlockStyle, Crease, CreaseMetadata, CustomBlockId, FoldId,
RenderBlock, ToDisplayPoint, RenderBlock, ToDisplayPoint,
}, },
scroll::Autoscroll,
}; };
use editor::{FoldPlaceholder, display_map::CreaseId}; use editor::{FoldPlaceholder, display_map::CreaseId};
use fs::Fs; use fs::Fs;
@ -389,7 +388,7 @@ impl TextThreadEditor {
cursor..cursor cursor..cursor
}; };
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges([new_selection]) selections.select_ranges([new_selection])
}); });
}); });
@ -449,8 +448,7 @@ impl TextThreadEditor {
if let Some(command) = self.slash_commands.command(name, cx) { if let Some(command) = self.slash_commands.command(name, cx) {
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor editor.change_selections(Default::default(), window, cx, |s| s.try_cancel());
.change_selections(Some(Autoscroll::fit()), window, cx, |s| s.try_cancel());
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
let newest_cursor = editor.selections.newest::<Point>(cx).head(); let newest_cursor = editor.selections.newest::<Point>(cx).head();
if newest_cursor.column > 0 if newest_cursor.column > 0
@ -1583,7 +1581,7 @@ impl TextThreadEditor {
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
editor.transact(window, cx, |this, window, cx| { editor.transact(window, cx, |this, window, cx| {
this.change_selections(Some(Autoscroll::fit()), window, cx, |s| { this.change_selections(Default::default(), window, cx, |s| {
s.select(selections); s.select(selections);
}); });
this.insert("", window, cx); this.insert("", window, cx);
@ -3141,6 +3139,7 @@ pub fn make_lsp_adapter_delegate(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use editor::SelectionEffects;
use fs::FakeFs; use fs::FakeFs;
use gpui::{App, TestAppContext, VisualTestContext}; use gpui::{App, TestAppContext, VisualTestContext};
use indoc::indoc; use indoc::indoc;
@ -3366,7 +3365,9 @@ mod tests {
) { ) {
context_editor.update_in(cx, |context_editor, window, cx| { context_editor.update_in(cx, |context_editor, window, cx| {
context_editor.editor.update(cx, |editor, cx| { context_editor.editor.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([range])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([range])
});
}); });
context_editor.copy(&Default::default(), window, cx); context_editor.copy(&Default::default(), window, cx);

View file

@ -10,7 +10,7 @@ use assistant_tool::{
ToolUseStatus, ToolUseStatus,
}; };
use buffer_diff::{BufferDiff, BufferDiffSnapshot}; use buffer_diff::{BufferDiff, BufferDiffSnapshot};
use editor::{Editor, EditorMode, MinimapVisibility, MultiBuffer, PathKey, scroll::Autoscroll}; use editor::{Editor, EditorMode, MinimapVisibility, MultiBuffer, PathKey};
use futures::StreamExt; use futures::StreamExt;
use gpui::{ use gpui::{
Animation, AnimationExt, AnyWindowHandle, App, AppContext, AsyncApp, Entity, Task, Animation, AnimationExt, AnyWindowHandle, App, AppContext, AsyncApp, Entity, Task,
@ -823,7 +823,7 @@ impl ToolCard for EditFileToolCard {
let first_hunk_start = let first_hunk_start =
first_hunk.multi_buffer_range().start; first_hunk.multi_buffer_range().start;
editor.change_selections( editor.change_selections(
Some(Autoscroll::fit()), Default::default(),
window, window,
cx, cx,
|selections| { |selections| {

View file

@ -178,7 +178,7 @@ async fn test_channel_notes_participant_indices(
channel_view_a.update_in(cx_a, |notes, window, cx| { channel_view_a.update_in(cx_a, |notes, window, cx| {
notes.editor.update(cx, |editor, cx| { notes.editor.update(cx, |editor, cx| {
editor.insert("a", window, cx); editor.insert("a", window, cx);
editor.change_selections(None, window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges(vec![0..1]); selections.select_ranges(vec![0..1]);
}); });
}); });
@ -188,7 +188,7 @@ async fn test_channel_notes_participant_indices(
notes.editor.update(cx, |editor, cx| { notes.editor.update(cx, |editor, cx| {
editor.move_down(&Default::default(), window, cx); editor.move_down(&Default::default(), window, cx);
editor.insert("b", window, cx); editor.insert("b", window, cx);
editor.change_selections(None, window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges(vec![1..2]); selections.select_ranges(vec![1..2]);
}); });
}); });
@ -198,7 +198,7 @@ async fn test_channel_notes_participant_indices(
notes.editor.update(cx, |editor, cx| { notes.editor.update(cx, |editor, cx| {
editor.move_down(&Default::default(), window, cx); editor.move_down(&Default::default(), window, cx);
editor.insert("c", window, cx); editor.insert("c", window, cx);
editor.change_selections(None, window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges(vec![2..3]); selections.select_ranges(vec![2..3]);
}); });
}); });
@ -273,12 +273,12 @@ async fn test_channel_notes_participant_indices(
.unwrap(); .unwrap();
editor_a.update_in(cx_a, |editor, window, cx| { editor_a.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges(vec![0..1]); selections.select_ranges(vec![0..1]);
}); });
}); });
editor_b.update_in(cx_b, |editor, window, cx| { editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges(vec![2..3]); selections.select_ranges(vec![2..3]);
}); });
}); });

View file

@ -4,7 +4,7 @@ use crate::{
}; };
use call::ActiveCall; use call::ActiveCall;
use editor::{ use editor::{
DocumentColorsRenderMode, Editor, EditorSettings, RowInfo, DocumentColorsRenderMode, Editor, EditorSettings, RowInfo, SelectionEffects,
actions::{ actions::{
ConfirmCodeAction, ConfirmCompletion, ConfirmRename, ContextMenuFirst, ConfirmCodeAction, ConfirmCompletion, ConfirmRename, ContextMenuFirst,
ExpandMacroRecursively, MoveToEnd, Redo, Rename, SelectAll, ToggleCodeActions, Undo, ExpandMacroRecursively, MoveToEnd, Redo, Rename, SelectAll, ToggleCodeActions, Undo,
@ -348,7 +348,9 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
// Type a completion trigger character as the guest. // Type a completion trigger character as the guest.
editor_b.update_in(cx_b, |editor, window, cx| { editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input(".", window, cx); editor.handle_input(".", window, cx);
}); });
cx_b.focus(&editor_b); cx_b.focus(&editor_b);
@ -461,7 +463,9 @@ 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 // Now we do a second completion, this time to ensure that documentation/snippets are
// resolved // resolved
editor_b.update_in(cx_b, |editor, window, cx| { editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([46..46])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([46..46])
});
editor.handle_input("; a", window, cx); editor.handle_input("; a", window, cx);
editor.handle_input(".", window, cx); editor.handle_input(".", window, cx);
}); });
@ -613,7 +617,7 @@ async fn test_collaborating_with_code_actions(
// Move cursor to a location that contains code actions. // Move cursor to a location that contains code actions.
editor_b.update_in(cx_b, |editor, window, cx| { editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 31)..Point::new(1, 31)]) s.select_ranges([Point::new(1, 31)..Point::new(1, 31)])
}); });
}); });
@ -817,7 +821,9 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T
// Move cursor to a location that can be renamed. // Move cursor to a location that can be renamed.
let prepare_rename = editor_b.update_in(cx_b, |editor, window, cx| { let prepare_rename = editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([7..7])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([7..7])
});
editor.rename(&Rename, window, cx).unwrap() editor.rename(&Rename, window, cx).unwrap()
}); });
@ -863,7 +869,9 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T
editor.cancel(&editor::actions::Cancel, window, cx); editor.cancel(&editor::actions::Cancel, window, cx);
}); });
let prepare_rename = editor_b.update_in(cx_b, |editor, window, cx| { let prepare_rename = editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([7..8])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([7..8])
});
editor.rename(&Rename, window, cx).unwrap() editor.rename(&Rename, window, cx).unwrap()
}); });
@ -1364,7 +1372,9 @@ async fn test_on_input_format_from_host_to_guest(
// Type a on type formatting trigger character as the guest. // Type a on type formatting trigger character as the guest.
cx_a.focus(&editor_a); cx_a.focus(&editor_a);
editor_a.update_in(cx_a, |editor, window, cx| { editor_a.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input(">", window, cx); editor.handle_input(">", window, cx);
}); });
@ -1460,7 +1470,9 @@ async fn test_on_input_format_from_guest_to_host(
// Type a on type formatting trigger character as the guest. // Type a on type formatting trigger character as the guest.
cx_b.focus(&editor_b); cx_b.focus(&editor_b);
editor_b.update_in(cx_b, |editor, window, cx| { editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input(":", window, cx); editor.handle_input(":", window, cx);
}); });
@ -1697,7 +1709,9 @@ async fn test_mutual_editor_inlay_hint_cache_update(
let after_client_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1; let after_client_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1;
editor_b.update_in(cx_b, |editor, window, cx| { editor_b.update_in(cx_b, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13].clone())); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13].clone())
});
editor.handle_input(":", window, cx); editor.handle_input(":", window, cx);
}); });
cx_b.focus(&editor_b); cx_b.focus(&editor_b);
@ -1718,7 +1732,9 @@ async fn test_mutual_editor_inlay_hint_cache_update(
let after_host_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1; let after_host_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1;
editor_a.update_in(cx_a, |editor, window, cx| { editor_a.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input("a change to increment both buffers' versions", window, cx); editor.handle_input("a change to increment both buffers' versions", window, cx);
}); });
cx_a.focus(&editor_a); cx_a.focus(&editor_a);
@ -2121,7 +2137,9 @@ async fn test_lsp_document_color(cx_a: &mut TestAppContext, cx_b: &mut TestAppCo
}); });
editor_a.update_in(cx_a, |editor, window, cx| { editor_a.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13].clone())); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13].clone())
});
editor.handle_input(":", window, cx); editor.handle_input(":", window, cx);
}); });
color_request_handle.next().await.unwrap(); color_request_handle.next().await.unwrap();

View file

@ -6,7 +6,7 @@ use collab_ui::{
channel_view::ChannelView, channel_view::ChannelView,
notifications::project_shared_notification::ProjectSharedNotification, notifications::project_shared_notification::ProjectSharedNotification,
}; };
use editor::{Editor, MultiBuffer, PathKey}; use editor::{Editor, MultiBuffer, PathKey, SelectionEffects};
use gpui::{ use gpui::{
AppContext as _, BackgroundExecutor, BorrowAppContext, Entity, SharedString, TestAppContext, AppContext as _, BackgroundExecutor, BorrowAppContext, Entity, SharedString, TestAppContext,
VisualContext, VisualTestContext, point, VisualContext, VisualTestContext, point,
@ -376,7 +376,9 @@ async fn test_basic_following(
// Changes to client A's editor are reflected on client B. // Changes to client A's editor are reflected on client B.
editor_a1.update_in(cx_a, |editor, window, cx| { editor_a1.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([1..1, 2..2])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([1..1, 2..2])
});
}); });
executor.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); executor.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE);
executor.run_until_parked(); executor.run_until_parked();
@ -393,7 +395,9 @@ async fn test_basic_following(
editor_b1.update(cx_b, |editor, cx| assert_eq!(editor.text(cx), "TWO")); editor_b1.update(cx_b, |editor, cx| assert_eq!(editor.text(cx), "TWO"));
editor_a1.update_in(cx_a, |editor, window, cx| { editor_a1.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([3..3])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([3..3])
});
editor.set_scroll_position(point(0., 100.), window, cx); editor.set_scroll_position(point(0., 100.), window, cx);
}); });
executor.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); executor.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE);
@ -1647,7 +1651,9 @@ async fn test_following_stops_on_unshare(cx_a: &mut TestAppContext, cx_b: &mut T
// b should follow a to position 1 // b should follow a to position 1
editor_a.update_in(cx_a, |editor, window, cx| { editor_a.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([1..1])) editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([1..1])
})
}); });
cx_a.executor() cx_a.executor()
.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); .advance_clock(workspace::item::LEADER_UPDATE_THROTTLE);
@ -1667,7 +1673,9 @@ async fn test_following_stops_on_unshare(cx_a: &mut TestAppContext, cx_b: &mut T
// b should not follow a to position 2 // b should not follow a to position 2
editor_a.update_in(cx_a, |editor, window, cx| { editor_a.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([2..2])) editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([2..2])
})
}); });
cx_a.executor() cx_a.executor()
.advance_clock(workspace::item::LEADER_UPDATE_THROTTLE); .advance_clock(workspace::item::LEADER_UPDATE_THROTTLE);
@ -1968,7 +1976,7 @@ async fn test_following_to_channel_notes_without_a_shared_project(
assert_eq!(notes.channel(cx).unwrap().name, "channel-1"); assert_eq!(notes.channel(cx).unwrap().name, "channel-1");
notes.editor.update(cx, |editor, cx| { notes.editor.update(cx, |editor, cx| {
editor.insert("Hello from A.", window, cx); editor.insert("Hello from A.", window, cx);
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges(vec![3..4]); selections.select_ranges(vec![3..4]);
}); });
}); });
@ -2109,7 +2117,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) workspace.add_item_to_center(Box::new(editor.clone()) as _, window, cx)
}); });
editor.update_in(cx_a, |editor, window, cx| { editor.update_in(cx_a, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::row_range(4..4)]); s.select_ranges([Point::row_range(4..4)]);
}) })
}); });

View file

@ -7,8 +7,8 @@ use client::{
}; };
use collections::HashMap; use collections::HashMap;
use editor::{ use editor::{
CollaborationHub, DisplayPoint, Editor, EditorEvent, display_map::ToDisplayPoint, CollaborationHub, DisplayPoint, Editor, EditorEvent, SelectionEffects,
scroll::Autoscroll, display_map::ToDisplayPoint, scroll::Autoscroll,
}; };
use gpui::{ use gpui::{
AnyView, App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render, AnyView, App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render,
@ -260,9 +260,16 @@ impl ChannelView {
.find(|item| &Channel::slug(&item.text).to_lowercase() == &position) .find(|item| &Channel::slug(&item.text).to_lowercase() == &position)
{ {
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::focused()), window, cx, |s| { editor.change_selections(
s.replace_cursors_with(|map| vec![item.range.start.to_display_point(map)]) SelectionEffects::scroll(Autoscroll::focused()),
window,
cx,
|s| {
s.replace_cursors_with(|map| {
vec![item.range.start.to_display_point(map)]
}) })
},
)
}); });
return; return;
} }

View file

@ -264,7 +264,8 @@ fn common_prefix<T1: Iterator<Item = char>, T2: Iterator<Item = char>>(a: T1, b:
mod tests { mod tests {
use super::*; use super::*;
use editor::{ use editor::{
Editor, ExcerptRange, MultiBuffer, test::editor_lsp_test_context::EditorLspTestContext, Editor, ExcerptRange, MultiBuffer, SelectionEffects,
test::editor_lsp_test_context::EditorLspTestContext,
}; };
use fs::FakeFs; use fs::FakeFs;
use futures::StreamExt; use futures::StreamExt;
@ -478,7 +479,7 @@ mod tests {
// Reset the editor to verify how suggestions behave when tabbing on leading indentation. // Reset the editor to verify how suggestions behave when tabbing on leading indentation.
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.set_text("fn foo() {\n \n}", window, cx); editor.set_text("fn foo() {\n \n}", window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 2)..Point::new(1, 2)]) s.select_ranges([Point::new(1, 2)..Point::new(1, 2)])
}); });
}); });
@ -767,7 +768,7 @@ mod tests {
); );
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
// Ensure copilot suggestions are shown for the first excerpt. // Ensure copilot suggestions are shown for the first excerpt.
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 5)..Point::new(1, 5)]) s.select_ranges([Point::new(1, 5)..Point::new(1, 5)])
}); });
editor.next_edit_prediction(&Default::default(), window, cx); editor.next_edit_prediction(&Default::default(), window, cx);
@ -793,7 +794,7 @@ mod tests {
); );
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
// Move to another excerpt, ensuring the suggestion gets cleared. // Move to another excerpt, ensuring the suggestion gets cleared.
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(4, 5)..Point::new(4, 5)]) s.select_ranges([Point::new(4, 5)..Point::new(4, 5)])
}); });
assert!(!editor.has_active_inline_completion()); assert!(!editor.has_active_inline_completion());
@ -1019,7 +1020,7 @@ mod tests {
); );
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges([Point::new(0, 0)..Point::new(0, 0)]) selections.select_ranges([Point::new(0, 0)..Point::new(0, 0)])
}); });
editor.refresh_inline_completion(true, false, window, cx); editor.refresh_inline_completion(true, false, window, cx);
@ -1029,7 +1030,7 @@ mod tests {
assert!(copilot_requests.try_next().is_err()); assert!(copilot_requests.try_next().is_err());
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(5, 0)..Point::new(5, 0)]) s.select_ranges([Point::new(5, 0)..Point::new(5, 0)])
}); });
editor.refresh_inline_completion(true, false, window, cx); editor.refresh_inline_completion(true, false, window, cx);

View file

@ -4,7 +4,7 @@ use collections::HashMap;
use dap::StackFrameId; use dap::StackFrameId;
use editor::{ use editor::{
Anchor, Bias, DebugStackFrameLine, Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer, Anchor, Bias, DebugStackFrameLine, Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer,
RowHighlightOptions, ToPoint, scroll::Autoscroll, RowHighlightOptions, SelectionEffects, ToPoint, scroll::Autoscroll,
}; };
use gpui::{ use gpui::{
AnyView, App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString, AnyView, App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString,
@ -99,10 +99,11 @@ impl StackTraceView {
if frame_anchor.excerpt_id if frame_anchor.excerpt_id
!= editor.selections.newest_anchor().head().excerpt_id != editor.selections.newest_anchor().head().excerpt_id
{ {
let auto_scroll = let effects = SelectionEffects::scroll(
Some(Autoscroll::center().for_anchor(frame_anchor)); Autoscroll::center().for_anchor(frame_anchor),
);
editor.change_selections(auto_scroll, window, cx, |selections| { editor.change_selections(effects, window, cx, |selections| {
let selection_id = selections.new_selection_id(); let selection_id = selections.new_selection_id();
let selection = Selection { let selection = Selection {

View file

@ -4,7 +4,6 @@ use editor::{
Anchor, Editor, EditorSnapshot, ToOffset, Anchor, Editor, EditorSnapshot, ToOffset,
display_map::{BlockContext, BlockPlacement, BlockProperties, BlockStyle}, display_map::{BlockContext, BlockPlacement, BlockProperties, BlockStyle},
hover_popover::diagnostics_markdown_style, hover_popover::diagnostics_markdown_style,
scroll::Autoscroll,
}; };
use gpui::{AppContext, Entity, Focusable, WeakEntity}; use gpui::{AppContext, Entity, Focusable, WeakEntity};
use language::{BufferId, Diagnostic, DiagnosticEntry}; use language::{BufferId, Diagnostic, DiagnosticEntry};
@ -311,7 +310,7 @@ impl DiagnosticBlock {
let range = range.start.to_offset(&snapshot)..range.end.to_offset(&snapshot); let range = range.start.to_offset(&snapshot)..range.end.to_offset(&snapshot);
editor.unfold_ranges(&[range.start..range.end], true, false, cx); editor.unfold_ranges(&[range.start..range.end], true, false, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([range.start..range.start]); s.select_ranges([range.start..range.start]);
}); });
window.focus(&editor.focus_handle(cx)); window.focus(&editor.focus_handle(cx));

View file

@ -12,7 +12,6 @@ use diagnostic_renderer::DiagnosticBlock;
use editor::{ use editor::{
DEFAULT_MULTIBUFFER_CONTEXT, Editor, EditorEvent, ExcerptRange, MultiBuffer, PathKey, DEFAULT_MULTIBUFFER_CONTEXT, Editor, EditorEvent, ExcerptRange, MultiBuffer, PathKey,
display_map::{BlockPlacement, BlockProperties, BlockStyle, CustomBlockId}, display_map::{BlockPlacement, BlockProperties, BlockStyle, CustomBlockId},
scroll::Autoscroll,
}; };
use futures::future::join_all; use futures::future::join_all;
use gpui::{ use gpui::{
@ -626,7 +625,7 @@ impl ProjectDiagnosticsEditor {
if let Some(anchor_range) = anchor_ranges.first() { if let Some(anchor_range) = anchor_ranges.first() {
let range_to_select = anchor_range.start..anchor_range.start; let range_to_select = anchor_range.start..anchor_range.start;
this.editor.update(cx, |editor, cx| { this.editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_anchor_ranges([range_to_select]); s.select_anchor_ranges([range_to_select]);
}) })
}); });

File diff suppressed because it is too large Load diff

View file

@ -179,7 +179,9 @@ fn test_edit_events(cx: &mut TestAppContext) {
// No event is emitted when the mutation is a no-op. // No event is emitted when the mutation is a no-op.
_ = editor2.update(cx, |editor, window, cx| { _ = editor2.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([0..0])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([0..0])
});
editor.backspace(&Backspace, window, cx); editor.backspace(&Backspace, window, cx);
}); });
@ -202,7 +204,9 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) {
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.start_transaction_at(now, window, cx); editor.start_transaction_at(now, window, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges([2..4])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([2..4])
});
editor.insert("cd", window, cx); editor.insert("cd", window, cx);
editor.end_transaction_at(now, cx); editor.end_transaction_at(now, cx);
@ -210,14 +214,18 @@ fn test_undo_redo_with_selection_restoration(cx: &mut TestAppContext) {
assert_eq!(editor.selections.ranges(cx), vec![4..4]); assert_eq!(editor.selections.ranges(cx), vec![4..4]);
editor.start_transaction_at(now, window, cx); editor.start_transaction_at(now, window, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges([4..5])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([4..5])
});
editor.insert("e", window, cx); editor.insert("e", window, cx);
editor.end_transaction_at(now, cx); editor.end_transaction_at(now, cx);
assert_eq!(editor.text(cx), "12cde6"); assert_eq!(editor.text(cx), "12cde6");
assert_eq!(editor.selections.ranges(cx), vec![5..5]); assert_eq!(editor.selections.ranges(cx), vec![5..5]);
now += group_interval + Duration::from_millis(1); now += group_interval + Duration::from_millis(1);
editor.change_selections(None, window, cx, |s| s.select_ranges([2..2])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([2..2])
});
// Simulate an edit in another editor // Simulate an edit in another editor
buffer.update(cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
@ -325,7 +333,7 @@ fn test_ime_composition(cx: &mut TestAppContext) {
assert_eq!(editor.marked_text_ranges(cx), None); assert_eq!(editor.marked_text_ranges(cx), None);
// Start a new IME composition with multiple cursors. // Start a new IME composition with multiple cursors.
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
OffsetUtf16(1)..OffsetUtf16(1), OffsetUtf16(1)..OffsetUtf16(1),
OffsetUtf16(3)..OffsetUtf16(3), OffsetUtf16(3)..OffsetUtf16(3),
@ -623,7 +631,7 @@ fn test_clone(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(selection_ranges.clone()) s.select_ranges(selection_ranges.clone())
}); });
editor.fold_creases( editor.fold_creases(
@ -709,12 +717,12 @@ async fn test_navigation_history(cx: &mut TestAppContext) {
// Move the cursor a small distance. // Move the cursor a small distance.
// Nothing is added to the navigation history. // Nothing is added to the navigation history.
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0) DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0)
]) ])
}); });
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 0)..DisplayPoint::new(DisplayRow(3), 0) DisplayPoint::new(DisplayRow(3), 0)..DisplayPoint::new(DisplayRow(3), 0)
]) ])
@ -723,7 +731,7 @@ async fn test_navigation_history(cx: &mut TestAppContext) {
// Move the cursor a large distance. // Move the cursor a large distance.
// The history can jump back to the previous position. // The history can jump back to the previous position.
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(13), 0)..DisplayPoint::new(DisplayRow(13), 3) DisplayPoint::new(DisplayRow(13), 0)..DisplayPoint::new(DisplayRow(13), 3)
]) ])
@ -893,7 +901,7 @@ fn test_fold_action(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(7), 0)..DisplayPoint::new(DisplayRow(12), 0) DisplayPoint::new(DisplayRow(7), 0)..DisplayPoint::new(DisplayRow(12), 0)
]); ]);
@ -984,7 +992,7 @@ fn test_fold_action_whitespace_sensitive_language(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(10), 0) DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(10), 0)
]); ]);
@ -1069,7 +1077,7 @@ fn test_fold_action_multiple_line_breaks(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(11), 0) DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(11), 0)
]); ]);
@ -1301,7 +1309,7 @@ fn test_move_cursor(cx: &mut TestAppContext) {
&[DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)] &[DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)]
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 2) DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 2)
]); ]);
@ -1446,7 +1454,7 @@ fn test_move_cursor_different_line_lengths(cx: &mut TestAppContext) {
build_editor(buffer.clone(), window, cx) build_editor(buffer.clone(), window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([empty_range(0, "ⓐⓑⓒⓓⓔ".len())]); s.select_display_ranges([empty_range(0, "ⓐⓑⓒⓓⓔ".len())]);
}); });
@ -1536,7 +1544,7 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(1), 4)..DisplayPoint::new(DisplayRow(1), 4), DisplayPoint::new(DisplayRow(1), 4)..DisplayPoint::new(DisplayRow(1), 4),
@ -1731,7 +1739,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. // First, let's assert behavior on the first line, that was not soft-wrapped.
// Start the cursor at the `k` on the first line // Start the cursor at the `k` on the first line
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 7)..DisplayPoint::new(DisplayRow(0), 7) DisplayPoint::new(DisplayRow(0), 7)..DisplayPoint::new(DisplayRow(0), 7)
]); ]);
@ -1753,7 +1761,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. // 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) // Start the cursor at the last line (`y` that was wrapped to a new line)
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 0) DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 0)
]); ]);
@ -1819,7 +1827,7 @@ fn test_beginning_of_line_stop_at_indent(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(1), 4)..DisplayPoint::new(DisplayRow(1), 4), DisplayPoint::new(DisplayRow(1), 4)..DisplayPoint::new(DisplayRow(1), 4),
@ -1901,7 +1909,7 @@ fn test_prev_next_word_boundary(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 11)..DisplayPoint::new(DisplayRow(0), 11), DisplayPoint::new(DisplayRow(0), 11)..DisplayPoint::new(DisplayRow(0), 11),
DisplayPoint::new(DisplayRow(2), 4)..DisplayPoint::new(DisplayRow(2), 4), DisplayPoint::new(DisplayRow(2), 4)..DisplayPoint::new(DisplayRow(2), 4),
@ -1971,7 +1979,7 @@ fn test_prev_next_word_bounds_with_soft_wrap(cx: &mut TestAppContext) {
"use one::{\n two::three::\n four::five\n};" "use one::{\n two::three::\n four::five\n};"
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(1), 7)..DisplayPoint::new(DisplayRow(1), 7) DisplayPoint::new(DisplayRow(1), 7)..DisplayPoint::new(DisplayRow(1), 7)
]); ]);
@ -2234,7 +2242,7 @@ async fn test_autoscroll(cx: &mut TestAppContext) {
// on screen, the editor autoscrolls to reveal the newest cursor, and // on screen, the editor autoscrolls to reveal the newest cursor, and
// allows the vertical scroll margin below that cursor. // allows the vertical scroll margin below that cursor.
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges([ selections.select_ranges([
Point::new(0, 0)..Point::new(0, 0), Point::new(0, 0)..Point::new(0, 0),
Point::new(6, 0)..Point::new(6, 0), Point::new(6, 0)..Point::new(6, 0),
@ -2262,7 +2270,7 @@ async fn test_autoscroll(cx: &mut TestAppContext) {
// Add a cursor above the visible area. Since both cursors fit on screen, // Add a cursor above the visible area. Since both cursors fit on screen,
// the editor scrolls to show both. // the editor scrolls to show both.
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |selections| { editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_ranges([ selections.select_ranges([
Point::new(1, 0)..Point::new(1, 0), Point::new(1, 0)..Point::new(1, 0),
Point::new(6, 0)..Point::new(6, 0), Point::new(6, 0)..Point::new(6, 0),
@ -2429,7 +2437,7 @@ fn test_delete_to_word_boundary(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
// an empty selection - the preceding word fragment is deleted // an empty selection - the preceding word fragment is deleted
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
@ -2448,7 +2456,7 @@ fn test_delete_to_word_boundary(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
// an empty selection - the following word fragment is deleted // an empty selection - the following word fragment is deleted
DisplayPoint::new(DisplayRow(0), 3)..DisplayPoint::new(DisplayRow(0), 3), DisplayPoint::new(DisplayRow(0), 3)..DisplayPoint::new(DisplayRow(0), 3),
@ -2483,7 +2491,7 @@ fn test_delete_to_previous_word_start_or_newline(cx: &mut TestAppContext) {
}; };
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 1)..DisplayPoint::new(DisplayRow(3), 1) DisplayPoint::new(DisplayRow(3), 1)..DisplayPoint::new(DisplayRow(3), 1)
]) ])
@ -2519,7 +2527,7 @@ fn test_delete_to_next_word_end_or_newline(cx: &mut TestAppContext) {
}; };
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0) DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)
]) ])
@ -2558,7 +2566,7 @@ fn test_newline(cx: &mut TestAppContext) {
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(1), 2), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(1), 2),
@ -2591,7 +2599,7 @@ fn test_newline_with_old_selections(cx: &mut TestAppContext) {
cx, cx,
); );
let mut editor = build_editor(buffer.clone(), window, cx); let mut editor = build_editor(buffer.clone(), window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
Point::new(2, 4)..Point::new(2, 5), Point::new(2, 4)..Point::new(2, 5),
Point::new(5, 4)..Point::new(5, 5), Point::new(5, 4)..Point::new(5, 5),
@ -3078,7 +3086,7 @@ fn test_insert_with_old_selections(cx: &mut TestAppContext) {
let editor = cx.add_window(|window, cx| { let editor = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple("a( X ), b( Y ), c( Z )", cx); let buffer = MultiBuffer::build_simple("a( X ), b( Y ), c( Z )", cx);
let mut editor = build_editor(buffer.clone(), window, cx); let mut editor = build_editor(buffer.clone(), window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([3..4, 11..12, 19..20]) s.select_ranges([3..4, 11..12, 19..20])
}); });
editor editor
@ -3727,7 +3735,7 @@ fn test_delete_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 1),
@ -3750,7 +3758,7 @@ fn test_delete_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(0), 1) DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(0), 1)
]) ])
@ -3787,7 +3795,7 @@ fn test_join_lines_with_single_selection(cx: &mut TestAppContext) {
); );
// When multiple lines are selected, remove newlines that are spanned by the selection // When multiple lines are selected, remove newlines that are spanned by the selection
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(0, 5)..Point::new(2, 2)]) s.select_ranges([Point::new(0, 5)..Point::new(2, 2)])
}); });
editor.join_lines(&JoinLines, window, cx); editor.join_lines(&JoinLines, window, cx);
@ -3806,7 +3814,7 @@ fn test_join_lines_with_single_selection(cx: &mut TestAppContext) {
); );
// When joining an empty line don't insert a space // When joining an empty line don't insert a space
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(2, 1)..Point::new(2, 2)]) s.select_ranges([Point::new(2, 1)..Point::new(2, 2)])
}); });
editor.join_lines(&JoinLines, window, cx); editor.join_lines(&JoinLines, window, cx);
@ -3846,7 +3854,7 @@ fn test_join_lines_with_single_selection(cx: &mut TestAppContext) {
// We remove any leading spaces // We remove any leading spaces
assert_eq!(buffer.read(cx).text(), "aaa bbb\n c\n \n\td"); assert_eq!(buffer.read(cx).text(), "aaa bbb\n c\n \n\td");
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(0, 1)..Point::new(0, 1)]) s.select_ranges([Point::new(0, 1)..Point::new(0, 1)])
}); });
editor.join_lines(&JoinLines, window, cx); editor.join_lines(&JoinLines, window, cx);
@ -3873,7 +3881,7 @@ fn test_join_lines_with_multi_selection(cx: &mut TestAppContext) {
let mut editor = build_editor(buffer.clone(), window, cx); let mut editor = build_editor(buffer.clone(), window, cx);
let buffer = buffer.read(cx).as_singleton().unwrap(); let buffer = buffer.read(cx).as_singleton().unwrap();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
Point::new(0, 2)..Point::new(1, 1), Point::new(0, 2)..Point::new(1, 1),
Point::new(1, 2)..Point::new(1, 2), Point::new(1, 2)..Point::new(1, 2),
@ -4713,7 +4721,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
@ -4739,7 +4747,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1),
DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1),
@ -4763,7 +4771,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
@ -4789,7 +4797,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1),
DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1),
@ -4811,7 +4819,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(1), 1),
DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1), DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(2), 1),
@ -4848,7 +4856,7 @@ fn test_move_line_up_down(cx: &mut TestAppContext) {
window, window,
cx, cx,
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 1)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(3), 1)..DisplayPoint::new(DisplayRow(3), 1), DisplayPoint::new(DisplayRow(3), 1)..DisplayPoint::new(DisplayRow(3), 1),
@ -4951,7 +4959,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {
Some(Autoscroll::fit()), Some(Autoscroll::fit()),
cx, cx,
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) s.select_ranges([Point::new(2, 0)..Point::new(2, 0)])
}); });
editor.move_line_down(&MoveLineDown, window, cx); editor.move_line_down(&MoveLineDown, window, cx);
@ -5036,7 +5044,9 @@ fn test_transpose(cx: &mut TestAppContext) {
_ = cx.add_window(|window, cx| { _ = cx.add_window(|window, cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), window, cx); let mut editor = build_editor(MultiBuffer::build_simple("abc", cx), window, cx);
editor.set_style(EditorStyle::default(), window, cx); editor.set_style(EditorStyle::default(), window, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges([1..1])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([1..1])
});
editor.transpose(&Default::default(), window, cx); editor.transpose(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "bac"); assert_eq!(editor.text(cx), "bac");
assert_eq!(editor.selections.ranges(cx), [2..2]); assert_eq!(editor.selections.ranges(cx), [2..2]);
@ -5055,12 +5065,16 @@ fn test_transpose(cx: &mut TestAppContext) {
_ = cx.add_window(|window, cx| { _ = cx.add_window(|window, cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), window, cx); let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), window, cx);
editor.set_style(EditorStyle::default(), window, cx); editor.set_style(EditorStyle::default(), window, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges([3..3])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([3..3])
});
editor.transpose(&Default::default(), window, cx); editor.transpose(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "acb\nde"); assert_eq!(editor.text(cx), "acb\nde");
assert_eq!(editor.selections.ranges(cx), [3..3]); assert_eq!(editor.selections.ranges(cx), [3..3]);
editor.change_selections(None, window, cx, |s| s.select_ranges([4..4])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([4..4])
});
editor.transpose(&Default::default(), window, cx); editor.transpose(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "acbd\ne"); assert_eq!(editor.text(cx), "acbd\ne");
assert_eq!(editor.selections.ranges(cx), [5..5]); assert_eq!(editor.selections.ranges(cx), [5..5]);
@ -5079,7 +5093,9 @@ fn test_transpose(cx: &mut TestAppContext) {
_ = cx.add_window(|window, cx| { _ = cx.add_window(|window, cx| {
let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), window, cx); let mut editor = build_editor(MultiBuffer::build_simple("abc\nde", cx), window, cx);
editor.set_style(EditorStyle::default(), window, cx); editor.set_style(EditorStyle::default(), window, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges([1..1, 2..2, 4..4])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([1..1, 2..2, 4..4])
});
editor.transpose(&Default::default(), window, cx); editor.transpose(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "bacd\ne"); assert_eq!(editor.text(cx), "bacd\ne");
assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]); assert_eq!(editor.selections.ranges(cx), [2..2, 3..3, 5..5]);
@ -5106,7 +5122,9 @@ fn test_transpose(cx: &mut TestAppContext) {
_ = cx.add_window(|window, cx| { _ = cx.add_window(|window, cx| {
let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), window, cx); let mut editor = build_editor(MultiBuffer::build_simple("🍐🏀✋", cx), window, cx);
editor.set_style(EditorStyle::default(), window, cx); editor.set_style(EditorStyle::default(), window, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges([4..4])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([4..4])
});
editor.transpose(&Default::default(), window, cx); editor.transpose(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "🏀🍐✋"); assert_eq!(editor.text(cx), "🏀🍐✋");
assert_eq!(editor.selections.ranges(cx), [8..8]); assert_eq!(editor.selections.ranges(cx), [8..8]);
@ -6085,7 +6103,7 @@ fn test_select_line(cx: &mut TestAppContext) {
build_editor(buffer, window, cx) build_editor(buffer, window, cx)
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
@ -6212,7 +6230,7 @@ async fn test_split_selection_into_lines_interacting_with_creases(cx: &mut TestA
}); });
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
@ -6231,7 +6249,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ˇ"); .assert_editor_state("aˇaˇaaa\nbbbbb\nˇccccc\nddddd\neeeee\nfffff\nggggg\nhhhhh\niiiiiˇ");
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(5), 0)..DisplayPoint::new(DisplayRow(0), 1) DisplayPoint::new(DisplayRow(5), 0)..DisplayPoint::new(DisplayRow(0), 1)
]) ])
@ -6977,7 +6995,7 @@ async fn test_undo_format_scrolls_to_last_edit_pos(cx: &mut TestAppContext) {
// Move cursor to a different position // Move cursor to a different position
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(4, 2)..Point::new(4, 2)]); s.select_ranges([Point::new(4, 2)..Point::new(4, 2)]);
}); });
}); });
@ -7082,7 +7100,7 @@ async fn test_undo_inline_completion_scrolls_to_edit_pos(cx: &mut TestAppContext
"}); "});
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(9, 2)..Point::new(9, 2)]); s.select_ranges([Point::new(9, 2)..Point::new(9, 2)]);
}); });
}); });
@ -7342,7 +7360,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut TestAppContext) {
.await; .await;
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 25)..DisplayPoint::new(DisplayRow(0), 25), DisplayPoint::new(DisplayRow(0), 25)..DisplayPoint::new(DisplayRow(0), 25),
DisplayPoint::new(DisplayRow(2), 24)..DisplayPoint::new(DisplayRow(2), 12), DisplayPoint::new(DisplayRow(2), 24)..DisplayPoint::new(DisplayRow(2), 12),
@ -7524,7 +7542,7 @@ async fn test_select_larger_syntax_node_for_cursor_at_end(cx: &mut TestAppContex
// Test case 1: Cursor at end of word // Test case 1: Cursor at end of word
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 5)..DisplayPoint::new(DisplayRow(0), 5) DisplayPoint::new(DisplayRow(0), 5)..DisplayPoint::new(DisplayRow(0), 5)
]); ]);
@ -7548,7 +7566,7 @@ async fn test_select_larger_syntax_node_for_cursor_at_end(cx: &mut TestAppContex
// Test case 2: Cursor at end of statement // Test case 2: Cursor at end of statement
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 11)..DisplayPoint::new(DisplayRow(0), 11) DisplayPoint::new(DisplayRow(0), 11)..DisplayPoint::new(DisplayRow(0), 11)
]); ]);
@ -7593,7 +7611,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte
// Test 1: Cursor on a letter of a string word // Test 1: Cursor on a letter of a string word
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 17)..DisplayPoint::new(DisplayRow(3), 17) DisplayPoint::new(DisplayRow(3), 17)..DisplayPoint::new(DisplayRow(3), 17)
]); ]);
@ -7627,7 +7645,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte
// Test 2: Partial selection within a word // Test 2: Partial selection within a word
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 17)..DisplayPoint::new(DisplayRow(3), 19) DisplayPoint::new(DisplayRow(3), 17)..DisplayPoint::new(DisplayRow(3), 19)
]); ]);
@ -7661,7 +7679,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte
// Test 3: Complete word already selected // Test 3: Complete word already selected
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 16)..DisplayPoint::new(DisplayRow(3), 21) DisplayPoint::new(DisplayRow(3), 16)..DisplayPoint::new(DisplayRow(3), 21)
]); ]);
@ -7695,7 +7713,7 @@ async fn test_select_larger_smaller_syntax_node_for_string(cx: &mut TestAppConte
// Test 4: Selection spanning across words // Test 4: Selection spanning across words
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 19)..DisplayPoint::new(DisplayRow(3), 24) DisplayPoint::new(DisplayRow(3), 19)..DisplayPoint::new(DisplayRow(3), 24)
]); ]);
@ -7897,7 +7915,9 @@ async fn test_autoindent(cx: &mut TestAppContext) {
.await; .await;
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([5..5, 8..8, 9..9])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([5..5, 8..8, 9..9])
});
editor.newline(&Newline, window, cx); editor.newline(&Newline, window, cx);
assert_eq!(editor.text(cx), "fn a(\n \n) {\n \n}\n"); assert_eq!(editor.text(cx), "fn a(\n \n) {\n \n}\n");
assert_eq!( assert_eq!(
@ -8679,7 +8699,7 @@ async fn test_surround_with_pair(cx: &mut TestAppContext) {
.await; .await;
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1), DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 1), DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 1),
@ -8829,7 +8849,7 @@ async fn test_delete_autoclose_pair(cx: &mut TestAppContext) {
.await; .await;
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
Point::new(0, 1)..Point::new(0, 1), Point::new(0, 1)..Point::new(0, 1),
Point::new(1, 1)..Point::new(1, 1), Point::new(1, 1)..Point::new(1, 1),
@ -9511,16 +9531,22 @@ async fn test_multibuffer_format_during_save(cx: &mut TestAppContext) {
}); });
multi_buffer_editor.update_in(cx, |editor, window, cx| { multi_buffer_editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(1..2)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(1..2)),
);
editor.insert("|one|two|three|", window, cx); editor.insert("|one|two|three|", window, cx);
}); });
assert!(cx.read(|cx| multi_buffer_editor.is_dirty(cx))); assert!(cx.read(|cx| multi_buffer_editor.is_dirty(cx)));
multi_buffer_editor.update_in(cx, |editor, window, cx| { multi_buffer_editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(60..70)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(60..70)),
);
editor.insert("|four|five|six|", window, cx); editor.insert("|four|five|six|", window, cx);
}); });
assert!(cx.read(|cx| multi_buffer_editor.is_dirty(cx))); assert!(cx.read(|cx| multi_buffer_editor.is_dirty(cx)));
@ -9683,9 +9709,12 @@ async fn test_autosave_with_dirty_buffers(cx: &mut TestAppContext) {
// Edit only the first buffer // Edit only the first buffer
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(10..10)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(10..10)),
);
editor.insert("// edited", window, cx); editor.insert("// edited", window, cx);
}); });
@ -11097,7 +11126,9 @@ async fn test_signature_help(cx: &mut TestAppContext) {
"}); "});
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([0..0])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([0..0])
});
}); });
let mocked_response = lsp::SignatureHelp { let mocked_response = lsp::SignatureHelp {
@ -11184,7 +11215,7 @@ async fn test_signature_help(cx: &mut TestAppContext) {
// When selecting a range, the popover is gone. // When selecting a range, the popover is gone.
// Avoid using `cx.set_state` to not actually edit the document, just change its selections. // Avoid using `cx.set_state` to not actually edit the document, just change its selections.
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(1, 25)..Point::new(1, 19))); s.select_ranges(Some(Point::new(1, 25)..Point::new(1, 19)));
}) })
}); });
@ -11201,7 +11232,7 @@ async fn test_signature_help(cx: &mut TestAppContext) {
// When unselecting again, the popover is back if within the brackets. // When unselecting again, the popover is back if within the brackets.
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19))); s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19)));
}) })
}); });
@ -11221,7 +11252,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. // 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| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(0, 0)..Point::new(0, 0))); s.select_ranges(Some(Point::new(0, 0)..Point::new(0, 0)));
s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19))); s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19)));
}) })
@ -11262,7 +11293,7 @@ async fn test_signature_help(cx: &mut TestAppContext) {
cx.condition(|editor, _| !editor.signature_help_state.is_shown()) cx.condition(|editor, _| !editor.signature_help_state.is_shown())
.await; .await;
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(1, 25)..Point::new(1, 19))); s.select_ranges(Some(Point::new(1, 25)..Point::new(1, 19)));
}) })
}); });
@ -11274,7 +11305,7 @@ async fn test_signature_help(cx: &mut TestAppContext) {
fn sample(param1: u8, param2: u8) {} fn sample(param1: u8, param2: u8) {}
"}); "});
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19))); s.select_ranges(Some(Point::new(1, 19)..Point::new(1, 19)));
}) })
}); });
@ -11930,7 +11961,7 @@ async fn test_completion_in_multibuffer_with_replace_range(cx: &mut TestAppConte
let fake_server = fake_servers.next().await.unwrap(); let fake_server = fake_servers.next().await.unwrap();
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
Point::new(1, 11)..Point::new(1, 11), Point::new(1, 11)..Point::new(1, 11),
Point::new(7, 11)..Point::new(7, 11), Point::new(7, 11)..Point::new(7, 11),
@ -13571,7 +13602,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {
let (editor, cx) = cx.add_window_view(|window, cx| build_editor(multibuffer, window, cx)); let (editor, cx) = cx.add_window_view(|window, cx| build_editor(multibuffer, window, cx));
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
assert_eq!(editor.text(cx), "aaaa\nbbbb"); assert_eq!(editor.text(cx), "aaaa\nbbbb");
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
Point::new(0, 0)..Point::new(0, 0), Point::new(0, 0)..Point::new(0, 0),
Point::new(1, 0)..Point::new(1, 0), Point::new(1, 0)..Point::new(1, 0),
@ -13589,7 +13620,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {
); );
// Ensure the cursor's head is respected when deleting across an excerpt boundary. // Ensure the cursor's head is respected when deleting across an excerpt boundary.
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(0, 2)..Point::new(1, 2)]) s.select_ranges([Point::new(0, 2)..Point::new(1, 2)])
}); });
editor.backspace(&Default::default(), window, cx); editor.backspace(&Default::default(), window, cx);
@ -13599,7 +13630,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {
[Point::new(1, 0)..Point::new(1, 0)] [Point::new(1, 0)..Point::new(1, 0)]
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 1)..Point::new(0, 1)]) s.select_ranges([Point::new(1, 1)..Point::new(0, 1)])
}); });
editor.backspace(&Default::default(), window, cx); editor.backspace(&Default::default(), window, cx);
@ -13647,7 +13678,9 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {
true, true,
); );
assert_eq!(editor.text(cx), expected_text); assert_eq!(editor.text(cx), expected_text);
editor.change_selections(None, window, cx, |s| s.select_ranges(selection_ranges)); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(selection_ranges)
});
editor.handle_input("X", window, cx); editor.handle_input("X", window, cx);
@ -13708,7 +13741,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) {
let editor = cx.add_window(|window, cx| { let editor = cx.add_window(|window, cx| {
let mut editor = build_editor(multibuffer.clone(), window, cx); let mut editor = build_editor(multibuffer.clone(), window, cx);
let snapshot = editor.snapshot(window, cx); let snapshot = editor.snapshot(window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 3)..Point::new(1, 3)]) s.select_ranges([Point::new(1, 3)..Point::new(1, 3)])
}); });
editor.begin_selection( editor.begin_selection(
@ -13730,7 +13763,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) {
// Refreshing selections is a no-op when excerpts haven't changed. // Refreshing selections is a no-op when excerpts haven't changed.
_ = editor.update(cx, |editor, window, cx| { _ = editor.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.refresh()); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| s.refresh());
assert_eq!( assert_eq!(
editor.selections.ranges(cx), editor.selections.ranges(cx),
[ [
@ -13755,7 +13788,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) {
// Refreshing selections will relocate the first selection to the original buffer // Refreshing selections will relocate the first selection to the original buffer
// location. // location.
editor.change_selections(None, window, cx, |s| s.refresh()); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| s.refresh());
assert_eq!( assert_eq!(
editor.selections.ranges(cx), editor.selections.ranges(cx),
[ [
@ -13817,7 +13850,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. // Ensure we don't panic when selections are refreshed and that the pending selection is finalized.
editor.change_selections(None, window, cx, |s| s.refresh()); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| s.refresh());
assert_eq!( assert_eq!(
editor.selections.ranges(cx), editor.selections.ranges(cx),
[Point::new(0, 3)..Point::new(0, 3)] [Point::new(0, 3)..Point::new(0, 3)]
@ -13876,7 +13909,7 @@ async fn test_extra_newline_insertion(cx: &mut TestAppContext) {
.await; .await;
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 3), DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 3),
DisplayPoint::new(DisplayRow(2), 5)..DisplayPoint::new(DisplayRow(2), 5), DisplayPoint::new(DisplayRow(2), 5)..DisplayPoint::new(DisplayRow(2), 5),
@ -14055,7 +14088,9 @@ async fn test_following(cx: &mut TestAppContext) {
// Update the selections only // Update the selections only
_ = leader.update(cx, |leader, window, cx| { _ = leader.update(cx, |leader, window, cx| {
leader.change_selections(None, window, cx, |s| s.select_ranges([1..1])); leader.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([1..1])
});
}); });
follower follower
.update(cx, |follower, window, cx| { .update(cx, |follower, window, cx| {
@ -14103,7 +14138,9 @@ async fn test_following(cx: &mut TestAppContext) {
// Update the selections and scroll position. The follower's scroll position is updated // Update the selections and scroll position. The follower's scroll position is updated
// via autoscroll, not via the leader's exact scroll position. // via autoscroll, not via the leader's exact scroll position.
_ = leader.update(cx, |leader, window, cx| { _ = leader.update(cx, |leader, window, cx| {
leader.change_selections(None, window, cx, |s| s.select_ranges([0..0])); leader.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([0..0])
});
leader.request_autoscroll(Autoscroll::newest(), cx); leader.request_autoscroll(Autoscroll::newest(), cx);
leader.set_scroll_position(gpui::Point::new(1.5, 3.5), window, cx); leader.set_scroll_position(gpui::Point::new(1.5, 3.5), window, cx);
}); });
@ -14127,7 +14164,9 @@ async fn test_following(cx: &mut TestAppContext) {
// Creating a pending selection that precedes another selection // Creating a pending selection that precedes another selection
_ = leader.update(cx, |leader, window, cx| { _ = leader.update(cx, |leader, window, cx| {
leader.change_selections(None, window, cx, |s| s.select_ranges([1..1])); leader.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([1..1])
});
leader.begin_selection(DisplayPoint::new(DisplayRow(0), 0), true, 1, window, cx); leader.begin_selection(DisplayPoint::new(DisplayRow(0), 0), true, 1, window, cx);
}); });
follower follower
@ -14783,7 +14822,7 @@ async fn test_on_type_formatting_not_triggered(cx: &mut TestAppContext) {
editor_handle.update_in(cx, |editor, window, cx| { editor_handle.update_in(cx, |editor, window, cx| {
window.focus(&editor.focus_handle(cx)); window.focus(&editor.focus_handle(cx));
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(0, 21)..Point::new(0, 20)]) s.select_ranges([Point::new(0, 21)..Point::new(0, 20)])
}); });
editor.handle_input("{", window, cx); editor.handle_input("{", window, cx);
@ -16398,7 +16437,7 @@ async fn test_multibuffer_reverts(cx: &mut TestAppContext) {
}); });
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(0, 0)..Point::new(6, 0))); s.select_ranges(Some(Point::new(0, 0)..Point::new(6, 0)));
}); });
editor.git_restore(&Default::default(), window, cx); editor.git_restore(&Default::default(), window, cx);
@ -16542,9 +16581,12 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) {
cx.executor().run_until_parked(); cx.executor().run_until_parked();
multi_buffer_editor.update_in(cx, |editor, window, cx| { multi_buffer_editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(1..2)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(1..2)),
);
editor.open_excerpts(&OpenExcerpts, window, cx); editor.open_excerpts(&OpenExcerpts, window, cx);
}); });
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -16594,9 +16636,12 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) {
.unwrap(); .unwrap();
multi_buffer_editor.update_in(cx, |editor, window, cx| { multi_buffer_editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(39..40)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(39..40)),
);
editor.open_excerpts(&OpenExcerpts, window, cx); editor.open_excerpts(&OpenExcerpts, window, cx);
}); });
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -16650,9 +16695,12 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) {
.unwrap(); .unwrap();
multi_buffer_editor.update_in(cx, |editor, window, cx| { multi_buffer_editor.update_in(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(70..70)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(70..70)),
);
editor.open_excerpts(&OpenExcerpts, window, cx); editor.open_excerpts(&OpenExcerpts, window, cx);
}); });
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -18254,7 +18302,7 @@ async fn test_active_indent_guide_single_line(cx: &mut TestAppContext) {
.await; .await;
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 0)..Point::new(1, 0)]) s.select_ranges([Point::new(1, 0)..Point::new(1, 0)])
}); });
}); });
@ -18282,7 +18330,7 @@ async fn test_active_indent_guide_respect_indented_range(cx: &mut TestAppContext
.await; .await;
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 0)..Point::new(1, 0)]) s.select_ranges([Point::new(1, 0)..Point::new(1, 0)])
}); });
}); });
@ -18298,7 +18346,7 @@ async fn test_active_indent_guide_respect_indented_range(cx: &mut TestAppContext
); );
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) s.select_ranges([Point::new(2, 0)..Point::new(2, 0)])
}); });
}); });
@ -18314,7 +18362,7 @@ async fn test_active_indent_guide_respect_indented_range(cx: &mut TestAppContext
); );
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(3, 0)..Point::new(3, 0)]) s.select_ranges([Point::new(3, 0)..Point::new(3, 0)])
}); });
}); });
@ -18345,7 +18393,7 @@ async fn test_active_indent_guide_empty_line(cx: &mut TestAppContext) {
.await; .await;
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) s.select_ranges([Point::new(2, 0)..Point::new(2, 0)])
}); });
}); });
@ -18371,7 +18419,7 @@ async fn test_active_indent_guide_non_matching_indent(cx: &mut TestAppContext) {
.await; .await;
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(1, 0)..Point::new(1, 0)]) s.select_ranges([Point::new(1, 0)..Point::new(1, 0)])
}); });
}); });
@ -19309,14 +19357,14 @@ async fn test_find_enclosing_node_with_task(cx: &mut TestAppContext) {
); );
// Test finding task when cursor is inside function body // Test finding task when cursor is inside function body
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(4, 5)..Point::new(4, 5)]) s.select_ranges([Point::new(4, 5)..Point::new(4, 5)])
}); });
let (_, row, _) = editor.find_enclosing_node_task(cx).unwrap(); let (_, row, _) = editor.find_enclosing_node_task(cx).unwrap();
assert_eq!(row, 3, "Should find task for cursor inside runnable_1"); assert_eq!(row, 3, "Should find task for cursor inside runnable_1");
// Test finding task when cursor is on function name // Test finding task when cursor is on function name
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(8, 4)..Point::new(8, 4)]) s.select_ranges([Point::new(8, 4)..Point::new(8, 4)])
}); });
let (_, row, _) = editor.find_enclosing_node_task(cx).unwrap(); let (_, row, _) = editor.find_enclosing_node_task(cx).unwrap();
@ -19470,7 +19518,7 @@ async fn test_folding_buffers(cx: &mut TestAppContext) {
.collect::<String>(), .collect::<String>(),
"bbbb" "bbbb"
); );
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges(vec![Point::new(1, 0)..Point::new(1, 0)]); selections.select_ranges(vec![Point::new(1, 0)..Point::new(1, 0)]);
}); });
editor.handle_input("B", window, cx); editor.handle_input("B", window, cx);
@ -19697,7 +19745,9 @@ async fn test_folding_buffer_when_multibuffer_has_only_one_excerpt(cx: &mut Test
HighlightStyle::color(Hsla::green()), HighlightStyle::color(Hsla::green()),
cx, cx,
); );
editor.change_selections(None, window, cx, |s| s.select_ranges(Some(highlight_range))); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(highlight_range))
});
}); });
let full_text = format!("\n\n{sample_text}"); let full_text = format!("\n\n{sample_text}");
@ -21067,7 +21117,7 @@ println!("5");
}) })
}); });
editor_1.update_in(cx, |editor, window, cx| { editor_1.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(expected_ranges.clone()); s.select_ranges(expected_ranges.clone());
}); });
}); });
@ -21513,7 +21563,7 @@ async fn test_html_linked_edits_on_completion(cx: &mut TestAppContext) {
let fake_server = fake_servers.next().await.unwrap(); let fake_server = fake_servers.next().await.unwrap();
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.set_text("<ad></ad>", window, cx); editor.set_text("<ad></ad>", window, cx);
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges([Point::new(0, 3)..Point::new(0, 3)]); selections.select_ranges([Point::new(0, 3)..Point::new(0, 3)]);
}); });
let Some((buffer, _)) = editor let Some((buffer, _)) = editor
@ -22519,7 +22569,7 @@ async fn test_pulling_diagnostics(cx: &mut TestAppContext) {
// Moving cursor should not trigger diagnostic request // Moving cursor should not trigger diagnostic request
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(0, 0)..Point::new(0, 0)]) s.select_ranges([Point::new(0, 0)..Point::new(0, 0)])
}); });
}); });

View file

@ -5238,8 +5238,8 @@ impl EditorElement {
paint_highlight(range.start, range.end, color, edges); paint_highlight(range.start, range.end, color, edges);
} }
let scroll_left = layout.position_map.snapshot.scroll_position().x let scroll_left =
* layout.position_map.em_advance; layout.position_map.snapshot.scroll_position().x * layout.position_map.em_width;
for (wrap_position, active) in layout.wrap_guides.iter() { for (wrap_position, active) in layout.wrap_guides.iter() {
let x = (layout.position_map.text_hitbox.origin.x let x = (layout.position_map.text_hitbox.origin.x
@ -6676,7 +6676,7 @@ impl EditorElement {
let position_map: &PositionMap = &position_map; let position_map: &PositionMap = &position_map;
let line_height = position_map.line_height; let line_height = position_map.line_height;
let max_glyph_advance = position_map.em_advance; let max_glyph_width = position_map.em_width;
let (delta, axis) = match delta { let (delta, axis) = match delta {
gpui::ScrollDelta::Pixels(mut pixels) => { gpui::ScrollDelta::Pixels(mut pixels) => {
//Trackpad //Trackpad
@ -6687,15 +6687,15 @@ impl EditorElement {
gpui::ScrollDelta::Lines(lines) => { gpui::ScrollDelta::Lines(lines) => {
//Not trackpad //Not trackpad
let pixels = let pixels =
point(lines.x * max_glyph_advance, lines.y * line_height); point(lines.x * max_glyph_width, lines.y * line_height);
(pixels, None) (pixels, None)
} }
}; };
let current_scroll_position = position_map.snapshot.scroll_position(); let current_scroll_position = position_map.snapshot.scroll_position();
let x = (current_scroll_position.x * max_glyph_advance let x = (current_scroll_position.x * max_glyph_width
- (delta.x * scroll_sensitivity)) - (delta.x * scroll_sensitivity))
/ max_glyph_advance; / max_glyph_width;
let y = (current_scroll_position.y * line_height let y = (current_scroll_position.y * line_height
- (delta.y * scroll_sensitivity)) - (delta.y * scroll_sensitivity))
/ line_height; / line_height;
@ -8591,7 +8591,7 @@ impl Element for EditorElement {
start_row, start_row,
editor_content_width, editor_content_width,
scroll_width, scroll_width,
em_advance, em_width,
&line_layouts, &line_layouts,
cx, cx,
) )
@ -10051,7 +10051,7 @@ fn compute_auto_height_layout(
mod tests { mod tests {
use super::*; use super::*;
use crate::{ use crate::{
Editor, MultiBuffer, Editor, MultiBuffer, SelectionEffects,
display_map::{BlockPlacement, BlockProperties}, display_map::{BlockPlacement, BlockProperties},
editor_tests::{init_test, update_test_language_settings}, editor_tests::{init_test, update_test_language_settings},
}; };
@ -10176,7 +10176,7 @@ mod tests {
window window
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.cursor_shape = CursorShape::Block; editor.cursor_shape = CursorShape::Block;
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
Point::new(0, 0)..Point::new(1, 0), Point::new(0, 0)..Point::new(1, 0),
Point::new(3, 2)..Point::new(3, 3), Point::new(3, 2)..Point::new(3, 3),

View file

@ -1257,7 +1257,7 @@ mod tests {
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
let anchor_range = snapshot.anchor_before(selection_range.start) let anchor_range = snapshot.anchor_before(selection_range.start)
..snapshot.anchor_after(selection_range.end); ..snapshot.anchor_after(selection_range.end);
editor.change_selections(Some(crate::Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.set_pending_anchor_range(anchor_range, crate::SelectMode::Character) s.set_pending_anchor_range(anchor_range, crate::SelectMode::Character)
}); });
}); });

View file

@ -3,7 +3,7 @@ use crate::{
EditorSnapshot, GlobalDiagnosticRenderer, Hover, EditorSnapshot, GlobalDiagnosticRenderer, Hover,
display_map::{InlayOffset, ToDisplayPoint, invisibles::is_invisible}, display_map::{InlayOffset, ToDisplayPoint, invisibles::is_invisible},
hover_links::{InlayHighlight, RangeInEditor}, hover_links::{InlayHighlight, RangeInEditor},
scroll::{Autoscroll, ScrollAmount}, scroll::ScrollAmount,
}; };
use anyhow::Context as _; use anyhow::Context as _;
use gpui::{ 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.update_in(cx, |editor, window, cx| {
editor.change_selections( editor.change_selections(
Some(Autoscroll::fit()), Default::default(),
window, window,
cx, cx,
|selections| { |selections| {

View file

@ -1302,6 +1302,7 @@ fn apply_hint_update(
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use crate::SelectionEffects;
use crate::editor_tests::update_test_language_settings; use crate::editor_tests::update_test_language_settings;
use crate::scroll::ScrollAmount; use crate::scroll::ScrollAmount;
use crate::{ExcerptRange, scroll::Autoscroll, test::editor_lsp_test_context::rust_lang}; use crate::{ExcerptRange, scroll::Autoscroll, test::editor_lsp_test_context::rust_lang};
@ -1384,7 +1385,9 @@ pub mod tests {
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input("some change", window, cx); editor.handle_input("some change", window, cx);
}) })
.unwrap(); .unwrap();
@ -1698,7 +1701,9 @@ pub mod tests {
rs_editor rs_editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input("some rs change", window, cx); editor.handle_input("some rs change", window, cx);
}) })
.unwrap(); .unwrap();
@ -1733,7 +1738,9 @@ pub mod tests {
md_editor md_editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input("some md change", window, cx); editor.handle_input("some md change", window, cx);
}) })
.unwrap(); .unwrap();
@ -2155,7 +2162,9 @@ pub mod tests {
] { ] {
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input(change_after_opening, window, cx); editor.handle_input(change_after_opening, window, cx);
}) })
.unwrap(); .unwrap();
@ -2199,7 +2208,9 @@ pub mod tests {
edits.push(cx.spawn(|mut cx| async move { edits.push(cx.spawn(|mut cx| async move {
task_editor task_editor
.update(&mut cx, |editor, window, cx| { .update(&mut cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13])); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([13..13])
});
editor.handle_input(async_later_change, window, cx); editor.handle_input(async_later_change, window, cx);
}) })
.unwrap(); .unwrap();
@ -2447,9 +2458,12 @@ pub mod tests {
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { editor.change_selections(
s.select_ranges([selection_in_cached_range..selection_in_cached_range]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|s| s.select_ranges([selection_in_cached_range..selection_in_cached_range]),
);
}) })
.unwrap(); .unwrap();
cx.executor().advance_clock(Duration::from_millis( cx.executor().advance_clock(Duration::from_millis(
@ -2712,15 +2726,24 @@ pub mod tests {
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]) SelectionEffects::scroll(Autoscroll::Next),
}); window,
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { cx,
s.select_ranges([Point::new(22, 0)..Point::new(22, 0)]) |s| s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]),
}); );
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges([Point::new(50, 0)..Point::new(50, 0)]) 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)]),
);
}) })
.unwrap(); .unwrap();
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -2745,9 +2768,12 @@ pub mod tests {
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges([Point::new(100, 0)..Point::new(100, 0)]) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges([Point::new(100, 0)..Point::new(100, 0)]),
);
}) })
.unwrap(); .unwrap();
cx.executor().advance_clock(Duration::from_millis( cx.executor().advance_clock(Duration::from_millis(
@ -2778,9 +2804,12 @@ pub mod tests {
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges([Point::new(4, 0)..Point::new(4, 0)]),
);
}) })
.unwrap(); .unwrap();
cx.executor().advance_clock(Duration::from_millis( cx.executor().advance_clock(Duration::from_millis(
@ -2812,7 +2841,7 @@ pub mod tests {
editor_edited.store(true, Ordering::Release); editor_edited.store(true, Ordering::Release);
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(57, 0)..Point::new(57, 0)]) s.select_ranges([Point::new(57, 0)..Point::new(57, 0)])
}); });
editor.handle_input("++++more text++++", window, cx); editor.handle_input("++++more text++++", window, cx);
@ -3130,7 +3159,7 @@ pub mod tests {
cx.executor().run_until_parked(); cx.executor().run_until_parked();
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) s.select_ranges([Point::new(10, 0)..Point::new(10, 0)])
}) })
}) })
@ -3412,7 +3441,7 @@ pub mod tests {
cx.executor().run_until_parked(); cx.executor().run_until_parked();
editor editor
.update(cx, |editor, window, cx| { .update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([Point::new(10, 0)..Point::new(10, 0)]) s.select_ranges([Point::new(10, 0)..Point::new(10, 0)])
}) })
}) })

View file

@ -1352,7 +1352,7 @@ impl ProjectItem for Editor {
cx, cx,
); );
if !restoration_data.selections.is_empty() { if !restoration_data.selections.is_empty() {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(clip_ranges(&restoration_data.selections, &snapshot)); 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); self.unfold_ranges(&[matches[index].clone()], false, true, cx);
let range = self.range_for_match(&matches[index]); let range = self.range_for_match(&matches[index]);
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| { self.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([range]); s.select_ranges([range]);
}) })
} }
@ -1570,7 +1570,7 @@ impl SearchableItem for Editor {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {
self.unfold_ranges(matches, false, false, cx); self.unfold_ranges(matches, false, false, cx);
self.change_selections(None, window, cx, |s| { self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(matches.iter().cloned()) s.select_ranges(matches.iter().cloned())
}); });
} }

View file

@ -843,7 +843,7 @@ mod jsx_tag_autoclose_tests {
let mut cx = EditorTestContext::for_editor(editor, cx).await; let mut cx = EditorTestContext::for_editor(editor, cx).await;
cx.update_editor(|editor, window, cx| { cx.update_editor(|editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select(vec![ selections.select(vec![
Selection::from_offset(4), Selection::from_offset(4),
Selection::from_offset(9), Selection::from_offset(9),

View file

@ -1,8 +1,8 @@
use crate::{ use crate::{
Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DisplayPoint, DisplaySnapshot, Editor, Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DisplayPoint, DisplaySnapshot, Editor,
EvaluateSelectedText, FindAllReferences, GoToDeclaration, GoToDefinition, GoToImplementation, EvaluateSelectedText, FindAllReferences, GoToDeclaration, GoToDefinition, GoToImplementation,
GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode, SelectionExt, GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode, SelectionEffects,
ToDisplayPoint, ToggleCodeActions, SelectionExt, ToDisplayPoint, ToggleCodeActions,
actions::{Format, FormatSelections}, actions::{Format, FormatSelections},
selections_collection::SelectionsCollection, selections_collection::SelectionsCollection,
}; };
@ -177,7 +177,7 @@ pub fn deploy_context_menu(
let anchor = buffer.anchor_before(point.to_point(&display_map)); let anchor = buffer.anchor_before(point.to_point(&display_map));
if !display_ranges(&display_map, &editor.selections).any(|r| r.contains(&point)) { 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 // Move the cursor to the clicked location so that dispatched actions make sense
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.clear_disjoint(); s.clear_disjoint();
s.set_pending_anchor_range(anchor..anchor, SelectMode::Character); s.set_pending_anchor_range(anchor..anchor, SelectMode::Character);
}); });

View file

@ -1,4 +1,4 @@
use crate::{ApplyAllDiffHunks, Editor, EditorEvent, SemanticsProvider}; use crate::{ApplyAllDiffHunks, Editor, EditorEvent, SelectionEffects, SemanticsProvider};
use buffer_diff::BufferDiff; use buffer_diff::BufferDiff;
use collections::HashSet; use collections::HashSet;
use futures::{channel::mpsc, future::join_all}; use futures::{channel::mpsc, future::join_all};
@ -213,7 +213,9 @@ impl ProposedChangesEditor {
self.buffer_entries = buffer_entries; self.buffer_entries = buffer_entries;
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |selections| selections.refresh()); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.refresh()
});
editor.buffer.update(cx, |buffer, cx| { editor.buffer.update(cx, |buffer, cx| {
for diff in new_diffs { for diff in new_diffs {
buffer.add_diff(diff, cx) buffer.add_diff(diff, cx)

View file

@ -5,7 +5,7 @@ use std::{rc::Rc, sync::LazyLock};
pub use crate::rust_analyzer_ext::expand_macro_recursively; pub use crate::rust_analyzer_ext::expand_macro_recursively;
use crate::{ use crate::{
DisplayPoint, Editor, EditorMode, FoldPlaceholder, MultiBuffer, DisplayPoint, Editor, EditorMode, FoldPlaceholder, MultiBuffer, SelectionEffects,
display_map::{ display_map::{
Block, BlockPlacement, CustomBlockId, DisplayMap, DisplayRow, DisplaySnapshot, Block, BlockPlacement, CustomBlockId, DisplayMap, DisplayRow, DisplaySnapshot,
ToDisplayPoint, ToDisplayPoint,
@ -93,7 +93,9 @@ pub fn select_ranges(
) { ) {
let (unmarked_text, text_ranges) = marked_text_ranges(marked_text, true); let (unmarked_text, text_ranges) = marked_text_ranges(marked_text, true);
assert_eq!(editor.text(cx), unmarked_text); assert_eq!(editor.text(cx), unmarked_text);
editor.change_selections(None, window, cx, |s| s.select_ranges(text_ranges)); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(text_ranges)
});
} }
#[track_caller] #[track_caller]

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
AnchorRangeExt, Autoscroll, DisplayPoint, Editor, MultiBuffer, RowExt, AnchorRangeExt, DisplayPoint, Editor, MultiBuffer, RowExt,
display_map::{HighlightKey, ToDisplayPoint}, display_map::{HighlightKey, ToDisplayPoint},
}; };
use buffer_diff::DiffHunkStatusKind; use buffer_diff::DiffHunkStatusKind;
@ -362,7 +362,7 @@ impl EditorTestContext {
let (unmarked_text, selection_ranges) = marked_text_ranges(marked_text, true); let (unmarked_text, selection_ranges) = marked_text_ranges(marked_text, true);
self.editor.update_in(&mut self.cx, |editor, window, cx| { self.editor.update_in(&mut self.cx, |editor, window, cx| {
editor.set_text(unmarked_text, window, cx); editor.set_text(unmarked_text, window, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(selection_ranges) s.select_ranges(selection_ranges)
}) })
}); });
@ -379,7 +379,7 @@ impl EditorTestContext {
let (unmarked_text, selection_ranges) = marked_text_ranges(marked_text, true); let (unmarked_text, selection_ranges) = marked_text_ranges(marked_text, true);
self.editor.update_in(&mut self.cx, |editor, window, cx| { self.editor.update_in(&mut self.cx, |editor, window, cx| {
assert_eq!(editor.text(cx), unmarked_text); assert_eq!(editor.text(cx), unmarked_text);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(selection_ranges) s.select_ranges(selection_ranges)
}) })
}); });

View file

@ -1,6 +1,6 @@
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};
use buffer_diff::{BufferDiff, BufferDiffSnapshot}; use buffer_diff::{BufferDiff, BufferDiffSnapshot};
use editor::{Editor, EditorEvent, MultiBuffer}; use editor::{Editor, EditorEvent, MultiBuffer, SelectionEffects};
use git::repository::{CommitDetails, CommitDiff, CommitSummary, RepoPath}; use git::repository::{CommitDetails, CommitDiff, CommitSummary, RepoPath};
use gpui::{ use gpui::{
AnyElement, AnyView, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, AnyElement, AnyView, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter,
@ -154,7 +154,7 @@ impl CommitView {
}); });
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.disable_header_for_buffer(metadata_buffer_id.unwrap(), cx); editor.disable_header_for_buffer(metadata_buffer_id.unwrap(), cx);
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges(vec![0..0]); selections.select_ranges(vec![0..0]);
}); });
}); });

View file

@ -8,7 +8,7 @@ use anyhow::Result;
use buffer_diff::{BufferDiff, DiffHunkSecondaryStatus}; use buffer_diff::{BufferDiff, DiffHunkSecondaryStatus};
use collections::HashSet; use collections::HashSet;
use editor::{ use editor::{
Editor, EditorEvent, Editor, EditorEvent, SelectionEffects,
actions::{GoToHunk, GoToPreviousHunk}, actions::{GoToHunk, GoToPreviousHunk},
scroll::Autoscroll, scroll::Autoscroll,
}; };
@ -255,9 +255,14 @@ impl ProjectDiff {
fn move_to_path(&mut self, path_key: PathKey, window: &mut Window, cx: &mut Context<Self>) { fn move_to_path(&mut self, path_key: PathKey, window: &mut Window, cx: &mut Context<Self>) {
if let Some(position) = self.multibuffer.read(cx).location_for_path(&path_key, cx) { if let Some(position) = self.multibuffer.read(cx).location_for_path(&path_key, cx) {
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::focused()), window, cx, |s| { editor.change_selections(
SelectionEffects::scroll(Autoscroll::focused()),
window,
cx,
|s| {
s.select_ranges([position..position]); s.select_ranges([position..position]);
}) },
)
}); });
} else { } else {
self.pending_scroll = Some(path_key); self.pending_scroll = Some(path_key);
@ -463,7 +468,7 @@ impl ProjectDiff {
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
if was_empty { if was_empty {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
// TODO select the very beginning (possibly inside a deletion) // TODO select the very beginning (possibly inside a deletion)
selections.select_ranges([0..0]) selections.select_ranges([0..0])
}); });

View file

@ -2,8 +2,8 @@ pub mod cursor_position;
use cursor_position::{LineIndicatorFormat, UserCaretPosition}; use cursor_position::{LineIndicatorFormat, UserCaretPosition};
use editor::{ use editor::{
Anchor, Editor, MultiBufferSnapshot, RowHighlightOptions, ToOffset, ToPoint, actions::Tab, Anchor, Editor, MultiBufferSnapshot, RowHighlightOptions, SelectionEffects, ToOffset, ToPoint,
scroll::Autoscroll, actions::Tab, scroll::Autoscroll,
}; };
use gpui::{ use gpui::{
App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Render, SharedString, Styled, App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Render, SharedString, Styled,
@ -249,9 +249,12 @@ impl GoToLine {
let Some(start) = self.anchor_from_query(&snapshot, cx) else { let Some(start) = self.anchor_from_query(&snapshot, cx) else {
return; return;
}; };
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { editor.change_selections(
s.select_anchor_ranges([start..start]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|s| s.select_anchor_ranges([start..start]),
);
editor.focus_handle(cx).focus(window); editor.focus_handle(cx).focus(window);
cx.notify() cx.notify()
}); });

View file

@ -2,7 +2,7 @@ use anyhow::Result;
use client::{UserStore, zed_urls}; use client::{UserStore, zed_urls};
use copilot::{Copilot, Status}; use copilot::{Copilot, Status};
use editor::{ use editor::{
Editor, Editor, SelectionEffects,
actions::{ShowEditPrediction, ToggleEditPrediction}, actions::{ShowEditPrediction, ToggleEditPrediction},
scroll::Autoscroll, scroll::Autoscroll,
}; };
@ -929,9 +929,14 @@ async fn open_disabled_globs_setting_in_editor(
.map(|inner_match| inner_match.start()..inner_match.end()) .map(|inner_match| inner_match.start()..inner_match.end())
}); });
if let Some(range) = range { if let Some(range) = range {
item.change_selections(Some(Autoscroll::newest()), window, cx, |selections| { item.change_selections(
SelectionEffects::scroll(Autoscroll::newest()),
window,
cx,
|selections| {
selections.select_ranges(vec![range]); selections.select_ranges(vec![range]);
}); },
);
} }
})?; })?;

View file

@ -1,7 +1,7 @@
use anyhow::Result; use anyhow::Result;
use chrono::{Datelike, Local, NaiveTime, Timelike}; use chrono::{Datelike, Local, NaiveTime, Timelike};
use editor::Editor;
use editor::scroll::Autoscroll; use editor::scroll::Autoscroll;
use editor::{Editor, SelectionEffects};
use gpui::{App, AppContext as _, Context, Window, actions}; use gpui::{App, AppContext as _, Context, Window, actions};
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -168,9 +168,12 @@ pub fn new_journal_entry(workspace: &Workspace, window: &mut Window, cx: &mut Ap
if let Some(editor) = item.downcast::<Editor>().map(|editor| editor.downgrade()) { if let Some(editor) = item.downcast::<Editor>().map(|editor| editor.downgrade()) {
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
let len = editor.buffer().read(cx).len(cx); let len = editor.buffer().read(cx).len(cx);
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { editor.change_selections(
s.select_ranges([len..len]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|s| s.select_ranges([len..len]),
);
if len > 0 { if len > 0 {
editor.insert("\n\n", window, cx); editor.insert("\n\n", window, cx);
} }

View file

@ -1,4 +1,4 @@
use editor::{Anchor, Editor, ExcerptId, scroll::Autoscroll}; use editor::{Anchor, Editor, ExcerptId, SelectionEffects, scroll::Autoscroll};
use gpui::{ use gpui::{
App, AppContext as _, Context, Div, Entity, EventEmitter, FocusHandle, Focusable, Hsla, App, AppContext as _, Context, Div, Entity, EventEmitter, FocusHandle, Focusable, Hsla,
InteractiveElement, IntoElement, MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement, InteractiveElement, IntoElement, MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement,
@ -340,7 +340,7 @@ impl Render for SyntaxTreeView {
mem::swap(&mut range.start, &mut range.end); mem::swap(&mut range.start, &mut range.end);
editor.change_selections( editor.change_selections(
Some(Autoscroll::newest()), SelectionEffects::scroll(Autoscroll::newest()),
window, cx, window, cx,
|selections| { |selections| {
selections.select_ranges(vec![range]); selections.select_ranges(vec![range]);

View file

@ -4,7 +4,7 @@ use std::{ops::Range, path::PathBuf};
use anyhow::Result; use anyhow::Result;
use editor::scroll::Autoscroll; use editor::scroll::Autoscroll;
use editor::{Editor, EditorEvent}; use editor::{Editor, EditorEvent, SelectionEffects};
use gpui::{ use gpui::{
App, ClickEvent, Context, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement, App, ClickEvent, Context, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement,
IntoElement, ListState, ParentElement, Render, RetainAllImageCache, Styled, Subscription, Task, IntoElement, ListState, ParentElement, Render, RetainAllImageCache, Styled, Subscription, Task,
@ -468,9 +468,12 @@ impl MarkdownPreviewView {
) { ) {
if let Some(state) = &self.active_editor { if let Some(state) = &self.active_editor {
state.editor.update(cx, |editor, cx| { state.editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::center()), window, cx, |selections| { editor.change_selections(
selections.select_ranges(vec![selection]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|selections| selections.select_ranges(vec![selection]),
);
window.focus(&editor.focus_handle(cx)); window.focus(&editor.focus_handle(cx));
}); });
} }

View file

@ -4,8 +4,8 @@ use std::{
sync::Arc, sync::Arc,
}; };
use editor::RowHighlightOptions;
use editor::{Anchor, AnchorRangeExt, Editor, scroll::Autoscroll}; use editor::{Anchor, AnchorRangeExt, Editor, scroll::Autoscroll};
use editor::{RowHighlightOptions, SelectionEffects};
use fuzzy::StringMatch; use fuzzy::StringMatch;
use gpui::{ use gpui::{
App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, HighlightStyle, App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, HighlightStyle,
@ -288,9 +288,12 @@ impl PickerDelegate for OutlineViewDelegate {
.highlighted_rows::<OutlineRowHighlights>() .highlighted_rows::<OutlineRowHighlights>()
.next(); .next();
if let Some((rows, _)) = highlight { if let Some((rows, _)) = highlight {
active_editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { active_editor.change_selections(
s.select_ranges([rows.start..rows.start]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|s| s.select_ranges([rows.start..rows.start]),
);
active_editor.clear_row_highlights::<OutlineRowHighlights>(); active_editor.clear_row_highlights::<OutlineRowHighlights>();
window.focus(&active_editor.focus_handle(cx)); window.focus(&active_editor.focus_handle(cx));
} }

View file

@ -19,10 +19,10 @@ use collections::{BTreeSet, HashMap, HashSet, hash_map};
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use editor::{ use editor::{
AnchorRangeExt, Bias, DisplayPoint, Editor, EditorEvent, EditorSettings, ExcerptId, AnchorRangeExt, Bias, DisplayPoint, Editor, EditorEvent, EditorSettings, ExcerptId,
ExcerptRange, MultiBufferSnapshot, RangeToAnchorExt, ShowScrollbar, ExcerptRange, MultiBufferSnapshot, RangeToAnchorExt, SelectionEffects, ShowScrollbar,
display_map::ToDisplayPoint, display_map::ToDisplayPoint,
items::{entry_git_aware_label_color, entry_label_color}, items::{entry_git_aware_label_color, entry_label_color},
scroll::{Autoscroll, AutoscrollStrategy, ScrollAnchor, ScrollbarAutoHide}, scroll::{Autoscroll, ScrollAnchor, ScrollbarAutoHide},
}; };
use file_icons::FileIcons; use file_icons::FileIcons;
use fuzzy::{StringMatch, StringMatchCandidate, match_strings}; use fuzzy::{StringMatch, StringMatchCandidate, match_strings};
@ -1099,7 +1099,7 @@ impl OutlinePanel {
if change_selection { if change_selection {
active_editor.update(cx, |editor, cx| { active_editor.update(cx, |editor, cx| {
editor.change_selections( editor.change_selections(
Some(Autoscroll::Strategy(AutoscrollStrategy::Center, None)), SelectionEffects::scroll(Autoscroll::center()),
window, window,
cx, cx,
|s| s.select_ranges(Some(anchor..anchor)), |s| s.select_ranges(Some(anchor..anchor)),

View file

@ -4,7 +4,7 @@ pub mod popover_menu;
use anyhow::Result; use anyhow::Result;
use editor::{ use editor::{
Editor, Editor, SelectionEffects,
actions::{MoveDown, MoveUp}, actions::{MoveDown, MoveUp},
scroll::Autoscroll, scroll::Autoscroll,
}; };
@ -695,9 +695,12 @@ impl<D: PickerDelegate> Picker<D> {
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.set_text(query, window, cx); editor.set_text(query, window, cx);
let editor_offset = editor.buffer().read(cx).len(cx); let editor_offset = editor.buffer().read(cx).len(cx);
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| { editor.change_selections(
s.select_ranges(Some(editor_offset..editor_offset)) SelectionEffects::scroll(Autoscroll::Next),
}); window,
cx,
|s| s.select_ranges(Some(editor_offset..editor_offset)),
);
}); });
} }
} }

View file

@ -12,7 +12,7 @@ use editor::{
entry_diagnostic_aware_icon_decoration_and_color, entry_diagnostic_aware_icon_decoration_and_color,
entry_diagnostic_aware_icon_name_and_color, entry_git_aware_label_color, entry_diagnostic_aware_icon_name_and_color, entry_git_aware_label_color,
}, },
scroll::{Autoscroll, ScrollbarAutoHide}, scroll::ScrollbarAutoHide,
}; };
use file_icons::FileIcons; use file_icons::FileIcons;
use git::status::GitSummary; use git::status::GitSummary;
@ -1589,7 +1589,7 @@ impl ProjectPanel {
}); });
self.filename_editor.update(cx, |editor, cx| { self.filename_editor.update(cx, |editor, cx| {
editor.set_text(file_name, window, cx); editor.set_text(file_name, window, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([selection]) s.select_ranges([selection])
}); });
window.focus(&editor.focus_handle(cx)); window.focus(&editor.focus_handle(cx));

View file

@ -1,4 +1,4 @@
use editor::{Bias, Editor, scroll::Autoscroll, styled_runs_for_code_label}; use editor::{Bias, Editor, SelectionEffects, scroll::Autoscroll, styled_runs_for_code_label};
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
App, Context, DismissEvent, Entity, FontWeight, ParentElement, StyledText, Task, WeakEntity, App, Context, DismissEvent, Entity, FontWeight, ParentElement, StyledText, Task, WeakEntity,
@ -136,9 +136,12 @@ impl PickerDelegate for ProjectSymbolsDelegate {
workspace.open_project_item::<Editor>(pane, buffer, true, true, window, cx); workspace.open_project_item::<Editor>(pane, buffer, true, true, window, cx);
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| { editor.change_selections(
s.select_ranges([position..position]) SelectionEffects::scroll(Autoscroll::center()),
}); window,
cx,
|s| s.select_ranges([position..position]),
);
}); });
})?; })?;
anyhow::Ok(()) anyhow::Ok(())

View file

@ -8,6 +8,7 @@ use crate::{
}; };
use anyhow::Context as _; use anyhow::Context as _;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::SelectionEffects;
use editor::{ use editor::{
Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToPoint, Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToPoint,
display_map::{ display_map::{
@ -477,7 +478,7 @@ impl Session {
if move_down { if move_down {
editor.update(cx, move |editor, cx| { editor.update(cx, move |editor, cx| {
editor.change_selections( editor.change_selections(
Some(Autoscroll::top_relative(8)), SelectionEffects::scroll(Autoscroll::top_relative(8)),
window, window,
cx, cx,
|selections| { |selections| {

View file

@ -1,6 +1,6 @@
use anyhow::Result; use anyhow::Result;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::CompletionProvider; use editor::{CompletionProvider, SelectionEffects};
use editor::{CurrentLineHighlight, Editor, EditorElement, EditorEvent, EditorStyle, actions::Tab}; use editor::{CurrentLineHighlight, Editor, EditorElement, EditorEvent, EditorStyle, actions::Tab};
use gpui::{ use gpui::{
Action, App, Bounds, Entity, EventEmitter, Focusable, PromptLevel, Subscription, Task, Action, App, Bounds, Entity, EventEmitter, Focusable, PromptLevel, Subscription, Task,
@ -895,10 +895,15 @@ impl RulesLibrary {
} }
EditorEvent::Blurred => { EditorEvent::Blurred => {
title_editor.update(cx, |title_editor, cx| { title_editor.update(cx, |title_editor, cx| {
title_editor.change_selections(None, window, cx, |selections| { title_editor.change_selections(
SelectionEffects::no_scroll(),
window,
cx,
|selections| {
let cursor = selections.oldest_anchor().head(); let cursor = selections.oldest_anchor().head();
selections.select_anchor_ranges([cursor..cursor]); selections.select_anchor_ranges([cursor..cursor]);
}); },
);
}); });
} }
_ => {} _ => {}
@ -920,10 +925,15 @@ impl RulesLibrary {
} }
EditorEvent::Blurred => { EditorEvent::Blurred => {
body_editor.update(cx, |body_editor, cx| { body_editor.update(cx, |body_editor, cx| {
body_editor.change_selections(None, window, cx, |selections| { body_editor.change_selections(
SelectionEffects::no_scroll(),
window,
cx,
|selections| {
let cursor = selections.oldest_anchor().head(); let cursor = selections.oldest_anchor().head();
selections.select_anchor_ranges([cursor..cursor]); selections.select_anchor_ranges([cursor..cursor]);
}); },
);
}); });
} }
_ => {} _ => {}

View file

@ -1540,7 +1540,10 @@ mod tests {
use std::ops::Range; use std::ops::Range;
use super::*; use super::*;
use editor::{DisplayPoint, Editor, MultiBuffer, SearchSettings, display_map::DisplayRow}; use editor::{
DisplayPoint, Editor, MultiBuffer, SearchSettings, SelectionEffects,
display_map::DisplayRow,
};
use gpui::{Hsla, TestAppContext, UpdateGlobal, VisualTestContext}; use gpui::{Hsla, TestAppContext, UpdateGlobal, VisualTestContext};
use language::{Buffer, Point}; use language::{Buffer, Point};
use project::Project; use project::Project;
@ -1677,7 +1680,7 @@ mod tests {
}); });
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0) DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)
]) ])
@ -1764,7 +1767,7 @@ mod tests {
// Park the cursor in between matches and ensure that going to the previous match selects // Park the cursor in between matches and ensure that going to the previous match selects
// the closest match to the left. // the closest match to the left.
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0) DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0)
]) ])
@ -1785,7 +1788,7 @@ mod tests {
// Park the cursor in between matches and ensure that going to the next match selects the // Park the cursor in between matches and ensure that going to the next match selects the
// closest match to the right. // closest match to the right.
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0) DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0)
]) ])
@ -1806,7 +1809,7 @@ mod tests {
// Park the cursor after the last match and ensure that going to the previous match selects // Park the cursor after the last match and ensure that going to the previous match selects
// the last match. // the last match.
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 60) DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 60)
]) ])
@ -1827,7 +1830,7 @@ mod tests {
// Park the cursor after the last match and ensure that going to the next match selects the // Park the cursor after the last match and ensure that going to the next match selects the
// first match. // first match.
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 60) DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 60)
]) ])
@ -1848,7 +1851,7 @@ mod tests {
// Park the cursor before the first match and ensure that going to the previous match // Park the cursor before the first match and ensure that going to the previous match
// selects the last match. // selects the last match.
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([ s.select_display_ranges([
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0) DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)
]) ])
@ -2625,7 +2628,7 @@ mod tests {
}); });
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(vec![Point::new(1, 0)..Point::new(2, 4)]) s.select_ranges(vec![Point::new(1, 0)..Point::new(2, 4)])
}) })
}); });
@ -2708,7 +2711,7 @@ mod tests {
}); });
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(vec![ s.select_ranges(vec![
Point::new(1, 0)..Point::new(1, 4), Point::new(1, 0)..Point::new(1, 4),
Point::new(5, 3)..Point::new(6, 4), Point::new(5, 3)..Point::new(6, 4),

View file

@ -7,7 +7,7 @@ use anyhow::Context as _;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use editor::{ use editor::{
Anchor, Editor, EditorElement, EditorEvent, EditorSettings, EditorStyle, MAX_TAB_TITLE_LEN, Anchor, Editor, EditorElement, EditorEvent, EditorSettings, EditorStyle, MAX_TAB_TITLE_LEN,
MultiBuffer, actions::SelectAll, items::active_match_index, scroll::Autoscroll, MultiBuffer, SelectionEffects, actions::SelectAll, items::active_match_index,
}; };
use futures::{StreamExt, stream::FuturesOrdered}; use futures::{StreamExt, stream::FuturesOrdered};
use gpui::{ use gpui::{
@ -1303,7 +1303,7 @@ impl ProjectSearchView {
self.results_editor.update(cx, |editor, cx| { self.results_editor.update(cx, |editor, cx| {
let range_to_select = editor.range_for_match(&range_to_select); 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.unfold_ranges(std::slice::from_ref(&range_to_select), false, true, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([range_to_select]) s.select_ranges([range_to_select])
}); });
}); });
@ -1350,7 +1350,9 @@ impl ProjectSearchView {
fn focus_results_editor(&mut self, window: &mut Window, cx: &mut Context<Self>) { fn focus_results_editor(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.query_editor.update(cx, |query_editor, cx| { self.query_editor.update(cx, |query_editor, cx| {
let cursor = query_editor.selections.newest_anchor().head(); let cursor = query_editor.selections.newest_anchor().head();
query_editor.change_selections(None, window, cx, |s| s.select_ranges([cursor..cursor])); query_editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([cursor..cursor])
});
}); });
let results_handle = self.results_editor.focus_handle(cx); let results_handle = self.results_editor.focus_handle(cx);
window.focus(&results_handle); window.focus(&results_handle);
@ -1370,7 +1372,7 @@ impl ProjectSearchView {
let range_to_select = match_ranges let range_to_select = match_ranges
.first() .first()
.map(|range| editor.range_for_match(range)); .map(|range| editor.range_for_match(range));
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(range_to_select) s.select_ranges(range_to_select)
}); });
editor.scroll(Point::default(), Some(Axis::Vertical), window, cx); editor.scroll(Point::default(), Some(Axis::Vertical), window, cx);

View file

@ -751,7 +751,7 @@ fn string_match_candidates<'a>(
mod tests { mod tests {
use std::{path::PathBuf, sync::Arc}; use std::{path::PathBuf, sync::Arc};
use editor::Editor; use editor::{Editor, SelectionEffects};
use gpui::{TestAppContext, VisualTestContext}; use gpui::{TestAppContext, VisualTestContext};
use language::{Language, LanguageConfig, LanguageMatcher, Point}; use language::{Language, LanguageConfig, LanguageMatcher, Point};
use project::{ContextProviderWithTasks, FakeFs, Project}; use project::{ContextProviderWithTasks, FakeFs, Project};
@ -1028,7 +1028,7 @@ mod tests {
.update(|_window, cx| second_item.act_as::<Editor>(cx)) .update(|_window, cx| second_item.act_as::<Editor>(cx))
.unwrap(); .unwrap();
editor.update_in(cx, |editor, window, cx| { editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(Some(Point::new(1, 2)..Point::new(1, 5))) s.select_ranges(Some(Point::new(1, 2)..Point::new(1, 5)))
}) })
}); });

View file

@ -393,7 +393,7 @@ fn worktree_context(worktree_abs_path: &Path) -> TaskContext {
mod tests { mod tests {
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use editor::Editor; use editor::{Editor, SelectionEffects};
use gpui::TestAppContext; use gpui::TestAppContext;
use language::{Language, LanguageConfig}; use language::{Language, LanguageConfig};
use project::{BasicContextProvider, FakeFs, Project, task_store::TaskStore}; use project::{BasicContextProvider, FakeFs, Project, task_store::TaskStore};
@ -538,7 +538,7 @@ mod tests {
// And now, let's select an identifier. // And now, let's select an identifier.
editor2.update_in(cx, |editor, window, cx| { editor2.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {
selections.select_ranges([14..18]) selections.select_ranges([14..18])
}) })
}); });

View file

@ -1,4 +1,4 @@
use editor::{Bias, Direction, Editor, display_map::ToDisplayPoint, movement, scroll::Autoscroll}; use editor::{Bias, Direction, Editor, display_map::ToDisplayPoint, movement};
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
use crate::{Vim, state::Mode}; use crate::{Vim, state::Mode};
@ -29,7 +29,7 @@ impl Vim {
.next_change(count, direction) .next_change(count, direction)
.map(|s| s.to_vec()) .map(|s| s.to_vec())
{ {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map(); let map = s.display_map();
s.select_display_ranges(selections.iter().map(|a| { s.select_display_ranges(selections.iter().map(|a| {
let point = a.to_display_point(&map); let point = a.to_display_point(&map);

View file

@ -2,10 +2,9 @@ use anyhow::Result;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use command_palette_hooks::CommandInterceptResult; use command_palette_hooks::CommandInterceptResult;
use editor::{ use editor::{
Bias, Editor, ToPoint, Bias, Editor, SelectionEffects, ToPoint,
actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive}, actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive},
display_map::ToDisplayPoint, display_map::ToDisplayPoint,
scroll::Autoscroll,
}; };
use gpui::{Action, App, AppContext as _, Context, Global, Window, actions}; use gpui::{Action, App, AppContext as _, Context, Global, Window, actions};
use itertools::Itertools; use itertools::Itertools;
@ -422,7 +421,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let target = snapshot let target = snapshot
.buffer_snapshot .buffer_snapshot
.clip_point(Point::new(buffer_row.0, current.head().column), Bias::Left); .clip_point(Point::new(buffer_row.0, current.head().column), Bias::Left);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([target..target]); s.select_ranges([target..target]);
}); });
@ -493,7 +492,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
.disjoint_anchor_ranges() .disjoint_anchor_ranges()
.collect::<Vec<_>>() .collect::<Vec<_>>()
}); });
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
let end = Point::new(range.end.0, s.buffer().line_len(range.end)); let end = Point::new(range.end.0, s.buffer().line_len(range.end));
s.select_ranges([end..Point::new(range.start.0, 0)]); s.select_ranges([end..Point::new(range.start.0, 0)]);
}); });
@ -503,7 +502,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
window.dispatch_action(action.action.boxed_clone(), cx); window.dispatch_action(action.action.boxed_clone(), cx);
cx.defer_in(window, move |vim, window, cx| { cx.defer_in(window, move |vim, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| { vim.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
if let Some(previous_selections) = previous_selections { if let Some(previous_selections) = previous_selections {
s.select_ranges(previous_selections); s.select_ranges(previous_selections);
} else { } else {
@ -1455,15 +1454,20 @@ impl OnMatchingLines {
editor editor
.update_in(cx, |editor, window, cx| { .update_in(cx, |editor, window, cx| {
editor.start_transaction_at(Instant::now(), window, cx); editor.start_transaction_at(Instant::now(), window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.replace_cursors_with(|_| new_selections); s.replace_cursors_with(|_| new_selections);
}); });
window.dispatch_action(action, cx); window.dispatch_action(action, cx);
cx.defer_in(window, move |editor, window, cx| { cx.defer_in(window, move |editor, window, cx| {
let newest = editor.selections.newest::<Point>(cx).clone(); let newest = editor.selections.newest::<Point>(cx).clone();
editor.change_selections(None, window, cx, |s| { editor.change_selections(
SelectionEffects::no_scroll(),
window,
cx,
|s| {
s.select(vec![newest]); s.select(vec![newest]);
}); },
);
editor.end_transaction_at(Instant::now(), cx); editor.end_transaction_at(Instant::now(), cx);
}) })
}) })
@ -1566,7 +1570,7 @@ impl Vim {
) )
.unwrap_or((start.range(), MotionKind::Exclusive)); .unwrap_or((start.range(), MotionKind::Exclusive));
if range.start != start.start { if range.start != start.start {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
range.start.to_point(&snapshot)..range.start.to_point(&snapshot) range.start.to_point(&snapshot)..range.start.to_point(&snapshot)
]); ]);
@ -1606,7 +1610,7 @@ impl Vim {
.range(&snapshot, start.clone(), around) .range(&snapshot, start.clone(), around)
.unwrap_or(start.range()); .unwrap_or(start.range());
if range.start != start.start { if range.start != start.start {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([ s.select_ranges([
range.start.to_point(&snapshot)..range.start.to_point(&snapshot) range.start.to_point(&snapshot)..range.start.to_point(&snapshot)
]); ]);
@ -1799,7 +1803,7 @@ impl ShellExec {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.edit([(range.clone(), text)], cx); editor.edit([(range.clone(), text)], cx);
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
let point = if is_read { let point = if is_read {
let point = range.end.to_point(&snapshot); let point = range.end.to_point(&snapshot);
Point::new(point.row.saturating_sub(1), 0) Point::new(point.row.saturating_sub(1), 0)

View file

@ -1,4 +1,4 @@
use editor::{DisplayPoint, Editor, movement, scroll::Autoscroll}; use editor::{DisplayPoint, Editor, movement};
use gpui::{Action, actions}; use gpui::{Action, actions};
use gpui::{Context, Window}; use gpui::{Context, Window};
use language::{CharClassifier, CharKind}; use language::{CharClassifier, CharKind};
@ -47,7 +47,7 @@ impl Vim {
mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool, mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool,
) { ) {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let times = times.unwrap_or(1); let times = times.unwrap_or(1);
let new_goal = SelectionGoal::None; let new_goal = SelectionGoal::None;
@ -100,7 +100,7 @@ impl Vim {
mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool, mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool,
) { ) {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let times = times.unwrap_or(1); let times = times.unwrap_or(1);
let new_goal = SelectionGoal::None; let new_goal = SelectionGoal::None;
@ -161,7 +161,7 @@ impl Vim {
) { ) {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let goal = selection.goal; let goal = selection.goal;
let cursor = if selection.is_empty() || selection.reversed { let cursor = if selection.is_empty() || selection.reversed {
@ -239,7 +239,7 @@ impl Vim {
Motion::FindForward { .. } => { Motion::FindForward { .. } => {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let goal = selection.goal; let goal = selection.goal;
let cursor = if selection.is_empty() || selection.reversed { let cursor = if selection.is_empty() || selection.reversed {
@ -266,7 +266,7 @@ impl Vim {
Motion::FindBackward { .. } => { Motion::FindBackward { .. } => {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let goal = selection.goal; let goal = selection.goal;
let cursor = if selection.is_empty() || selection.reversed { let cursor = if selection.is_empty() || selection.reversed {

View file

@ -1,5 +1,6 @@
use crate::{Vim, motion::Motion, object::Object, state::Mode}; use crate::{Vim, motion::Motion, object::Object, state::Mode};
use collections::HashMap; use collections::HashMap;
use editor::SelectionEffects;
use editor::{Bias, Editor, display_map::ToDisplayPoint}; use editor::{Bias, Editor, display_map::ToDisplayPoint};
use gpui::actions; use gpui::actions;
use gpui::{Context, Window}; use gpui::{Context, Window};
@ -88,7 +89,7 @@ impl Vim {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default(); let mut selection_starts: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
selection_starts.insert(selection.id, anchor); selection_starts.insert(selection.id, anchor);
@ -106,7 +107,7 @@ impl Vim {
IndentDirection::Out => editor.outdent(&Default::default(), window, cx), IndentDirection::Out => editor.outdent(&Default::default(), window, cx),
IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx), IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx),
} }
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = selection_starts.remove(&selection.id).unwrap(); let anchor = selection_starts.remove(&selection.id).unwrap();
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
@ -128,7 +129,7 @@ impl Vim {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut original_positions: HashMap<_, _> = Default::default(); let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
original_positions.insert(selection.id, anchor); original_positions.insert(selection.id, anchor);
@ -140,7 +141,7 @@ impl Vim {
IndentDirection::Out => editor.outdent(&Default::default(), window, cx), IndentDirection::Out => editor.outdent(&Default::default(), window, cx),
IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx), IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx),
} }
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = original_positions.remove(&selection.id).unwrap(); let anchor = original_positions.remove(&selection.id).unwrap();
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);

View file

@ -1,5 +1,5 @@
use crate::{Vim, state::Mode}; use crate::{Vim, state::Mode};
use editor::{Bias, Editor, scroll::Autoscroll}; use editor::{Bias, Editor};
use gpui::{Action, Context, Window, actions}; use gpui::{Action, Context, Window, actions};
use language::SelectionGoal; use language::SelectionGoal;
use settings::Settings; use settings::Settings;
@ -34,7 +34,7 @@ impl Vim {
editor.dismiss_menus_and_popups(false, window, cx); editor.dismiss_menus_and_popups(false, window, cx);
if !HelixModeSetting::get_global(cx).0 { if !HelixModeSetting::get_global(cx).0 {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, mut cursor, _| { s.move_cursors_with(|map, mut cursor, _| {
*cursor.column_mut() = cursor.column().saturating_sub(1); *cursor.column_mut() = cursor.column().saturating_sub(1);
(map.clip_point(cursor, Bias::Left), SelectionGoal::None) (map.clip_point(cursor, Bias::Left), SelectionGoal::None)

View file

@ -4,7 +4,6 @@ use editor::{
movement::{ movement::{
self, FindRange, TextLayoutDetails, find_boundary, find_preceding_boundary_display_point, self, FindRange, TextLayoutDetails, find_boundary, find_preceding_boundary_display_point,
}, },
scroll::Autoscroll,
}; };
use gpui::{Action, Context, Window, actions, px}; use gpui::{Action, Context, Window, actions, px};
use language::{CharKind, Point, Selection, SelectionGoal}; use language::{CharKind, Point, Selection, SelectionGoal};
@ -626,7 +625,7 @@ impl Vim {
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => { Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
if !prior_selections.is_empty() { if !prior_selections.is_empty() {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(prior_selections.iter().cloned()) s.select_ranges(prior_selections.iter().cloned())
}) })
}); });

View file

@ -26,7 +26,6 @@ use collections::BTreeSet;
use convert::ConvertTarget; use convert::ConvertTarget;
use editor::Bias; use editor::Bias;
use editor::Editor; use editor::Editor;
use editor::scroll::Autoscroll;
use editor::{Anchor, SelectionEffects}; use editor::{Anchor, SelectionEffects};
use editor::{display_map::ToDisplayPoint, movement}; use editor::{display_map::ToDisplayPoint, movement};
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
@ -103,7 +102,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, _: &HelixDelete, window, cx| { Vim::action(editor, cx, |vim, _: &HelixDelete, window, cx| {
vim.record_current_action(cx); vim.record_current_action(cx);
vim.update_editor(window, cx, |_, editor, window, cx| { vim.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if selection.is_empty() { if selection.is_empty() {
selection.end = movement::right(map, selection.end) selection.end = movement::right(map, selection.end)
@ -377,7 +376,7 @@ impl Vim {
self.start_recording(cx); self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx); self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| (right(map, cursor, 1), SelectionGoal::None)); s.move_cursors_with(|map, cursor, _| (right(map, cursor, 1), SelectionGoal::None));
}); });
}); });
@ -388,7 +387,7 @@ impl Vim {
if self.mode.is_visual() { if self.mode.is_visual() {
let current_mode = self.mode; let current_mode = self.mode;
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if current_mode == Mode::VisualLine { if current_mode == Mode::VisualLine {
let start_of_line = motion::start_of_line(map, false, selection.start); let start_of_line = motion::start_of_line(map, false, selection.start);
@ -412,7 +411,7 @@ impl Vim {
self.start_recording(cx); self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx); self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| { s.move_cursors_with(|map, cursor, _| {
( (
first_non_whitespace(map, false, cursor), first_non_whitespace(map, false, cursor),
@ -432,7 +431,7 @@ impl Vim {
self.start_recording(cx); self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx); self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| { s.move_cursors_with(|map, cursor, _| {
(next_line_end(map, cursor, 1), SelectionGoal::None) (next_line_end(map, cursor, 1), SelectionGoal::None)
}); });
@ -453,7 +452,7 @@ impl Vim {
return; return;
}; };
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_anchor_ranges(marks.iter().map(|mark| *mark..*mark)) s.select_anchor_ranges(marks.iter().map(|mark| *mark..*mark))
}); });
}); });
@ -489,7 +488,7 @@ impl Vim {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
editor.edit_with_autoindent(edits, cx); editor.edit_with_autoindent(edits, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| { s.move_cursors_with(|map, cursor, _| {
let previous_line = motion::start_of_relative_buffer_row(map, cursor, -1); let previous_line = motion::start_of_relative_buffer_row(map, cursor, -1);
let insert_point = motion::end_of_line(map, false, previous_line, 1); let insert_point = motion::end_of_line(map, false, previous_line, 1);
@ -530,7 +529,7 @@ impl Vim {
(end_of_line..end_of_line, "\n".to_string() + &indent) (end_of_line..end_of_line, "\n".to_string() + &indent)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.maybe_move_cursors_with(|map, cursor, goal| { s.maybe_move_cursors_with(|map, cursor, goal| {
Motion::CurrentLine.move_point( Motion::CurrentLine.move_point(
map, map,
@ -607,7 +606,7 @@ impl Vim {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
editor.edit(edits, cx); editor.edit(edits, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|_, selection| { s.move_with(|_, selection| {
if let Some(position) = original_positions.get(&selection.id) { if let Some(position) = original_positions.get(&selection.id) {
selection.collapse_to(*position, SelectionGoal::None); selection.collapse_to(*position, SelectionGoal::None);
@ -755,7 +754,7 @@ impl Vim {
editor.newline(&editor::actions::Newline, window, cx); editor.newline(&editor::actions::Newline, window, cx);
} }
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let point = movement::saturating_left(map, selection.head()); let point = movement::saturating_left(map, selection.head());
selection.collapse_to(point, SelectionGoal::None) selection.collapse_to(point, SelectionGoal::None)
@ -791,7 +790,7 @@ impl Vim {
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
mut positions: HashMap<usize, Anchor>, mut positions: HashMap<usize, Anchor>,
) { ) {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if let Some(anchor) = positions.remove(&selection.id) { if let Some(anchor) = positions.remove(&selection.id) {
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);

View file

@ -8,7 +8,6 @@ use editor::{
Bias, DisplayPoint, Bias, DisplayPoint,
display_map::{DisplaySnapshot, ToDisplayPoint}, display_map::{DisplaySnapshot, ToDisplayPoint},
movement::TextLayoutDetails, movement::TextLayoutDetails,
scroll::Autoscroll,
}; };
use gpui::{Context, Window}; use gpui::{Context, Window};
use language::Selection; use language::Selection;
@ -40,7 +39,7 @@ impl Vim {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
// We are swapping to insert mode anyway. Just set the line end clipping behavior now // We are swapping to insert mode anyway. Just set the line end clipping behavior now
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let kind = match motion { let kind = match motion {
Motion::NextWordStart { ignore_punctuation } Motion::NextWordStart { ignore_punctuation }
@ -114,7 +113,7 @@ impl Vim {
// We are swapping to insert mode anyway. Just set the line end clipping behavior now // We are swapping to insert mode anyway. Just set the line end clipping behavior now
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
objects_found |= object.expand_selection(map, selection, around); objects_found |= object.expand_selection(map, selection, around);
}); });

View file

@ -1,5 +1,5 @@
use collections::HashMap; use collections::HashMap;
use editor::{display_map::ToDisplayPoint, scroll::Autoscroll}; use editor::{SelectionEffects, display_map::ToDisplayPoint};
use gpui::{Context, Window}; use gpui::{Context, Window};
use language::{Bias, Point, SelectionGoal}; use language::{Bias, Point, SelectionGoal};
use multi_buffer::MultiBufferRow; use multi_buffer::MultiBufferRow;
@ -36,7 +36,7 @@ impl Vim {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default(); let mut selection_starts: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Left); let anchor = map.display_point_to_anchor(selection.head(), Bias::Left);
selection_starts.insert(selection.id, anchor); selection_starts.insert(selection.id, anchor);
@ -66,7 +66,7 @@ impl Vim {
editor.convert_to_rot47(&Default::default(), window, cx) editor.convert_to_rot47(&Default::default(), window, cx)
} }
} }
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = selection_starts.remove(&selection.id).unwrap(); let anchor = selection_starts.remove(&selection.id).unwrap();
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
@ -90,7 +90,7 @@ impl Vim {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
let mut original_positions: HashMap<_, _> = Default::default(); let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
object.expand_selection(map, selection, around); object.expand_selection(map, selection, around);
original_positions.insert( original_positions.insert(
@ -116,7 +116,7 @@ impl Vim {
editor.convert_to_rot47(&Default::default(), window, cx) editor.convert_to_rot47(&Default::default(), window, cx)
} }
} }
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = original_positions.remove(&selection.id).unwrap(); let anchor = original_positions.remove(&selection.id).unwrap();
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
@ -239,7 +239,7 @@ impl Vim {
.collect::<String>(); .collect::<String>();
editor.edit([(range, text)], cx) editor.edit([(range, text)], cx)
} }
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(cursor_positions) s.select_ranges(cursor_positions)
}) })
}); });

View file

@ -7,7 +7,6 @@ use collections::{HashMap, HashSet};
use editor::{ use editor::{
Bias, DisplayPoint, Bias, DisplayPoint,
display_map::{DisplaySnapshot, ToDisplayPoint}, display_map::{DisplaySnapshot, ToDisplayPoint},
scroll::Autoscroll,
}; };
use gpui::{Context, Window}; use gpui::{Context, Window};
use language::{Point, Selection}; use language::{Point, Selection};
@ -30,7 +29,7 @@ impl Vim {
let mut original_columns: HashMap<_, _> = Default::default(); let mut original_columns: HashMap<_, _> = Default::default();
let mut motion_kind = None; let mut motion_kind = None;
let mut ranges_to_copy = Vec::new(); let mut ranges_to_copy = Vec::new();
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let original_head = selection.head(); let original_head = selection.head();
original_columns.insert(selection.id, original_head.column()); original_columns.insert(selection.id, original_head.column());
@ -71,7 +70,7 @@ impl Vim {
// Fixup cursor position after the deletion // Fixup cursor position after the deletion
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let mut cursor = selection.head(); let mut cursor = selection.head();
if kind.linewise() { if kind.linewise() {
@ -102,7 +101,7 @@ impl Vim {
// Emulates behavior in vim where if we expanded backwards to include a newline // Emulates behavior in vim where if we expanded backwards to include a newline
// the cursor gets set back to the start of the line // the cursor gets set back to the start of the line
let mut should_move_to_start: HashSet<_> = Default::default(); let mut should_move_to_start: HashSet<_> = Default::default();
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
object.expand_selection(map, selection, around); object.expand_selection(map, selection, around);
let offset_range = selection.map(|p| p.to_offset(map, Bias::Left)).range(); let offset_range = selection.map(|p| p.to_offset(map, Bias::Left)).range();
@ -159,7 +158,7 @@ impl Vim {
// Fixup cursor position after the deletion // Fixup cursor position after the deletion
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let mut cursor = selection.head(); let mut cursor = selection.head();
if should_move_to_start.contains(&selection.id) { if should_move_to_start.contains(&selection.id) {

View file

@ -1,4 +1,4 @@
use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint, scroll::Autoscroll}; use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint};
use gpui::{Action, Context, Window}; use gpui::{Action, Context, Window};
use language::{Bias, Point}; use language::{Bias, Point};
use schemars::JsonSchema; use schemars::JsonSchema;
@ -97,7 +97,7 @@ impl Vim {
editor.edit(edits, cx); editor.edit(edits, cx);
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
let mut new_ranges = Vec::new(); let mut new_ranges = Vec::new();
for (visual, anchor) in new_anchors.iter() { for (visual, anchor) in new_anchors.iter() {
let mut point = anchor.to_point(&snapshot); let mut point = anchor.to_point(&snapshot);

View file

@ -4,7 +4,6 @@ use editor::{
Anchor, Bias, DisplayPoint, Editor, MultiBuffer, Anchor, Bias, DisplayPoint, Editor, MultiBuffer,
display_map::{DisplaySnapshot, ToDisplayPoint}, display_map::{DisplaySnapshot, ToDisplayPoint},
movement, movement,
scroll::Autoscroll,
}; };
use gpui::{Context, Entity, EntityId, UpdateGlobal, Window}; use gpui::{Context, Entity, EntityId, UpdateGlobal, Window};
use language::SelectionGoal; use language::SelectionGoal;
@ -116,7 +115,7 @@ impl Vim {
} }
} }
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_anchor_ranges(ranges) s.select_anchor_ranges(ranges)
}); });
}) })
@ -169,7 +168,7 @@ impl Vim {
} }
}) })
.collect(); .collect();
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(points.into_iter().map(|p| p..p)) s.select_ranges(points.into_iter().map(|p| p..p))
}) })
}) })
@ -251,7 +250,7 @@ impl Vim {
} }
if !should_jump && !ranges.is_empty() { if !should_jump && !ranges.is_empty() {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_anchor_ranges(ranges) s.select_anchor_ranges(ranges)
}); });
} }

View file

@ -1,4 +1,4 @@
use editor::{DisplayPoint, RowExt, display_map::ToDisplayPoint, movement, scroll::Autoscroll}; use editor::{DisplayPoint, RowExt, SelectionEffects, display_map::ToDisplayPoint, movement};
use gpui::{Action, Context, Window}; use gpui::{Action, Context, Window};
use language::{Bias, SelectionGoal}; use language::{Bias, SelectionGoal};
use schemars::JsonSchema; 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). // 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, // 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. // the cursor will go to the last (or first, if is_multiline) inserted character.
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.replace_cursors_with(|map| { s.replace_cursors_with(|map| {
let mut cursors = Vec::new(); let mut cursors = Vec::new();
for (anchor, line_mode, is_multiline) in &new_selections { for (anchor, line_mode, is_multiline) in &new_selections {
@ -238,7 +238,7 @@ impl Vim {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
object.expand_selection(map, selection, around); object.expand_selection(map, selection, around);
}); });
@ -252,7 +252,7 @@ impl Vim {
}; };
editor.insert(&text, window, cx); editor.insert(&text, window, cx);
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
selection.start = map.clip_point(selection.start, Bias::Left); selection.start = map.clip_point(selection.start, Bias::Left);
selection.end = selection.start selection.end = selection.start
@ -276,7 +276,7 @@ impl Vim {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
motion.expand_selection( motion.expand_selection(
map, map,
@ -296,7 +296,7 @@ impl Vim {
}; };
editor.insert(&text, window, cx); editor.insert(&text, window, cx);
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
selection.start = map.clip_point(selection.start, Bias::Left); selection.start = map.clip_point(selection.start, Bias::Left);
selection.end = selection.start selection.end = selection.start

View file

@ -1,4 +1,4 @@
use editor::{Editor, movement}; use editor::{Editor, SelectionEffects, movement};
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
use language::Point; use language::Point;
@ -41,7 +41,7 @@ impl Vim {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if selection.start == selection.end { if selection.start == selection.end {
Motion::Right.expand_selection( Motion::Right.expand_selection(

View file

@ -1,6 +1,6 @@
use crate::{Vim, motion::Motion, object::Object}; use crate::{Vim, motion::Motion, object::Object};
use collections::HashMap; use collections::HashMap;
use editor::{Bias, display_map::ToDisplayPoint}; use editor::{Bias, SelectionEffects, display_map::ToDisplayPoint};
use gpui::{Context, Window}; use gpui::{Context, Window};
use language::SelectionGoal; use language::SelectionGoal;
@ -18,7 +18,7 @@ impl Vim {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default(); let mut selection_starts: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
selection_starts.insert(selection.id, anchor); selection_starts.insert(selection.id, anchor);
@ -32,7 +32,7 @@ impl Vim {
}); });
}); });
editor.toggle_comments(&Default::default(), window, cx); editor.toggle_comments(&Default::default(), window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = selection_starts.remove(&selection.id).unwrap(); let anchor = selection_starts.remove(&selection.id).unwrap();
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
@ -53,7 +53,7 @@ impl Vim {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut original_positions: HashMap<_, _> = Default::default(); let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
original_positions.insert(selection.id, anchor); original_positions.insert(selection.id, anchor);
@ -61,7 +61,7 @@ impl Vim {
}); });
}); });
editor.toggle_comments(&Default::default(), window, cx); editor.toggle_comments(&Default::default(), window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = original_positions.remove(&selection.id).unwrap(); let anchor = original_positions.remove(&selection.id).unwrap();
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None); selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);

View file

@ -7,7 +7,7 @@ use crate::{
state::{Mode, Register}, state::{Mode, Register},
}; };
use collections::HashMap; use collections::HashMap;
use editor::{ClipboardSelection, Editor}; use editor::{ClipboardSelection, Editor, SelectionEffects};
use gpui::Context; use gpui::Context;
use gpui::Window; use gpui::Window;
use language::Point; use language::Point;
@ -31,7 +31,7 @@ impl Vim {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
let mut original_positions: HashMap<_, _> = Default::default(); let mut original_positions: HashMap<_, _> = Default::default();
let mut kind = None; let mut kind = None;
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let original_position = (selection.head(), selection.goal); let original_position = (selection.head(), selection.goal);
kind = motion.expand_selection( kind = motion.expand_selection(
@ -51,7 +51,7 @@ impl Vim {
}); });
let Some(kind) = kind else { return }; let Some(kind) = kind else { return };
vim.yank_selections_content(editor, kind, window, cx); vim.yank_selections_content(editor, kind, window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|_, selection| { s.move_with(|_, selection| {
let (head, goal) = original_positions.remove(&selection.id).unwrap(); let (head, goal) = original_positions.remove(&selection.id).unwrap();
selection.collapse_to(head, goal); selection.collapse_to(head, goal);
@ -73,7 +73,7 @@ impl Vim {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
let mut start_positions: HashMap<_, _> = Default::default(); let mut start_positions: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
object.expand_selection(map, selection, around); object.expand_selection(map, selection, around);
let start_position = (selection.start, selection.goal); let start_position = (selection.start, selection.goal);
@ -81,7 +81,7 @@ impl Vim {
}); });
}); });
vim.yank_selections_content(editor, MotionKind::Exclusive, window, cx); vim.yank_selections_content(editor, MotionKind::Exclusive, window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|_, selection| { s.move_with(|_, selection| {
let (head, goal) = start_positions.remove(&selection.id).unwrap(); let (head, goal) = start_positions.remove(&selection.id).unwrap();
selection.collapse_to(head, goal); selection.collapse_to(head, goal);

View file

@ -5,8 +5,8 @@ use crate::{
state::Mode, state::Mode,
}; };
use editor::{ use editor::{
Anchor, Bias, Editor, EditorSnapshot, ToOffset, ToPoint, display_map::ToDisplayPoint, Anchor, Bias, Editor, EditorSnapshot, SelectionEffects, ToOffset, ToPoint,
scroll::Autoscroll, display_map::ToDisplayPoint,
}; };
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
use language::{Point, SelectionGoal}; use language::{Point, SelectionGoal};
@ -72,7 +72,7 @@ impl Vim {
editor.edit_with_block_indent(edits.clone(), Vec::new(), cx); editor.edit_with_block_indent(edits.clone(), Vec::new(), cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_anchor_ranges(edits.iter().map(|(range, _)| range.end..range.end)); s.select_anchor_ranges(edits.iter().map(|(range, _)| range.end..range.end));
}); });
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
@ -124,7 +124,7 @@ impl Vim {
editor.edit(edits, cx); editor.edit(edits, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(new_selections); s.select_ranges(new_selections);
}); });
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
@ -251,7 +251,7 @@ impl Vim {
} }
if let Some(position) = final_cursor_position { if let Some(position) = final_cursor_position {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|_map, selection| { s.move_with(|_map, selection| {
selection.collapse_to(position, SelectionGoal::None); selection.collapse_to(position, SelectionGoal::None);
}); });

View file

@ -1,6 +1,6 @@
use crate::{Vim, motion::Motion, object::Object, state::Mode}; use crate::{Vim, motion::Motion, object::Object, state::Mode};
use collections::HashMap; use collections::HashMap;
use editor::{Bias, Editor, RewrapOptions, display_map::ToDisplayPoint, scroll::Autoscroll}; use editor::{Bias, Editor, RewrapOptions, SelectionEffects, display_map::ToDisplayPoint};
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
use language::SelectionGoal; use language::SelectionGoal;
@ -22,7 +22,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
}, },
cx, cx,
); );
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if let Some(anchor) = positions.remove(&selection.id) { if let Some(anchor) = positions.remove(&selection.id) {
let mut point = anchor.to_display_point(map); let mut point = anchor.to_display_point(map);
@ -53,7 +53,7 @@ impl Vim {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default(); let mut selection_starts: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
selection_starts.insert(selection.id, anchor); selection_starts.insert(selection.id, anchor);
@ -73,7 +73,7 @@ impl Vim {
}, },
cx, cx,
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = selection_starts.remove(&selection.id).unwrap(); let anchor = selection_starts.remove(&selection.id).unwrap();
let mut point = anchor.to_display_point(map); let mut point = anchor.to_display_point(map);
@ -96,7 +96,7 @@ impl Vim {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
let mut original_positions: HashMap<_, _> = Default::default(); let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right); let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
original_positions.insert(selection.id, anchor); original_positions.insert(selection.id, anchor);
@ -110,7 +110,7 @@ impl Vim {
}, },
cx, cx,
); );
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let anchor = original_positions.remove(&selection.id).unwrap(); let anchor = original_positions.remove(&selection.id).unwrap();
let mut point = anchor.to_display_point(map); let mut point = anchor.to_display_point(map);

View file

@ -4,7 +4,7 @@ use crate::{
object::Object, object::Object,
state::Mode, state::Mode,
}; };
use editor::{Bias, movement, scroll::Autoscroll}; use editor::{Bias, movement};
use gpui::{Context, Window}; use gpui::{Context, Window};
use language::BracketPair; use language::BracketPair;
@ -109,7 +109,7 @@ impl Vim {
editor.edit(edits, cx); editor.edit(edits, cx);
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
if mode == Mode::VisualBlock { if mode == Mode::VisualBlock {
s.select_anchor_ranges(anchors.into_iter().take(1)) s.select_anchor_ranges(anchors.into_iter().take(1))
} else { } else {
@ -207,7 +207,7 @@ impl Vim {
} }
} }
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(anchors); s.select_ranges(anchors);
}); });
edits.sort_by_key(|(range, _)| range.start); edits.sort_by_key(|(range, _)| range.start);
@ -317,7 +317,7 @@ impl Vim {
edits.sort_by_key(|(range, _)| range.start); edits.sort_by_key(|(range, _)| range.start);
editor.edit(edits, cx); editor.edit(edits, cx);
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_anchor_ranges(stable_anchors); s.select_anchor_ranges(stable_anchors);
}); });
}); });
@ -375,7 +375,7 @@ impl Vim {
anchors.push(start..start) anchors.push(start..start)
} }
} }
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(anchors); s.select_ranges(anchors);
}); });
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);

View file

@ -22,7 +22,8 @@ mod visual;
use anyhow::Result; use anyhow::Result;
use collections::HashMap; use collections::HashMap;
use editor::{ use editor::{
Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, ToPoint, Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, SelectionEffects,
ToPoint,
movement::{self, FindRange}, movement::{self, FindRange},
}; };
use gpui::{ use gpui::{
@ -963,7 +964,7 @@ impl Vim {
} }
} }
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
// we cheat with visual block mode and use multiple cursors. // we cheat with visual block mode and use multiple cursors.
// the cost of this cheat is we need to convert back to a single // the cost of this cheat is we need to convert back to a single
// cursor whenever vim would. // cursor whenever vim would.
@ -1163,7 +1164,7 @@ impl Vim {
} else { } else {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|_, selection| { s.move_with(|_, selection| {
selection.collapse_to(selection.start, selection.goal) selection.collapse_to(selection.start, selection.goal)
}) })
@ -1438,7 +1439,8 @@ impl Vim {
Mode::VisualLine | Mode::VisualBlock | Mode::Visual => { Mode::VisualLine | Mode::VisualBlock | Mode::Visual => {
self.update_editor(window, cx, |vim, editor, window, cx| { self.update_editor(window, cx, |vim, editor, window, cx| {
let original_mode = vim.undo_modes.get(transaction_id); let original_mode = vim.undo_modes.get(transaction_id);
editor.change_selections(None, window, cx, |s| match original_mode { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
match original_mode {
Some(Mode::VisualLine) => { Some(Mode::VisualLine) => {
s.move_with(|map, selection| { s.move_with(|map, selection| {
selection.collapse_to( selection.collapse_to(
@ -1460,13 +1462,14 @@ impl Vim {
); );
}); });
} }
}
}); });
}); });
self.switch_mode(Mode::Normal, true, window, cx) self.switch_mode(Mode::Normal, true, window, cx)
} }
Mode::Normal => { Mode::Normal => {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
selection selection
.collapse_to(map.clip_at_line_end(selection.end), selection.goal) .collapse_to(map.clip_at_line_end(selection.end), selection.goal)

View file

@ -2,10 +2,9 @@ use std::sync::Arc;
use collections::HashMap; use collections::HashMap;
use editor::{ use editor::{
Bias, DisplayPoint, Editor, Bias, DisplayPoint, Editor, SelectionEffects,
display_map::{DisplaySnapshot, ToDisplayPoint}, display_map::{DisplaySnapshot, ToDisplayPoint},
movement, movement,
scroll::Autoscroll,
}; };
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
use language::{Point, Selection, SelectionGoal}; use language::{Point, Selection, SelectionGoal};
@ -133,7 +132,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
vim.update_editor(window, cx, |_, editor, window, cx| { vim.update_editor(window, cx, |_, editor, window, cx| {
editor.set_clip_at_line_ends(false, cx); editor.set_clip_at_line_ends(false, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map(); let map = s.display_map();
let ranges = ranges let ranges = ranges
.into_iter() .into_iter()
@ -187,7 +186,7 @@ impl Vim {
motion.move_point(map, point, goal, times, &text_layout_details) motion.move_point(map, point, goal, times, &text_layout_details)
}) })
} else { } else {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let was_reversed = selection.reversed; let was_reversed = selection.reversed;
let mut current_head = selection.head(); let mut current_head = selection.head();
@ -259,7 +258,7 @@ impl Vim {
) -> Option<(DisplayPoint, SelectionGoal)>, ) -> Option<(DisplayPoint, SelectionGoal)>,
) { ) {
let text_layout_details = editor.text_layout_details(window); let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
let map = &s.display_map(); let map = &s.display_map();
let mut head = s.newest_anchor().head().to_display_point(map); let mut head = s.newest_anchor().head().to_display_point(map);
let mut tail = s.oldest_anchor().tail().to_display_point(map); let mut tail = s.oldest_anchor().tail().to_display_point(map);
@ -375,7 +374,7 @@ impl Vim {
} }
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let mut mut_selection = selection.clone(); let mut mut_selection = selection.clone();
@ -454,7 +453,7 @@ impl Vim {
) { ) {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.split_selection_into_lines(&Default::default(), window, cx); editor.split_selection_into_lines(&Default::default(), window, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| { s.move_cursors_with(|map, cursor, _| {
(next_line_end(map, cursor, 1), SelectionGoal::None) (next_line_end(map, cursor, 1), SelectionGoal::None)
}); });
@ -472,7 +471,7 @@ impl Vim {
) { ) {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.split_selection_into_lines(&Default::default(), window, cx); editor.split_selection_into_lines(&Default::default(), window, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| { s.move_cursors_with(|map, cursor, _| {
( (
first_non_whitespace(map, false, cursor), first_non_whitespace(map, false, cursor),
@ -495,7 +494,7 @@ impl Vim {
pub fn other_end(&mut self, _: &OtherEnd, window: &mut Window, cx: &mut Context<Self>) { pub fn other_end(&mut self, _: &OtherEnd, window: &mut Window, cx: &mut Context<Self>) {
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|_, selection| { s.move_with(|_, selection| {
selection.reversed = !selection.reversed; selection.reversed = !selection.reversed;
}); });
@ -511,7 +510,7 @@ impl Vim {
) { ) {
let mode = self.mode; let mode = self.mode;
self.update_editor(window, cx, |_, editor, window, cx| { self.update_editor(window, cx, |_, editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|_, selection| { s.move_with(|_, selection| {
selection.reversed = !selection.reversed; selection.reversed = !selection.reversed;
}); });
@ -530,7 +529,7 @@ impl Vim {
editor.selections.line_mode = false; editor.selections.line_mode = false;
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if line_mode { if line_mode {
let mut position = selection.head(); let mut position = selection.head();
@ -567,7 +566,7 @@ impl Vim {
vim.copy_selections_content(editor, kind, window, cx); vim.copy_selections_content(editor, kind, window, cx);
if line_mode && vim.mode != Mode::VisualBlock { if line_mode && vim.mode != Mode::VisualBlock {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let end = selection.end.to_point(map); let end = selection.end.to_point(map);
let start = selection.start.to_point(map); let start = selection.start.to_point(map);
@ -587,7 +586,7 @@ impl Vim {
// Fixup cursor position after the deletion // Fixup cursor position after the deletion
editor.set_clip_at_line_ends(true, cx); editor.set_clip_at_line_ends(true, cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let mut cursor = selection.head().to_point(map); let mut cursor = selection.head().to_point(map);
@ -613,7 +612,7 @@ impl Vim {
// For visual line mode, adjust selections to avoid yanking the next line when on \n // For visual line mode, adjust selections to avoid yanking the next line when on \n
if line_mode && vim.mode != Mode::VisualBlock { if line_mode && vim.mode != Mode::VisualBlock {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
let start = selection.start.to_point(map); let start = selection.start.to_point(map);
let end = selection.end.to_point(map); let end = selection.end.to_point(map);
@ -634,7 +633,7 @@ impl Vim {
MotionKind::Exclusive MotionKind::Exclusive
}; };
vim.yank_selections_content(editor, kind, window, cx); vim.yank_selections_content(editor, kind, window, cx);
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| { s.move_with(|map, selection| {
if line_mode { if line_mode {
selection.start = start_of_line(map, false, selection.start); selection.start = start_of_line(map, false, selection.start);
@ -687,7 +686,9 @@ impl Vim {
} }
editor.edit(edits, cx); editor.edit(edits, cx);
editor.change_selections(None, window, cx, |s| s.select_ranges(stable_anchors)); editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges(stable_anchors)
});
}); });
}); });
self.switch_mode(Mode::Normal, false, window, cx); self.switch_mode(Mode::Normal, false, window, cx);
@ -799,7 +800,7 @@ impl Vim {
if direction == Direction::Prev { if direction == Direction::Prev {
std::mem::swap(&mut start_selection, &mut end_selection); std::mem::swap(&mut start_selection, &mut end_selection);
} }
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([start_selection..end_selection]); s.select_ranges([start_selection..end_selection]);
}); });
editor.set_collapse_matches(true); editor.set_collapse_matches(true);

View file

@ -18,7 +18,7 @@ use client::zed_urls;
use collections::VecDeque; use collections::VecDeque;
use debugger_ui::debugger_panel::DebugPanel; use debugger_ui::debugger_panel::DebugPanel;
use editor::ProposedChangesEditorToolbar; use editor::ProposedChangesEditorToolbar;
use editor::{Editor, MultiBuffer, scroll::Autoscroll}; use editor::{Editor, MultiBuffer};
use futures::future::Either; use futures::future::Either;
use futures::{StreamExt, channel::mpsc, select_biased}; use futures::{StreamExt, channel::mpsc, select_biased};
use git_ui::git_panel::GitPanel; 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| { editor.update(cx, |editor, cx| {
let last_multi_buffer_offset = editor.buffer().read(cx).len(cx); let last_multi_buffer_offset = editor.buffer().read(cx).len(cx);
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(Some( s.select_ranges(Some(
last_multi_buffer_offset..last_multi_buffer_offset, last_multi_buffer_offset..last_multi_buffer_offset,
)); ));
@ -1774,7 +1774,7 @@ mod tests {
use super::*; use super::*;
use assets::Assets; use assets::Assets;
use collections::HashSet; use collections::HashSet;
use editor::{DisplayPoint, Editor, display_map::DisplayRow, scroll::Autoscroll}; use editor::{DisplayPoint, Editor, SelectionEffects, display_map::DisplayRow};
use gpui::{ use gpui::{
Action, AnyWindowHandle, App, AssetSource, BorrowAppContext, SemanticVersion, Action, AnyWindowHandle, App, AssetSource, BorrowAppContext, SemanticVersion,
TestAppContext, UpdateGlobal, VisualTestContext, WindowHandle, actions, TestAppContext, UpdateGlobal, VisualTestContext, WindowHandle, actions,
@ -3348,7 +3348,7 @@ mod tests {
workspace workspace
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor1.update(cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(10), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(10), 0)
..DisplayPoint::new(DisplayRow(10), 0)]) ..DisplayPoint::new(DisplayRow(10), 0)])
}); });
@ -3378,7 +3378,7 @@ mod tests {
workspace workspace
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor3.update(cx, |editor, cx| { editor3.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(12), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(12), 0)
..DisplayPoint::new(DisplayRow(12), 0)]) ..DisplayPoint::new(DisplayRow(12), 0)])
}); });
@ -3593,7 +3593,7 @@ mod tests {
workspace workspace
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor1.update(cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(15), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(15), 0)
..DisplayPoint::new(DisplayRow(15), 0)]) ..DisplayPoint::new(DisplayRow(15), 0)])
}) })
@ -3604,7 +3604,7 @@ mod tests {
workspace workspace
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor1.update(cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(3), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(3), 0)
..DisplayPoint::new(DisplayRow(3), 0)]) ..DisplayPoint::new(DisplayRow(3), 0)])
}); });
@ -3615,7 +3615,7 @@ mod tests {
workspace workspace
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor1.update(cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(13), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(13), 0)
..DisplayPoint::new(DisplayRow(13), 0)]) ..DisplayPoint::new(DisplayRow(13), 0)])
}) })
@ -3627,7 +3627,7 @@ mod tests {
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor1.update(cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.transact(window, cx, |editor, window, cx| { editor.transact(window, cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(2), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(2), 0)
..DisplayPoint::new(DisplayRow(14), 0)]) ..DisplayPoint::new(DisplayRow(14), 0)])
}); });
@ -3640,7 +3640,7 @@ mod tests {
workspace workspace
.update(cx, |_, window, cx| { .update(cx, |_, window, cx| {
editor1.update(cx, |editor, cx| { editor1.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |s| { editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_display_ranges([DisplayPoint::new(DisplayRow(1), 0) s.select_display_ranges([DisplayPoint::new(DisplayRow(1), 0)
..DisplayPoint::new(DisplayRow(1), 0)]) ..DisplayPoint::new(DisplayRow(1), 0)])
}) })