Remove into SelectionEffects
from .change_selections
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
This commit is contained in:
parent
f338c46bf7
commit
28380d714d
65 changed files with 837 additions and 625 deletions
|
@ -8,7 +8,6 @@ use editor::{
|
|||
Bias, DisplayPoint,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
movement::TextLayoutDetails,
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Window};
|
||||
use language::Selection;
|
||||
|
@ -40,7 +39,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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let kind = match motion {
|
||||
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
|
||||
editor.set_clip_at_line_ends(false, 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| {
|
||||
objects_found |= object.expand_selection(map, selection, around);
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use collections::HashMap;
|
||||
use editor::{display_map::ToDisplayPoint, scroll::Autoscroll};
|
||||
use editor::{SelectionEffects, display_map::ToDisplayPoint};
|
||||
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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges(cursor_positions)
|
||||
})
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@ use collections::{HashMap, HashSet};
|
|||
use editor::{
|
||||
Bias, DisplayPoint,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Window};
|
||||
use language::{Point, Selection};
|
||||
|
@ -30,7 +29,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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let original_head = selection.head();
|
||||
original_columns.insert(selection.id, original_head.column());
|
||||
|
@ -71,7 +70,7 @@ impl Vim {
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
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| {
|
||||
let mut cursor = selection.head();
|
||||
if kind.linewise() {
|
||||
|
@ -102,7 +101,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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), 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();
|
||||
|
@ -159,7 +158,7 @@ impl Vim {
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
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| {
|
||||
let mut cursor = selection.head();
|
||||
if should_move_to_start.contains(&selection.id) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint, scroll::Autoscroll};
|
||||
use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint};
|
||||
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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
let mut new_ranges = Vec::new();
|
||||
for (visual, anchor) in new_anchors.iter() {
|
||||
let mut point = anchor.to_point(&snapshot);
|
||||
|
|
|
@ -4,7 +4,6 @@ use editor::{
|
|||
Anchor, Bias, DisplayPoint, Editor, MultiBuffer,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
movement,
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Entity, EntityId, UpdateGlobal, Window};
|
||||
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)
|
||||
});
|
||||
})
|
||||
|
@ -169,7 +168,7 @@ impl Vim {
|
|||
}
|
||||
})
|
||||
.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))
|
||||
})
|
||||
})
|
||||
|
@ -251,7 +250,7 @@ impl Vim {
|
|||
}
|
||||
|
||||
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)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
selection.start = map.clip_point(selection.start, Bias::Left);
|
||||
selection.end = selection.start
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{Editor, movement};
|
||||
use editor::{Editor, SelectionEffects, 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if selection.start == selection.end {
|
||||
Motion::Right.expand_selection(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{Vim, motion::Motion, object::Object};
|
||||
use collections::HashMap;
|
||||
use editor::{Bias, display_map::ToDisplayPoint};
|
||||
use editor::{Bias, SelectionEffects, 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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);
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
state::{Mode, Register},
|
||||
};
|
||||
use collections::HashMap;
|
||||
use editor::{ClipboardSelection, Editor};
|
||||
use editor::{ClipboardSelection, Editor, SelectionEffects};
|
||||
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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), 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(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
let (head, goal) = start_positions.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(head, goal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue