vim: Fix issues with r/R (#13623)
Release Notes: - vim: Fix undo after repeated insert/replace mode (#13573) - vim: Fix 'r' repeating too much (#13566)
This commit is contained in:
parent
363ac6bc96
commit
da03610555
5 changed files with 96 additions and 60 deletions
|
@ -23,11 +23,11 @@ use crate::{
|
|||
};
|
||||
use case::{change_case_motion, change_case_object, CaseTarget};
|
||||
use collections::BTreeSet;
|
||||
use editor::display_map::ToDisplayPoint;
|
||||
use editor::scroll::Autoscroll;
|
||||
use editor::Anchor;
|
||||
use editor::Bias;
|
||||
use editor::Editor;
|
||||
use editor::{display_map::ToDisplayPoint, movement};
|
||||
use gpui::{actions, ViewContext, WindowContext};
|
||||
use language::{Point, SelectionGoal};
|
||||
use log::error;
|
||||
|
@ -490,45 +490,34 @@ pub(crate) fn normal_replace(text: Arc<str>, cx: &mut WindowContext) {
|
|||
editor.transact(cx, |editor, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
let (map, display_selections) = editor.selections.all_display(cx);
|
||||
// Selections are biased right at the start. So we need to store
|
||||
// anchors that are biased left so that we can restore the selections
|
||||
// after the change
|
||||
let stable_anchors = editor
|
||||
.selections
|
||||
.disjoint_anchors()
|
||||
.into_iter()
|
||||
.map(|selection| {
|
||||
let start = selection.start.bias_left(&map.buffer_snapshot);
|
||||
start..start
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let edits = display_selections
|
||||
.into_iter()
|
||||
.map(|selection| {
|
||||
let mut range = selection.range();
|
||||
range.end = right(&map, range.end, count);
|
||||
let repeated_text = text.repeat(count);
|
||||
let mut edits = Vec::new();
|
||||
for selection in display_selections {
|
||||
let mut range = selection.range();
|
||||
for _ in 0..count {
|
||||
let new_point = movement::saturating_right(&map, range.end);
|
||||
if range.end == new_point {
|
||||
return;
|
||||
}
|
||||
range.end = new_point;
|
||||
}
|
||||
|
||||
(
|
||||
range.start.to_offset(&map, Bias::Left)
|
||||
..range.end.to_offset(&map, Bias::Left),
|
||||
repeated_text,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
edits.push((
|
||||
range.start.to_offset(&map, Bias::Left)
|
||||
..range.end.to_offset(&map, Bias::Left),
|
||||
text.repeat(count),
|
||||
))
|
||||
}
|
||||
|
||||
editor.buffer().update(cx, |buffer, cx| {
|
||||
buffer.edit(edits, None, cx);
|
||||
});
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_anchor_ranges(stable_anchors);
|
||||
if count > 1 {
|
||||
s.move_cursors_with(|map, point, _| {
|
||||
(right(map, point, count - 1), SelectionGoal::None)
|
||||
});
|
||||
}
|
||||
s.move_with(|map, selection| {
|
||||
let point = movement::saturating_left(map, selection.head());
|
||||
selection.collapse_to(point, SelectionGoal::None)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1441,5 +1430,9 @@ mod test {
|
|||
cx.set_shared_state("ˇhello world\n").await;
|
||||
cx.simulate_shared_keystrokes("2 r - f w .").await;
|
||||
cx.shared_state().await.assert_eq("--llo -ˇ-rld\n");
|
||||
|
||||
cx.set_shared_state("ˇhello world\n").await;
|
||||
cx.simulate_shared_keystrokes("2 0 r - ").await;
|
||||
cx.shared_state().await.assert_eq("ˇhello world\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue