Revert "Remove into SelectionEffects from .change_selections"

This reverts commit 28380d714d.
This commit is contained in:
Conrad Irwin 2025-06-27 14:06:17 -06:00
parent 28380d714d
commit 6e762d9c05
65 changed files with 625 additions and 837 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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