vim: Improve pasting while in replace mode (#41549)
- Update `vim::normal::Vim.normal_replace` to work with more than one character - Add `vim::replace::Vim.paste_replace` to handle pasting the clipboard's contents while in replace mode - Update vim's handling of the `editor::actions::Paste` action so that the `paste_replace` method is called when vim is in replace mode, otherwise it'll just call the regular `editor::Editor.paste` method Closes #41378 Release Notes: - Improved pasting while in Vim's Replace mode, ensuring that the Zed replaces the same number of characters as the length of the contents being pasted
This commit is contained in:
@@ -965,8 +965,17 @@ impl Vim {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
// We need to use `text.chars().count()` instead of `text.len()` here as
|
||||
// `len()` counts bytes, not characters.
|
||||
let char_count = text.chars().count();
|
||||
let count = Vim::take_count(cx).unwrap_or(char_count);
|
||||
let is_return_char = text == "\n".into() || text == "\r".into();
|
||||
let count = Vim::take_count(cx).unwrap_or(1);
|
||||
let repeat_count = match (is_return_char, char_count) {
|
||||
(true, _) => 0,
|
||||
(_, 1) => count,
|
||||
(_, _) => 1,
|
||||
};
|
||||
|
||||
Vim::take_forced_motion(cx);
|
||||
self.stop_recording(cx);
|
||||
self.update_editor(cx, |_, editor, cx| {
|
||||
@@ -989,7 +998,7 @@ impl Vim {
|
||||
edits.push((
|
||||
range.start.to_offset(&display_map, Bias::Left)
|
||||
..range.end.to_offset(&display_map, Bias::Left),
|
||||
text.repeat(if is_return_char { 0 } else { count }),
|
||||
text.repeat(repeat_count),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user