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:
Dino
2025-10-30 20:33:03 +00:00
committed by GitHub
parent 5ae0768ce4
commit 8aa2158418
3 changed files with 60 additions and 4 deletions
+11 -2
View File
@@ -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),
));
}